Shop OBEX P1 Docs P2 Docs Learn Events
SHIFTOUT decimal value output data? — Parallax Forums

SHIFTOUT decimal value output data?

PBasicBeginnerPBasicBeginner Posts: 3
edited 2011-03-23 09:08 in BASIC Stamp
Hi,

I'm just curious if its possible to SHIFTOUT a decimal value i.e "6.5" on the STAMP?

I've built a D/A converter using the MAX518 chip, each time a push button has been pushed, the output to the MAX518 must increase by 2.5, and I'm using SHIFTOUT to communicate with the chip.

The maxoutput to the chip is a 255 and the minimum is 100. I'm really lost as how you would do this as the STAMP doesn't use integer math.

Any help would be greatly appreciated, thanks!

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2011-03-21 18:54
    Sorry, I'm not having a go at you here, but could you re-phrase all that?
    2.5 what?
    You have an 8 bit DAC, that means there are 256 steps, your last step
    is your reference / 256 and every step thereafter. If you need a step of 2.5,
    then your reference is 2.5 * 256 = 640
    Or, I'm off by a step, but you get the general idea?
    No worries, some greater intelligence than mine will be along shortly to
    contradict me and the universe will come right.
    The datasheet has applications, I looked.

    PE -- It says [your datasheet states] your REFs are internally connected to V_DD, so your steps are 5V / 256 = 0.0195V per step:
    "The MAX518 has both DAC’s reference inputs
    connected to VDD. Figure 15 shows a simplified diagram
    of one DAC."
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-21 21:50
    The Stamps use only integer math, specifically unsigned 16 bit integer arithmetic. There are some provisions to use 2's complement integer arithmetic as well. It's possible to scale integer arithmetic to deal with fractional values. Do you understand what PJ was describing? The MAX518 uses an 8 bit unsigned value ranging from 0 to 255 to produce voltages from 0 to Vref in steps of Vref / 256. If you need voltage steps of 2.5V, then you have to pick Vref so that some N * Vref / 256 = 2.5V.
  • PBasicBeginnerPBasicBeginner Posts: 3
    edited 2011-03-23 07:26
    Thank you for the responses, and my apologies for the late response and the first post.

    Like you said, the MAX518 uses a 8 bit unsigned value ranging from 0 to 255.

    This is how I would normally send a value to the chip,
    SHIFTOUT 0, 1, MSBFIRST, [%01011000\8,0\1,255\8,0\1,0\8,0\1]

    255 being the value I'm sending to the chip resulting in an output of 5V, that works all fine and great.

    However, how could I send a value of a decimal number, i.e "2.5" not volts, but in regards to the range that the MAX518 uses. i.e I'd like to do this.
    SHIFTOUT 0, 1, MSBFIRST, [%01011000\8,0\1,2.5\8,0\1,0\8,0\1]

    This would result in a output of .05 volts. However, since the Stamp uses only integer math I'm a little lost as you could do this?

    Would the */ operator work perhaps? All I really need is just a point in the right direction, if the */ operator will work for this, then I will figure it out myself, I know a lot of people don't like to spoon feed so I'll try my best.

    (Sorry if this is still as un-articulated as my first post)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-23 07:42
    You can't do it. The MAX518 only accepts an 8 bit integer value. If you need finer control of the output voltage, you need to pick a higher resolution DAC, maybe one that accepts a 9-bit or 10-bit integer value to give you values from 0 to 511 or 0 to 1023. With the same reference voltage, that would give you smaller step sizes, but it's all integers. With a 9-bit DAC, your "2.5" would be 5.
  • PBasicBeginnerPBasicBeginner Posts: 3
    edited 2011-03-23 09:08
    Mike Green wrote: »
    You can't do it. The MAX518 only accepts an 8 bit integer value. If you need finer control of the output voltage, you need to pick a higher resolution DAC, maybe one that accepts a 9-bit or 10-bit integer value to give you values from 0 to 511 or 0 to 1023. With the same reference voltage, that would give you smaller step sizes, but it's all integers. With a 9-bit DAC, your "2.5" would be 5.

    Ah right, didn't think it was possible. Thank you very much for the help!
Sign In or Register to comment.