Little driver for the MCP4725 12bits DAC

Place your projects here
Post Reply
User avatar
cicciocb
Site Admin
Posts: 2195
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 470 times
Been thanked: 1461 times
Contact:

Little driver for the MCP4725 12bits DAC

Post by cicciocb »

Hi all,

Here you can find a very simple library for the DAC 12bits MCP4725. This chip has a small EEPROM inside that is used to restore the default output when the chip is powered off.

The code contains two subroutines (SUBs): one that writes the output voltage and the other that writes the output and sets the default value at the same time.

The second subroutine should be used only to set the default value and should be called occasionally.

I hope it will be useful to someone.

Code: [Local Link Removed for Guests]

'ANNEX32 RDS MCP4725 library
SDA = 47
SCL = 21
I2C.SETUP SDA, SCL
for z = 0 to 4095
  mcp4725_out z
  pause 1
next z

' set the dafault value at 3.3*1024/4096 = 0.825V
mcp4725_store 1024

end

'set the value of the output (12 bits = 0 ... 4095)
sub mcp4725_out(value)
  local h, l
  h = value >> 8
  l = value and 255
  i2c.writeRegbyte &h60, h, l
end sub

'set the value and store the default value
'that will be restored when the chip is powered
sub mcp4725_store(value)
  local h, l
  h = value >> 4
  l = (value and &h0f) << 4
  i2c.begin &h60
  i2c.write &h60 ' write DAC and EEPROM
  i2c.write h
  i2c.write l
  i2c.end  
end sub
Post Reply