Results 1 to 2 of 2

Thread: MCP4822 Dual 12 bit DAC - example program

  1. #1
    Senior Member
    Join Date
    Jan 1970
    Location
    Cambridge, UK
    Posts
    416

    Default MCP4822 Dual 12 bit DAC - example program

    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

  2. #2
    Moderator
    Join Date
    Mar 2008
    Location
    Western Australia
    Posts
    11,127

    Default

    Well done for posting a "modern" version for the X2 parts.

    Back in 2010 I posted demo code for X1 parts using bit-bashed methods (since i2c and HSPI use the same IO pins)
    http://www.picaxeforum.co.uk/showthr...Converters-101
    westaust55

    Hey Hamlet, 2B OR NOT 2B = $FF

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •