Monday, November 21, 2016

Teensy and MCP4922 Dual Channel 12-Bit DAC

Overview
The MCP4922 is a 12-bit, two channel, SPI-based DAC. As microcontrollers do not often have many DAC outputs (and are often limited to PWM outputs), cheap external DACs are a great way of increasing the analog output options of a microcontroller such as the Teensy.

The cost of these chips is relatively low - around AUD$3 per chip or $1.50 per DAC channel - and they don't require any additional components for basic implementation. 


Hardware
To connect the MCP4922 to a Teensy microcontroller, the following connections should be made:

  • Teensy 5V or 3.3V (depending on model) to MCP4922 VDD (Pin 1)
  • Teensy SPI Chip Select pin (either user-designated or as defined in the SPI library) to MCP4922 CS (Pin 3)
  • Teensy SPI Serial Clock pin (as defined in the SPI library) to MCP4922 SCK (Pin 4)
  • Teensy SPI Digital Out (as defined in the SPI library) to MCP4922 SDI (Pin 5)
  • Teensy 5V or 3.3V (depending on model) to MCP4922 V REF A (Pin 13)
  • Teensy ground to MCP4922 VSS (Pin 12)
  • Teensy 5V or 3.3V (depending on model)to MCP4922 V REF B (Pin 11)
  • Teensy 5V or 3.3V (depending on model) to MCP4922 SHDN
  • Teensy ground to MCP4922 LDAC
  • MCP4922 V OUT A (Pin 14) is the output for DAC A
  • MCP4922 V OUT B (Pin 10) is the output for DACB





Software
The SPI library can be used to easily write data to the DAC. In the example below,  a function is written that has a chip select pin value, a DAC channel value and a DAC output value between 0 - 4095. This function writes to the SPI bus and updates the DAC output.

Download here: http://milkcrate.com.au/_other/downloads/arduino/MCP4922_DAC/




0 comments: