spi 12bit digital to analog chip
Posted: Tue Aug 06, 2013 2:07 am
i'm using a microchip mcp4921, these chips are easy to use with the spi protocol,
since this is a 12bit dac, you can get 4096 different values, using a 5v referance
to figure out which number to send to the spi port for desired output voltage is easy to
there is a couple things left to do, you have to set bits 12 and 13 in the spi 16 bit message to do this
then convert the 16 bit variable into two 8 bit variables to send
pull chip select pin low, send high variable char, send low variable char set chip select pin hit
this chips is very quick to make a triangle waveform by looping 0-4095-0 in this flowchart i created a quick draw up as an example of manually picking out a voltage, using rc5 and a remote as a keypad, you can type in a voltage value then press the blue button to set it, top lcd line shows the commanded voltage, bottom line shows the commanded 12bit value here is a cheetsheet for hook up and operation
since this is a 12bit dac, you can get 4096 different values, using a 5v referance
Code: Select all
5volts/4096 = .001220703125 mv_per_step
Code: Select all
chip_send_number = desired_voltage / mv_per_step
Code: Select all
chip_send_number=chip_send_number | 3 << 12
Code: Select all
high=(chip_send_number>>8) & 255
low=chip_send_number & 255
this chips is very quick to make a triangle waveform by looping 0-4095-0 in this flowchart i created a quick draw up as an example of manually picking out a voltage, using rc5 and a remote as a keypad, you can type in a voltage value then press the blue button to set it, top lcd line shows the commanded voltage, bottom line shows the commanded 12bit value here is a cheetsheet for hook up and operation