Shop OBEX P1 Docs P2 Docs Learn Events
MCP4822 - 2 channel, 12-bit DAC.. Got Code?? — Parallax Forums

MCP4822 - 2 channel, 12-bit DAC.. Got Code??

davekorpidavekorpi Posts: 20
edited 2013-12-27 19:01 in Propeller 1
Hi all!

Hope EVERYONE had an AWESOME Holiday for sure!

Anyone know if the code here..
MCP4922 - 2 channel, 12-bit DAC


Will work for the MCP4822- 2 Channel, 12-bit DAC with some small mods??

I have a bunch of MCP-4822's that I want to use and I wonder if yall know if the MCP4922 code in the OBEX will work...

Reference:
http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf


http://ww1.microchip.com/downloads/en/DeviceDoc/22249A.pdf

I have tried it and can not get the things to sing... I have a beautiful +5 VDC Ref
OutZS := 2048
DAC.Set(0, OutZS) ' Channel A 0-5 VDC half-range 2048 = 2.5V with 5V reference)
DAC.Set(1, OutZS) ' Channel B 4-20 mA half-range 2048 = 2.5V with 5V reference)

Here is a snagit of the quick scheemo I am breadboarding..

http://www.screencast.com/t/gtWVaQngHd

Thanks a million yall!!!

I know.. Why don't I get some 4922's??!!! Wellll.. cuz I have 4822's and PROBABLY some smart folks KNOW that they SHOULD both work the same... I ain't that smart by golly!

Comments

  • T ChapT Chap Posts: 4,223
    edited 2013-12-26 20:57
    Can you post the actual code you are testing? Have you tested with LDAC at vss?

    Have you verified the pin assignments?

    DAC.Init(11, 12, 13) 'CS, SCK, SDI respectively
  • davekorpidavekorpi Posts: 20
    edited 2013-12-26 21:22
    T Chap:

    FINAL ANSWER!!!

    The MCP4822 will drive the MCP4922 directly..


    when I am not a weenie and forget to hook up the VDD Pin!



    Sorry for the hassle guys and gals. My stupidity on the wiring..

    If you want to get 0-4.096 so I adjust the Gain value to 0 instead of the 1 that I was also messing with.

    ' Channel, Gain, Shutdown, Value
    data := (Channel << 15) + (0 << 13) + (1 << 12) + Value 'Bit 13 = 0 for 5 VDC

    See the code by Ryan David with a few notes of mine...
    ''******************************************************************
    ''*  MCP4921/4922 Driver v0.1                                      *
    ''*  Author: Ryan David (coding tips from Timmoore - thanks!)      *
    ''*  Date Modified: 9-5-09                                         *
    ''*                                                                * 
    ''*  Changelog:                                                    *
    ''*     Rev 0.1 (9-5-09)                                           *
    ''*        -Inital Release                                         * 
    ''*                                                                *
    ''*  Very simple MCP4921/4922 Driver written in spin.  Eventually  *
    ''*  I would like to convert it over to assembly.  I still need    *
    ''*  check the output on the scope, but it should be okay.  The    *
    ''*  internal DAC register should be updated on the rising edge    *
    ''*  of CS with LDAC tied to ground.                               *
    ''
    ''
    ''              *Pin 1
    ''              &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    ''          5V &#9472;&#9474;Vdd      VoutA&#9474;- Output A
    ''        Prop -&#9474;CS        AVss&#9474;- Ground
    ''        Prop -&#9474;SCK       AVss&#9474;- 5V (with gain bit set to 1)
    ''        Prop -&#9474;SDI       LDAC&#9474;- Ground
    ''              &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    ''                  MCP4921
    
    
    ''              *Pin 1
    ''              &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    ''          5V &#9472;&#9474;Vdd      VoutA&#9474;- Output A
    ''             -&#9474;NC       VrefA&#9474;- 5V (with gain bit set to 1)
    ''        Prop -&#9474;CS        AVss&#9474;- Ground
    ''        Prop -&#9474;SCK      VrefB&#9474;- 5V (with gain bit set to 1)
    ''        Prop -&#9474;SDI      VoutB&#9474;- Output B
    ''             -&#9474;NC        SHDN&#9474;- 5V
    ''             -&#9474;NC        LDAC&#9474;- Ground
    ''              &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    ''                  MCP4922
    
    
    ''*  Call the 'Init' routine first with the pin assignments, and  *
    ''*  then you can call the 'Set' routine with the channel (0 for  *
    ''*  channel A, 1 for channel B) and the value (from 0 to 4095).  *
    ''*  MCP4921 uses will only use channel 0                         *
    
    
    VAR
      byte CS, SCK, SDI
      
    PUB Init(inCS, inSCK, inSDI)
      CS := inCS
      SCK := inSCK
      SDI := inSDI  
    
    
      dirA[SDI]~~
      dirA[SCK]~~
      dirA[CS]~~
    
    
      outA[CS] := 1 
      outA[SCK] := 0
    
    
    PUB Set(Channel, Value) | data
      '        Channel,        Gain,       Shutdown,   Value
      data := (Channel << 15) + (0 << 13) + (1 << 12) + Value   'Bit 13 = 0 for 5 VDC
      'data := (Channel << 15) + (1 << 13) + (1 << 12) + Value  ' Standard gain bit 13 = 1 is 2.5 VDC
      data ><= 16
    
    
      outa[CS] := 0
    
    
      repeat 16
        outa[SDI] := data & 1
        outa[SCK] := 1
        outa[SCK] := 0
        data >>= 1
    
    
      outA[CS] :=1
    
    
  • T ChapT Chap Posts: 4,223
    edited 2013-12-27 10:16
    I don't have an answer for your crystal changes. As far as the 4922, I use that object and it doesn't get much simpler to set a voltage. I have not examined the 4822 protocol to see if anything looks different. In SPIN, the clocking speed to the DAC is pretty slow anyway so I don't see why any variation in the crystal would cause the issue.
     DAC_CS  = 2                   ' 12 Bit DAC Chip Sel
      DAC_SCK = 1                   ' 12 Bit DAC SCK
      DAC_SDI = 0                   ' 12 Bit DAC SDI 
    

    I am not sure your pin order matters, I took a quick glance and don't see anything obvious that requires the order be in reverse of this, but I use CS = 0, SCK= 1 SDI = 2 in that order versus what you are doing.

    Go back and verify you have 5V at the VDD pin, VSS at both the VSS and LDAC pin. If you are breadboarding this, you may want to change to a different section of the board. It does happen that bad contacts on a breadboard can cause a lot of wasted time. Try different pins on the Prop to confirm you don't have dead pins, or at least do simple output tests on prop pins to confirm you have connections.
  • Mike GMike G Posts: 2,702
    edited 2013-12-27 10:34
    The external clock must be between 4 and 8MHz for use with the PLL. See page 14 in the Propeller Datasheet.
  • T ChapT Chap Posts: 4,223
    edited 2013-12-27 10:57
    Mike, I read also there are other places that discuss larger crystals so I was not clear on whether that meant it applied to PLL use or not. Good call.
  • davekorpidavekorpi Posts: 20
    edited 2013-12-27 10:58
    OK on the clock being between 4 and 8 MHz... What do I do when I hook up a 10 MHz clock and
    I see this on page 66 of the Propeller Manual..

    http://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf

    Any hints whi it does not work as per this:

    _clkmode = xtal2 ' For 10 MHZ Xtal div by 8 on xtal1
    _clkfreq = 10_000_000 ' From Pg 66/399 of Propeller Manual

    When I do this:

    _clkmode = xtal1 + pll8x ' For 10 MHZ Xtal div by 8 on xtal1
    _xinfreq = 10_000_000

    The Serial Port works with my 10 MHz clock.. Would tell me the timing is happy...

    Know any different??

    Am I messing up?

    Anyone ever got a 4822 to work with 4922 code?
  • PublisonPublison Posts: 12,366
    edited 2013-12-27 11:34
    davekorpi wrote: »
    OK on the clock being between 4 and 8 MHz... What do I do when I hook up a 10 MHz clock and
    I see this on page 66 of the Propeller Manual..

    http://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf

    Any hints whi it does not work as per this:

    _clkmode = xtal2 ' For 10 MHZ Xtal div by 8 on xtal1
    _clkfreq = 10_000_000 ' From Pg 66/399 of Propeller Manual

    When I do this:

    _clkmode = xtal1 + pll8x ' For 10 MHZ Xtal div by 8 on xtal1
    _xinfreq = 10_000_000

    The Serial Port works with my 10 MHz clock.. Would tell me the timing is happy...

    Know any different??

    Am I messing up?

    Anyone ever got a 4822 to work with 4922 code?

    Is your 10Mhz in a crystal or a clock?

    If it is a crystal, the crystal capacitance should be 36pf to work correctly. Then you would use:

    _clkmode = xtal1 + pll8x ' For 10 MHZ Xtal div by 8 on xtal1 "It is actually multiply x 8"
    _xinfreq = 10_000_000

    I have two boards with 10 Mhz Xtals and they work fine at pll8x.

    Both were commercially produced, on being :

    http://www.parallax.com/product/28327


  • davekorpidavekorpi Posts: 20
    edited 2013-12-27 12:06
    The Clock is 10 MHz Crystal just like the one on the backpack..

    GOT SCHEEMOES on the Backpack??
    http://www.parallax.com/product/28327

    COOL!!! I used the same clock defs as you!!

    _clkmode = xtal1 + pll8x ' For 10 MHZ Xtal div by 8 on xtal1 "It is actually multiply x 8"
    _xinfreq = 10_000_000


    Can we use the 4922 code to make a 4922 (also a 2 chan SPI DAC) work???


    MCP4922 - 2 channel, 12-bit DAC


  • Mike GMike G Posts: 2,702
    edited 2013-12-27 12:20
    Ya learn something everyday... Thanks for the info.
  • PublisonPublison Posts: 12,366
    edited 2013-12-27 12:36
    davekorpi wrote: »
    The Clock is 10 MHz Crystal just like the one on the backpack..

    GOT SCHEEMOES on the Backpack??
    http://www.parallax.com/product/28327



    Schematics can be gotten of the product page, under "Downloads"

    I don't believe there is a Bill of Materials list for the part number, but I think it has been mentioned in a few threads here if you search for such things as :10 Mhz Xtal"
  • T ChapT Chap Posts: 4,223
    edited 2013-12-27 19:01
    DS22249A-page 19
    MCP4802/4812/4822
    4.1.3 POWER-ON RESET CIRCUIT

    The internal Power-on Reset (POR) circuit monitors the
    power supply voltage (VDD) during the device
    operation. The circuit also ensures that the DAC
    powers up with high output impedance (<SHDN> =0

    The devices will continue to have a
    high-impedance output until a valid write command is
    received and the LDACpin meets the input low threshold.

    5.2 Write Command
    The write command is initiated by driving the CS
    pin low, followed by clocking the four Configuration bits and
    the 12 data bits into the SDI pin on the rising edge of
    SCK. The CS pin is then raised, causing the data to be
    latched into the selected DAC’s input registers.


    The 4922 has hardware shutdown using a pin but also uses the same software power on reset + shutdown. The 4822 uses a software shutdown and on power up, the device is shutdown until you send a write command. However, it does appear that the write command for both 4922 and 4822 is identical except for bit 14 on the 4822 which is a don't care bit. I can't see why it doesn't work.

    DAC.Set(0, 0) In your code you are only setting channel A, have you tried setting B as well to see what happens? This is sounding more like a connection, noise, or bad chip problem. You do now show any bypass caps on the schematic. Any transients on the power lines could cause the chip to reset it's outputs to shutdown. Transients on CS could cause the write to be aborted. Are the Prop and the 4822 powered from the same rails? You should have a ,1uf and a 10uf at the 4822 between +5 and GND.
Sign In or Register to comment.