MCP4822 Dual 12 bit DAC - example program

matherp

Senior Member
As the title says...
Code:
#picaxe 28X2
setfreq em64
'
' example program for driving the MCP4822 dual 12 bit DAC
' using hardware SPI
'
' outputs a ramp to both DAC outputs
'
symbol SDO=c.5   ' pin assignment for SPI data - not needed for HSPI use
symbol SCK=c.3   ' pin assignment SPI clock - not needed for HSPI use
symbol cs=b.0    ' chip select
symbol latch=b.1 ' data latch
hspisetup spimode00,spifast 'chip works fine in fastest mode
high cs
high latch
w0=0
do 'loop time about 0.44 msec (64 values in 28 msec)
	b1=b1 | %00010000'set the not-shutdown bit high and channel bit to A, gain to 2 (0-4.095V)
	low cs
	hspiout (b1,b0)
	high cs
	b1=b1 | %10100000 ' or in the channel B bit and set the gain to 1 (0-2.047V)
	low cs
	hspiout (b1,b0)
	high cs
	pulsout latch,1 ' move the input registers to the DAC
	w0=w0+64 ' jump 64 steps at a time to get a reasonable scope trace
	b1=b1 & %00001111 'clear the control bits and wrap w0 at 4096
loop
 
Top