Saturday, July 18, 2020

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter

Microchip MCP492X SPI Digital To Analog Converter

MCP492X is a 12-bit digital to analog converter (DAC) with SPI interface. MCP4921 is a single output DAC while MCP4922 has two configurable DAC. This SPI DAC could clock up to 20 MHz.

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter DAC AVR ATMega Serial Peripheral Interface Microchip
A sample of this programming example


In this post I use MCP4922 I possess. I bought this chip from Futurlec on-line store a few years ago. It comes with an easy to prototype 14-bit DIP.


Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
MCP4922 14-pin DIP Package

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
MCP4922 14-pin DIP pin diagram

These are the pins description of this IC:
  1. VDD  is positive supply voltage for internal device working (2.7 V to 5.5 V).
  2. NC - No Connection
  3. CS - Chip Select Input
  4. SCK - Serial Clock Input
  5. SDI - Serial Data Input
  6. NC - No Connection
  7. NC - No Connection
  8. LDAC - is active low. It transfers DAC setting from serial latches to output latches.
  9. SHDN - Hardware shut down input
  10. VOUTB - DAC_B Output
  11. VREFB - DAC_B Voltage Input (AVSS To VDD)
  12. AVSS - Analog ground
  13. VREFA - DAC_A Voltage Input (AVSS to VDD)
  14. VOUTA - DAC_A Output
The data format transfers to this device is 16-bit wide. One upper nibble is the DAC configuration bits while the remaining 12-bit is the DAC output value. The output value to DAC is up 4096 maximum.

DAC output voltage - VOUT lists as follow:
Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
Where,
  • VREF is DAC voltage reference input. It could be DAC_A or DAC_B
  • G is output voltage gain, 1X or 2X.
  • DN is 12-bit DAC data input value
  • 2^N is the DAC resolution. In this case, the resolution is 12-bit yield the decimal value to 2^12 = 4046
The 16-bit SPI data representation lists below.

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
MCP4922 Write Command Register


Each bit functions as below.
  • Bit 15 - A/B - Write '0' for DAC_A, otherwise DAC_B
  • Bit 14 - BUF - Write '0' for Unbuffered, otherwise Buffered.
  • Bit 13 - GA - Write '0' 1x Gain, otherwise 2x Gain.
  • Bit 12 - SHDN - Write '0' to disable output buffer, otherwise enable the output buffer.
  • Bit 11:0 - D11:D0 - 12-bit digital data DAC output ranges from 0 to 4095 (4096 in total).
Data transfer to this device is 16-bit, we need to send 8-bit twice with only on latching pulse.

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
Writing the command to MCP4922. External wiring is not include here.

Interfacing And Programming With Atmel Studio 7 In C

In this example, I use both output DAC. Both DAC outputs the maximum 12-bit value, 0xFFF or 4096. With 2X gain, DAC A generate the output voltage nearest to 10 V. Similarly, using 1X gain, DAC B generate output the voltage nearest to 5 V. The sample of this program lists below. The reference voltage for both DAC is 5 V.

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter DAC AVR ATMega Serial Peripheral Interface Microchip
A sample of this programming example

C source code:


Schematic Diagram

Interfacing ATMega32 SPI to MCP4922 Dual 12-bit Digital To Analog Converter
Schematic Diagram for simulation 



2 comments:

  1. Well done. Can you do this in a similar way with Arduino Uno? I am about to control a joystick of a wheelchair with Arduino and remote control. The joystick, however, requires 5 clear sine lines. That's why I got 3 DAC MCP4922 for it. But I can't do it, I don't know my way around that well. Do you have the time and inclination to realize something like that and publish it? You will also get a present from me.
    greetings
    Archie

    ReplyDelete
    Replies
    1. Hi
      Here I'm spending time to complete my work on AVR ATMega32 and PIC examples.
      However Arduino requires more physical hardware and time consuming to prototype.
      Thanks

      Delete

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)