Shop OBEX P1 Docs P2 Docs Learn Events
Stamp Math Questions — Parallax Forums

Stamp Math Questions

ArchiverArchiver Posts: 46,084
edited 2003-02-26 19:44 in General Discussion
I am having a little problem getting may hands around some math used in the
Stamp. I am using a MAX186 to read data from an AMP100 hall effect current
sensor. (http://www.ampsense.com/AMP100.html )

The sensor puts out an offset voltage so that 0 amps is read as 2.5 volts. Full
range for the 100 amps is 1.9V or 19mV per amp. I am using the following to read
the ADC into the Stamp and then outputting it to debug. Not all of the code is
here but you should get the idea.

Shiftin Din, clk, msbpost, [noparse][[/noparse]ADCin\12]
Debug dec ADCin dig 3,"."dec ADCin dig 2, dec ADCin dig 1

When run I get an output in debug that reads 2.52 which is correct. What I want
to do is offset this output so it reads 0. I just haven't figured out how to
properly do math on ADCin. What the main goal is to feed this info to StampPlot
to plot a graph of the current draw. Anyone have any pointers or tutorials on
performing math on binary numbers such as ADCin? Thanks!


Hank

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 02:31
    Hi Hank,

    It sounds like the resolution of your ADC is 1 mV. When you use the
    DIG operator, the rightmost digit is DIG 0, not DIG 1.

    But I don't think you need to use DIG.

    mA var word
    mV var word
    ADCin var word
    mV=ADCin-2500 ' subtract the 2500 millivolt (2.5V) offset
    debug dec mV,cr ' display raw reading, mV above 2500
    debug dec mV/1000, ".", dec3 mV,cr ' display volts
    mA=mV */ 13474 ' convert to milliamps
    debug dec mA,cr ' display milliamps
    debug dec mA/1000, ".", dec3 mA,cr ' display amps


    Now, you might be asking, why the factor */13474 to convert from
    millivolts to milliamps? You said the calibration is 19 millivolts
    per amp, or that is the same as 19 millivolts per 1000 milliamps.
    Divide 1000/19=52.6316. That is the multiplier you would use on a
    calculator to get from millivolts to milliamps.
    milliamps = 52.6316 * millivolts

    To make it work with the stamp, multiply 52.6316 times 256, round
    off, and you get 13474.

    The stamp does the problem like this: 13474/256. The division by
    256 is implied in the */ operator. (Divide it on your calculator and
    show yourself that 13474/256 is very close to 52.6316).
    milliamps = 13474 */ millivolts

    -- Tracy




    >I am having a little problem getting may hands around some math used
    >in the Stamp. I am using a MAX186 to read data from an AMP100 hall
    >effect current sensor. (http://www.ampsense.com/AMP100.html )
    >
    >The sensor puts out an offset voltage so that 0 amps is read as 2.5
    >volts. Full range for the 100 amps is 1.9V or 19mV per amp. I am
    >using the following to read the ADC into the Stamp and then
    >outputting it to debug. Not all of the code is here but you should
    >get the idea.
    >
    >Shiftin Din, clk, msbpost, [noparse][[/noparse]ADCin\12]
    >Debug dec ADCin dig 3,"."dec ADCin dig 2, dec ADCin dig 1
    >
    >When run I get an output in debug that reads 2.52 which is correct.
    >What I want to do is offset this output so it reads 0. I just
    >haven't figured out how to properly do math on ADCin. What the main
    >goal is to feed this info to StampPlot to plot a graph of the
    >current draw. Anyone have any pointers or tutorials on performing
    >math on binary numbers such as ADCin? Thanks!
    >
    >Hank
  • ArchiverArchiver Posts: 46,084
    edited 2003-02-26 19:44
    Thanks for the info Tracy. It worked much better then what I was trying to do.
    One day I'll fully understand all of these "special" math functions... [noparse]:)[/noparse]

    Hank

    Original Message
    From: "Tracy Allen" <tracy@e...>
    To: <basicstamps@yahoogroups.com>
    Sent: Tuesday, February 25, 2003 9:31 PM
    Subject: Re: [noparse][[/noparse]basicstamps] Stamp Math Questions


    > Hi Hank,
    >
    > It sounds like the resolution of your ADC is 1 mV. When you use the
    > DIG operator, the rightmost digit is DIG 0, not DIG 1.
    >
    > But I don't think you need to use DIG.
    >
    > mA var word
    > mV var word
    > ADCin var word
    > mV=ADCin-2500 ' subtract the 2500 millivolt (2.5V) offset
    > debug dec mV,cr ' display raw reading, mV above 2500
    > debug dec mV/1000, ".", dec3 mV,cr ' display volts
    > mA=mV */ 13474 ' convert to milliamps
    > debug dec mA,cr ' display milliamps
    > debug dec mA/1000, ".", dec3 mA,cr ' display amps
    >
    >
    > Now, you might be asking, why the factor */13474 to convert from
    > millivolts to milliamps? You said the calibration is 19 millivolts
    > per amp, or that is the same as 19 millivolts per 1000 milliamps.
    > Divide 1000/19=52.6316. That is the multiplier you would use on a
    > calculator to get from millivolts to milliamps.
    > milliamps = 52.6316 * millivolts
    >
    > To make it work with the stamp, multiply 52.6316 times 256, round
    > off, and you get 13474.
    >
    > The stamp does the problem like this: 13474/256. The division by
    > 256 is implied in the */ operator. (Divide it on your calculator and
    > show yourself that 13474/256 is very close to 52.6316).
    > milliamps = 13474 */ millivolts
    >
    > -- Tracy
    >
    >
    >
    >
    > >I am having a little problem getting may hands around some math used
    > >in the Stamp. I am using a MAX186 to read data from an AMP100 hall
    > >effect current sensor. (http://www.ampsense.com/AMP100.html )
    > >
    > >The sensor puts out an offset voltage so that 0 amps is read as 2.5
    > >volts. Full range for the 100 amps is 1.9V or 19mV per amp. I am
    > >using the following to read the ADC into the Stamp and then
    > >outputting it to debug. Not all of the code is here but you should
    > >get the idea.
    > >
    > >Shiftin Din, clk, msbpost, [noparse][[/noparse]ADCin\12]
    > >Debug dec ADCin dig 3,"."dec ADCin dig 2, dec ADCin dig 1
    > >
    > >When run I get an output in debug that reads 2.52 which is correct.
    > >What I want to do is offset this output so it reads 0. I just
    > >haven't figured out how to properly do math on ADCin. What the main
    > >goal is to feed this info to StampPlot to plot a graph of the
    > >current draw. Anyone have any pointers or tutorials on performing
    > >math on binary numbers such as ADCin? Thanks!
    > >
    > >Hank
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
Sign In or Register to comment.