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

Basic Stamp 2 Math

WD8MBEWD8MBE Posts: 8
edited 2011-10-27 06:52 in BASIC Stamp
I am using a LT-1298 and Basic Stamp 2 to read voltages. I am getting data from the LT-1298 and need to convert it. The formula I am trying to use is AD=AD*5000/4095. I should get 2589.74 which is actually 2.589 volts. However, using this formula and displaying AD with Debug I get 13.

Can someone tell me what I am doing wrong? The 5000 is 5 volt reference.

SHIFTIN Din,CLK,MSBPOST,[AD\12]

Now lets say AD = 2121 (2121*5000)/4095=2589.74 But Debug Terminal displays 13.

I am new to this and need help.

Thanks,
Tom

Comments

  • LeonLeon Posts: 7,620
    edited 2011-10-12 12:00
    I don't know much about the Stamp, but you are probably going outside the range for a variable with 2121*5000. Try 2121*5 and multiply your result by 1000.
  • RDL2004RDL2004 Posts: 2,554
    edited 2011-10-12 19:00
    Tracy Allen has some good info on doing math on the BS2.

    http://www.emesystems.com/BS2index.htm
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-10-15 10:21
    Here are some possibilities. The reasoning for this is at http://emesystems.com/BS2math1.htm

    result = 2121 */ 3125
    which gives 25891 as the result
    x = 2121
    result = x */ 3125   ' calculate
    result = result + 5 / 10  ' round off to 3 decimals
    debug dec result/1000, ".", dec3 result,cr
    
    displays 2.589

    Another method using **:
    x=2121
    result = x ** 14464 + x
     debug dec result/1000, ".", dec3 result,cr
    
  • WD8MBEWD8MBE Posts: 8
    edited 2011-10-27 06:52
    My thanks to everyone who has answered back.

    The plan is to put a BS2, XBee setup connected to my solar/wind generator battery bank. Using the LT-1298 to monitor voltages and having information sent to the house receiving on another XBee and displaying the voltage data on my PC. Plus graphing and logging the data. Monitoring the performance of my battery bank.

    My test setup is as follows: I am using a steady 12vdc source feeding into a voltage divider (12vdc "in" with 4vdc "out") plus a zener diode to make sure the LT-1298 does not get move then 5vdc. Course the LT-1298 does the A?D and the BS2 the math and send the data thru the XBee.

    I somewhat understand the formulas given, except some of the numbers posted. Tracy, you 3125 and 14464. I have no clue where these numbers come from. I am just trying to understand all the formulas and come up with a solid solution for the math and giving me a good representation of the voltages read by the LT-1298.

    As a further note: My battery bank presently consists of (4) 6vdc deep cycle batteries. Parallel/series configuration for 12vdc out. Maybe I should set the equipment up to read each battery voltage? Would not take much to add another LT-1298.

    Anyway, my overall goal is to be able to read the battery bank voltages in the house on my PC. Any help assistance or advice is greatly appreciated.

    Tom
Sign In or Register to comment.