I took a few moments out to write a program to answer the question ‘any progress on making a library for MCP4725?’
The MCP4725 is a simple digital to analog converter circuit to be able to work with an microcontroller.
You will find many MCP4725 I2C DAC modules on the web, or, direct from Microchip.
This is an introduction to the MCP4725 DAC module.
Digital to Analog Conversion (DAC) is not difficult to understand. A DAC simply converts digital signal into an analog signal. An analog signal, by definition, is a nominally continuous electrical signal. The analog signal path implies a continuous signal in contrast to a digital signal path, which breaks everything into on or off states. This is the main difference between analog and digital signal.
The MCP4725 DAC module is a low-power, high accuracy, single-channel, 12-bit buffered voltage output DAC with a non-volatile memory (EEPROM). Its on-board precision output amplifier allows it to achieve rail-to-rail analog output swing. The DAC input and configuration data can be programmed to the non-volatile memory by the user using I2C interface command. The non-volatile memory feature enables the DAC device to hold the DAC input code during power-off time, and the DAC output is available immediately after power-up. The device also includes a Power-On-Reset (POR) circuit to ensure reliable power-up and an on-board charge pump for the EEPROM programming voltage. The DAC reference is driven from VDD directly. In power-down mode, the output amplifier can be configured to present a low, medium, or high resistance output load. The device has a two-wire I2C compatible serial interface for standard (100 kHz), fast (400 kHz), or high speed (3.4 MHz) mode.
• 12-bit resolution
• EEPROM memory
• Power down mode
• Voltage: 2.7 V to 5.5 V
• Transmission speed up to 3.4 Mbps
• Default I2C address 0xC0
The module draws less than 0.4 mA from the power supply with zero load at the output, and will deliver around 25mA to the load. It can accept up to 4096 possible inputs (12 bit DAC) to provide the analog output. Here, an output value of 0 is zero and an output value of 4095 is full scale, where the full scale value is determined actually by the reference voltage supplied to VCC pin. In this light, it is important to take note that the power supply at the VDD pin should be clean as possible for good DAC performance.
I used the MCP4725 module to generate a saw wave and a sine wave.
The code will work on any supported microcontroller. I used an 16F18855 Xpress board as it was on the bench.
Connectivity
The connections are very simple. VCC and GCN, SDA and CLK to the I2C bus, and the OUT is where the generated signal will be found.
I2C discovery: I used the ”Show_I2C_Devices_to_Serial_Terminal.gcb” to validate the I2C bus and the I2C address of the MCP4725 module.
I connected the Xpress board to the USB cable, started the Terminal application (at 19200 BPS) and compiled and loaded the HEX. The following was shown:
This shows two devices on the I2C bus. 0xC0 is the MCP4725 module.
Generate a Saw Tooth Wave: I took the discovery program as my baseline and adapted as shown below. The program send to the MCP4725 module a value between 0 and 4095 to generate the saw tooth wave.
The saw tooth wave generated by the code @ 1.15Hz
Generate a Sine Wave: The sine wave was a little more complex because I had to use the Sin() functions, and then, scale the sin result a minimum of 0, and a maximum of 4095.
The code.
The sine wave generated by the code @ 5.81 Hz
Summary
These program show the simplicity of using the MCP – these programs do not cover the full range of capabilities but by simply setting the high bits of the value sent will write (and retain the setting).
You should be able to get your MCP4725 I2C DAC module working the way you want and integrated it into your next project.
Enjoy
Last edit: Anobium 2021-02-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For a while now, I have the email in my inbox and a MCP4725 sitting in the hardware inbox ( see https://sourceforge.net/p/gcbasic/discussion/579125/thread/df8dedef68/#3dff)
I took a few moments out to write a program to answer the question ‘any progress on making a library for MCP4725?’
The MCP4725 is a simple digital to analog converter circuit to be able to work with an microcontroller.
You will find many MCP4725 I2C DAC modules on the web, or, direct from Microchip.
This is an introduction to the MCP4725 DAC module.
Digital to Analog Conversion (DAC) is not difficult to understand. A DAC simply converts digital signal into an analog signal. An analog signal, by definition, is a nominally continuous electrical signal. The analog signal path implies a continuous signal in contrast to a digital signal path, which breaks everything into on or off states. This is the main difference between analog and digital signal.
The MCP4725 DAC module is a low-power, high accuracy, single-channel, 12-bit buffered voltage output DAC with a non-volatile memory (EEPROM). Its on-board precision output amplifier allows it to achieve rail-to-rail analog output swing. The DAC input and configuration data can be programmed to the non-volatile memory by the user using I2C interface command. The non-volatile memory feature enables the DAC device to hold the DAC input code during power-off time, and the DAC output is available immediately after power-up. The device also includes a Power-On-Reset (POR) circuit to ensure reliable power-up and an on-board charge pump for the EEPROM programming voltage. The DAC reference is driven from VDD directly. In power-down mode, the output amplifier can be configured to present a low, medium, or high resistance output load. The device has a two-wire I2C compatible serial interface for standard (100 kHz), fast (400 kHz), or high speed (3.4 MHz) mode.
• 12-bit resolution
• EEPROM memory
• Power down mode
• Voltage: 2.7 V to 5.5 V
• Transmission speed up to 3.4 Mbps
• Default I2C address 0xC0
The module draws less than 0.4 mA from the power supply with zero load at the output, and will deliver around 25mA to the load. It can accept up to 4096 possible inputs (12 bit DAC) to provide the analog output. Here, an output value of 0 is zero and an output value of 4095 is full scale, where the full scale value is determined actually by the reference voltage supplied to VCC pin. In this light, it is important to take note that the power supply at the VDD pin should be clean as possible for good DAC performance.
I used the MCP4725 module to generate a saw wave and a sine wave.
The code will work on any supported microcontroller. I used an 16F18855 Xpress board as it was on the bench.
Connectivity
The connections are very simple. VCC and GCN, SDA and CLK to the I2C bus, and the OUT is where the generated signal will be found.
Program Examples
See https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/Vendor_Boards/MPLAB_Xpress_Board_PIC16F18855 for the code, or, in your demonstration folders.
I2C discovery: I used the ”Show_I2C_Devices_to_Serial_Terminal.gcb” to validate the I2C bus and the I2C address of the MCP4725 module.
I connected the Xpress board to the USB cable, started the Terminal application (at 19200 BPS) and compiled and loaded the HEX. The following was shown:
This shows two devices on the I2C bus. 0xC0 is the MCP4725 module.
Generate a Saw Tooth Wave: I took the discovery program as my baseline and adapted as shown below. The program send to the MCP4725 module a value between 0 and 4095 to generate the saw tooth wave.
The saw tooth wave generated by the code @ 1.15Hz
Generate a Sine Wave: The sine wave was a little more complex because I had to use the Sin() functions, and then, scale the sin result a minimum of 0, and a maximum of 4095.
The code.
The sine wave generated by the code @ 5.81 Hz
Summary
These program show the simplicity of using the MCP – these programs do not cover the full range of capabilities but by simply setting the high bits of the value sent will write (and retain the setting).
You should be able to get your MCP4725 I2C DAC module working the way you want and integrated it into your next project.
Enjoy
Last edit: Anobium 2021-02-15
Many thanks. That looks really useful. Really appreciate it.
Cheers for posting.
looks interesting device,
Thank you!