User Tools

Site Tools


mmbasic:picomite_mcp4922_dac_on_spi

PicoMite: MCP4922 DAC on SPI

Digital Analog Converter Chip: MCP4922, 2-channel, 12bit (also other versions available)

I used this DAC before and think it is a nice chip.

Datasheet: https://www.mouser.de/datasheet/2/268/21897a-70809.pdf

Be sure to get the active LOW-Pins LDAC_ and SHDN_ right, LDAC_ to LOW/GND will trigger the conversion every time the CS_ is rised, so we can save one Pin on the Picomite. Tie SHDN_to VDD to have the chip work.

Here is some code which works for me and might get you started.

' MCP4922 Dual 12bit DAC
SetPin GP2,GP3,GP4,SPI

SetPin GP6, DOUT
Pin(GP6) = 1

SPI open 4000000,0,16

Do
For a% = 0 To 4096-8 Step 64

' CS Down (LOW Active)
Pin(GP6)=0

'  DACn Write Buffer Gain_ Shutdown_
'           DWBGS
junk = SPI(&B0111000000000000 + a%) ' 1st DAC
Pin(GP6)=1

Pin(GP6)=0
junk = SPI(&B1111000000000000 + a%) ' 2nd DAC

' CS
Pin(GP6)=1

'Print a%
'Pause 300

Next a%
Loop

SPI Close
mmbasic/picomite_mcp4922_dac_on_spi.txt · Last modified: 2024/02/24 17:31 by gerry