newbie wants help with integer division
harry_s
Posts: 7
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
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
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
·
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