PIC24E I2C communication with MCP4725

Running the Experiment

We make a simple program flow, using the ADC readouts from our previous article Simultaneous Sampling of 4 ADC Channels with PIC24E. Only the value from AN0 is sent to the MCP4725. The 12-bit DAC value is created by shifting left twice the 10-bit value from AN0.

 DacVal.full = ADCValues[0]<<2;

For example, maximum read of AN0 = 1023 converts to DAC value of 4095. This translates to voltage equal to Vdd of MCP4725, or 3.3 volts.

Even though the ADC readout from AN0 never exceeds 1023 in this experiment, It is a good practice to limit the DAC value to the 12-bit range

if (DacVal.full>4095) DacVal.full = 4095;
else if (DacVal.full<0) DacVal.full = 0;
writeMCP4725(); // send to DAC

Figure 2 – 4 show readouts from a voltmeter with 3 values of AN0. The voltage output equal 3.3, 2.14, and 0.36 volts when AN0 read 1023, 658, and 111, respectively. Simple calculations verify they are correct. For, example, for AN0 = 111, the output must equal (111 x 3.3)/1023 = 0.358 volt.

Figure 2 DAC voltage readout (3.3 Volts) when AN0 = 1023

Figure 3 DAC readout (2.14 Volts) when AN0 = 658

Figure 4 DAC readout (0.36 volt) when AN0 = 111


  1. R. Reese, J.W. Bruce and B.A. Jones, Microcontrollers: From Assembly Language to C Using the PIC24 Family, Cengage Learning, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s