Shop OBEX P1 Docs P2 Docs Learn Events
Greater than 8bit D to A converter? — Parallax Forums

Greater than 8bit D to A converter?

Alex41Alex41 Posts: 112
edited 2008-01-18 00:17 in General Discussion
Hello,

I'm using SX/B and see that the PWM command can be used as a 8 bit D to A converter.

What can I do if I need greater sesolution than 8 bit? say 10 bit, or maybe 12?

Everyone seems to point to the PWM command, but are there 10 or 12 bit DAC chips?

I guess these would use the SERIN and SEROUT command to control them?

Thanks,
Alex

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If at first you don't succeed, then skydiving is not for you.

Comments

  • BeanBean Posts: 8,129
    edited 2008-01-10 16:00
    I have used the AD5641 14-bit DAC before. It's less than $5 from digikey. You would use the SHIFTOUT command to control them. I can post code if you need it.

    [noparse][[/noparse]edit] The AD5641 does require a well regulated input. It does NOT have an internal voltage reference.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 1/10/2008 4:12:45 PM GMT
  • JonnyMacJonnyMac Posts: 9,218
    edited 2008-01-10 16:01
    The LTC1298 is an easy-to-use, dual-channel 12-bit ADC. I've attached a bit of code that you might find helpful. SHIFTOUT and SHIFTIN are used to communicate with the chip.
  • BeanBean Posts: 8,129
    edited 2008-01-10 16:13
    Jon,
    I think he is looking for a DAC instead of an ADC.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • JonnyMacJonnyMac Posts: 9,218
    edited 2008-01-10 16:46
    Whoops... the Starbucks hadn't kicked in. The LTC1257 is a dual-channel, 12-bit DAC. Like the LTC1298, it's easy to use.
  • James NewtonJames Newton Posts: 329
    edited 2008-01-10 19:19
    There isn't any reason why the standard 8 bit PWM routines couldn't be expanded to provide 10 or 16 bit PWM output. Sadly, I have no such routines in the library. If you make one, please share it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    James Newton, Host of SXList.com
    james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
    SX FAQ / Code / Tutorials / Documentation:
    http://www.sxlist.com Pick faster!



  • Alex41Alex41 Posts: 112
    edited 2008-01-10 19:48
    Thanks for the quick reply!

    Yes, SHIFTIN/SHIFTOUT is what I meant to say. That's what happens when I rely on my memory.

    I looked at the datasheet for the LTC1257 and it looks like it has a voltage reference. Isn't the voltage reference to give it a sort of base voltage to work with which will make it more accurate?

    A few lines of code would be great if it isn't too much trouble. I have the ADC8031 working on my SX Tech board and have that figured out, just haven't found anything on how to run a DAC converter in SX/B. I would assume its a sort of reverse process to the ADC, but using the SHIFTOUT command?

    It looks like I would need to use a 12bit DAC, I now need to split the word variable into LSB and MSB to send the data to the DAC?

    Alex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • PJMontyPJMonty Posts: 983
    edited 2008-01-10 23:49
    Alex,

    Just curious - what do you need the extra bits of DAC resolution for?

    Thanks,
    PeterM
  • Alex41Alex41 Posts: 112
    edited 2008-01-11 18:55
    I know I need a decent amount of resolution, but not sure exactly what·I need until I build one and test it. I do know·I need more than 8 bit. Figured I'd jump to 12 and try that first. Those chips don't seem too expensive. I've got the A to D conversion figured out code-wise, just need to do the same for D to A.

    I'm all about keeping it simple and Jon says the LTC1257 chip is easy to use, so I'll try that first.

    Alex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-01-12 12:52
    Since the SX is an 8-bit device, you might as well jump to 16 bits rather than fool with coding something in between. You can always drop what you don't need to use by shifting left or right.

    If you are using the SX48, it actually has a 16bit resolution timer built into it. So, the coding would be more concis

    There are at least three differnt hardware configurations for DAC. a resister ladder as presented in Guenter's text; R2R resistor networks; and Sigma-Delta configured as output. Also I believe the PWM may quality as a fourth that uses a filtering/smoothing network to get your output.

    Each has its own pros and cons regarding how many pins it uses, how wide the frequency response is, and how smooth you output is.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 1/12/2008 1:02:22 PM GMT
  • Alex41Alex41 Posts: 112
    edited 2008-01-12 22:00
    I've thought about using the output of the TIMER on the SX-48 chip.

    Lately I have been getting much more familiar with the TIMER commad and learning the ins and outs of it, with help from this forum. I do have a few SX-48 boards and may try that and see how it works.

    Thanks for the ideas. Keep 'em coming - I'm here to learn.

    Alex



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • Alex41Alex41 Posts: 112
    edited 2008-01-13 03:04
    Jon,

    I have a ask a question or two about the code you posted for reading the LTC1298.

    I see the subroutine "FUNC RD_1298"· contains the actual communication with the ADC chip.

    What does the rest of the program do? Is that all necessary to initialize the chip and understand its output? If that is the case using the LTC1298 is waaaayyy over my head. Or is the rest of the code for displaying the output in different forms of some kind? Hex and string?·I see the "TX" pin is used to transmit the data to a host. Would this host be another chip, or a LCD display?

    Thanks for your help,
    Alex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • JonnyMacJonnyMac Posts: 9,218
    edited 2008-01-13 06:19
    A lot of that code has to do with formatting routines so that you can send the ADC values to a terminal program or serial LCD. It's really quite easy; just take your time and it will come to you -- it's not over you head.
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2008-01-13 10:44
    Alex,

    the simplest DAC you can realize with the SX is a PWM output, filtered by an RC low-pass.

    The 8-bit code looks like this:

        add    DACAcc, DACVal
        movb   DACOut, C
    
    



    Put these instructions inside a loop, or have them periodically executed by an ISR. The output signal (without the filter) will be a square wave with a duty cycle from 0 up to almost 100%, depending on the contents of DACVal. With the filter, the voltage across the capaitor will be from 0 to almost 5 Volts.

    If you like, you can expand this into a 16-bit version like this:

       add  DACAccL, DACValL
       mov  w, #1
       snc
       add  DACAccH, w
       add  DACAccH, DACValH
       movb DACOut, C
    
    



    Two bytes are here used for DACAcc and for DACVal. When the addition of DACAccL and DACValL overflows, i.e. when carry is set, you need to increment DACAccH by one. You can't use addb DACAccH, c, or inc DACAccH to achieve this because both instructions don't set the carry in case they cause an overflow in DACAccH. This is why I use w to add 1 to DACAccH when c is set.

    If this version is good enough for your project depends on the response time you need, and the 16-bit version is a lot slower than the 8-bit version but you might give it a try.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • Alex41Alex41 Posts: 112
    edited 2008-01-16 14:15
    Guenther,

    Thank you for the code. I've been using SX/B lately and never used assembly before. I do have your book and trying to understand your code from it. Just a few questions,

    The DAC**** are all variables? Also I assume the DACOut is the name of the output pin?



    Thank you,

    Alex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • BeanBean Posts: 8,129
    edited 2008-01-16 16:23
    Alex,
    · Try this...
    DEVICE          SX28, OSCHS2, TURBO, STACKX, OPTIONX
    FREQ            50_000_000
     
    DACOut  PIN RB.0 OUTPUT
     
    tempW   VAR WORD
     
    DACAcc  VAR WORD
    DACVal  VAR WORD
     
    INTERRUPT NOPRESERVE 2_000_000
      DACAcc = DACAcc + DACVal
      DACOut = C
    RETURNINT
     
    PROGRAM Start
     
    Start:
      DO
        FOR tempW = 0 TO 99
          DACVal = tempW * 661
          PAUSE 100
        NEXT
      LOOP
    END
     
    

    Since the interrupt rate is 2,000,000 the update rate is only about 30Hz (2,000,000 / 65536). So I hope to don't need the output to change rapidly.

    Oh, and don't forget the resistor and cap on the output.

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 1/16/2008 5:49:41 PM GMT
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2008-01-16 17:37
    Alex,

    yes, your assumptions regarding DACAcc, DACVal, and DACOut are right, and Bean's example nicely translates my cryptic assembly code into SX/B - thanks Bean!

    As Bean pointed out, this DAC version has a pretty slow response-time. In case you want to generate fast output waveforms, like audio signals, this does not work. For such applications, you might consider using something like an R-2R ladder network, as I have described it in my book. Although my example is 8 bit only, it can also be expanded to more bits, but each bit costs one more SX output pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • Alex41Alex41 Posts: 112
    edited 2008-01-17 23:43
    Thanks for the help once again, the support is great here. The help makes understanding the SX much easier, especially considering there isn't that much documentation on it (SX/B wise).



    Bean,

    The program looks great, short and simple too. What I'm looking to do is read an input voltage with a ADC then· make a voltage output, either adding some voltage to it, or subtracting some voltage from the original. At first I was looking for a DAC chip to do this, but doing it with software seems much easier. I see your program runs an interrupt, will this cause any problems if I'm reading a ADC chip using SHIFTIN? Will the program slowdown when the SHIFTIN command runs? The calculations for adding/subtracting voltage would be only a few lines. The 30Hz update of your program is plenty fast, I would guess 10Hz may even be enough.

    Guenther,

    I did read the section in your book about the R-2R ladder network. I also read the Parallax book "Basic Analog and Digital" The description in it would be fairly straight forward to convert it to SX/B and add a few more bits of resolution. It looks fun to build just for good practice also.

    Thanks again for the help,

    Alex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If at first you don't succeed, then skydiving is not for you.
  • BeanBean Posts: 8,129
    edited 2008-01-18 00:17
    Alex,
    The interrupts will cause the SHIFTIN to be somewhat slower, but it shouldn't effect the data at all.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
Sign In or Register to comment.