Monday, November 21, 2016

MIDI-controlled 12-bit DAC

Overview
The MCP4922 is a 12-bit, two channel, SPI-based DAC - and can be easily connect to a studio setup using a Teensy via MIDI!This is an easy way of adding a 0 - 5V or 0 - 3.3V 4096-step DAC to a MIDI sequencing environment.

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
Hardware connection is identical to the previous post on the MCP4922. 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.

This function is then connected to MIDI via MIDI control messages.

This particular sketch supports both high res MIDI and normal res MIDI. 

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





0 comments: