I2C 12 bit DAC MCP4725 support on WC8 and WC32

CAI_Support

Senior Member
We noticed there are low cost I2C ADC module on the market based on MCP4725 chip.  We like to provide some example PLC code for controlling this DAC chip, so that through PLC program the MCP4725 chip module, WebControl can send out analog output.
 
 
 
MCP4725 has three address bits, however, upper two are fixed at the factory, only lower bit can be programmed.  For write to the chip, its I2C address is 0xC0 or 0xC2, based on A0 logic level is 0 or 1.  The module we purchased from market has already soldered A0 to ground.
 
Two I2C commands of MCP4725 are mostly use, Write-to-DAC 0x40 or Write-to-DAC-and-EEPROM 0x60
 
There is an EEPROM inside MCP4725. If EEPROM stores a value, it will set its analog output to that value during power up. 
That is probably desirable for many applications, for example, audio output level control sets output to last set volume when power on.
 
12bit DAC will take higher 8 bits of the 12bit data first, then four bits loaded on the upper position for next data byte.
 
This simple program will generate analog output at VCC/4096 -1

START
I2CWRITE 1 0 0xc0 # I2c starts
BNZ NO_DAC
I2CWRITE 0 0 0x60 # write to DAC and EEPROM
I2CWRITE 0 0 0xFF # upper 8 bits
I2CWRITE 0 1 0xE0 # lower 4 bits and stop
NO_DAC:
I2CWRITE 0 1 0xc0 #I2C stops
END

 
Max output is VCC, each step is VCC/4096.  That will be 0xFF in first byte and 0xF0 in second byte.  If you use PLC calculate DAC output value, please make sure shift the lower 4 bits into higher four bit position.  The example PLC code sending 12 bit value 0xFFE to DAC, which is max Vcc minus 1 bit.
 
After first I2CWRITE, PLC code should check if DAC exist or not. If no_DAC, then send stop bit to tell WebControl release I2C bus for other devices.
 
The above PLC code example, we use

I2CWRITE 0 0 0x60

which write to both DAC and EEPROM.  If this code is repeatedly called, it is best to use 0x40, so that it would not worn out EEPROM inside sensor too quickly.
 
Back
Top