Shop OBEX P1 Docs P2 Docs Learn Events
newbie wants help with integer division — Parallax Forums

newbie wants help with integer division

harry_sharry_s Posts: 7
edited 2007-08-01 07:58 in BASIC Stamp
Hi all

I am trying to experiment with PID...I am using an analog input of temperature spaning from 0 to 50C and I am using an ADO0831 with input span 0-5VOLTS.

I am calculating the temperature by

t= tempSpan * adcBits/255

I wanted to use the trick with the tenths of temperature that the stamp in class- industrial control uses but I get wrong results since I fail the result of the mutiplication is bigger than 64k...

how do I resolve this problem?

Can you please also recommend some source of information & tricks on how to do floating point calculations on basic stamp?

Thank you

Comments

  • BeanBean Posts: 8,129
    edited 2007-07-31 13:37
    I think the problem is that your input cannot be to the tenth of a degree (that would require an input value from 0 to 500).
    But you could get the temperature in 0.2 degree increments.

    Make tempSpan = 250 ' 50 / 0.2

    t = (tempSpan * adcBits) / 255

    tWhole = t / 5
    tFrac = t // 5

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-31 13:44
    If you're interested, there's a discussion of multiple precision arithmetic with the Stamp including examples here under math: www.emesystems.com
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-31 17:24
    Harry,

    You can probably use the */ operator. On your calculator find, multiiplier = tempSpan * 10. Then use,

    t = multiplier */ ADCbits

    That will not have the overflow limiitation and the result will come out directly in tenths.

    Edited: I had included a divide by 256 in the calculation of the multiplier. That is implied in the */ operator.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 7/31/2007 9:18:16 PM GMT
  • harry_sharry_s Posts: 7
    edited 2007-08-01 07:58
    Thank you all for your answers !!!
Sign In or Register to comment.