using variables with floatmath ?
lfreeze
Posts: 174
·
Please help, I think the problem described below has exceeded my small skills with the propeller.
·
I am trying to scale the output of an ADC0831 to display 0.0· to 5.0 volts depending on its Output of· from 0 to 255. I am dividing 5 by 255 and using the result of 0.0195 as
A multiplier to determine the voltage
·
Example:··· ADC puts out a value of 127, to convert this to a voltage, I multiply
················ ,0195 by 127 which equals a voltage of· 2.47
·
After spending a lot of time and trying most of the math objects ·to program this, I discovered that you cannot use interger variables in the float math formula. You must use· values that contain a decimal Point and one integer.
·
Example:· you cannot use 127, you must use 127.0 ·
·
Is there an object or formula to convert integer variables to variables containing
A decimal point and the option to add a 0 after the decimal?· Or am I not seeing the forest
for the trees and there is a simple solution I have overlooked?
·
Example:
·
Convert·· the variable 127 to 127.0··
·
The program below is what I have been working on. If you run it, it will not display the
Correct result. If you change the firstnumber variable to 127.0 it will work correctly
·
Many thanks for any solutions, or suggestions..
·
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· adcmultiplier =0.0196
···
OBJ
· ser···· : "fullduplexserial"
· f······ : "FloatMath"
· fp····· : "FloatString"
···
VAR
· long firstnumber, secondnumber
·
PUB start
· ser.start(31, 30, 0, 9600)····
·
· firstnumber :=127· 'value from ADC0831 (0 to 255)
·
·· repeat
·························
····· secondnumber:=f.fmul(firstnumber, adcmultiplier)· '· multiplies two decimal numbers···
····· secondnumber:=(fp.FloatToString(secondnumber)) 'converts float number to string·····
····· ser.str(string("· secondnumber·· float to string result = "))·
····· ser.str(secondnumber)··· 'display converted float to string value
·
····· ser.tx(13)'carriage return
····· waitcnt (40_000_000 + cnt)
Please help, I think the problem described below has exceeded my small skills with the propeller.
·
I am trying to scale the output of an ADC0831 to display 0.0· to 5.0 volts depending on its Output of· from 0 to 255. I am dividing 5 by 255 and using the result of 0.0195 as
A multiplier to determine the voltage
·
Example:··· ADC puts out a value of 127, to convert this to a voltage, I multiply
················ ,0195 by 127 which equals a voltage of· 2.47
·
After spending a lot of time and trying most of the math objects ·to program this, I discovered that you cannot use interger variables in the float math formula. You must use· values that contain a decimal Point and one integer.
·
Example:· you cannot use 127, you must use 127.0 ·
·
Is there an object or formula to convert integer variables to variables containing
A decimal point and the option to add a 0 after the decimal?· Or am I not seeing the forest
for the trees and there is a simple solution I have overlooked?
·
Example:
·
Convert·· the variable 127 to 127.0··
·
The program below is what I have been working on. If you run it, it will not display the
Correct result. If you change the firstnumber variable to 127.0 it will work correctly
·
Many thanks for any solutions, or suggestions..
·
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· adcmultiplier =0.0196
···
OBJ
· ser···· : "fullduplexserial"
· f······ : "FloatMath"
· fp····· : "FloatString"
···
VAR
· long firstnumber, secondnumber
·
PUB start
· ser.start(31, 30, 0, 9600)····
·
· firstnumber :=127· 'value from ADC0831 (0 to 255)
·
·· repeat
·························
····· secondnumber:=f.fmul(firstnumber, adcmultiplier)· '· multiplies two decimal numbers···
····· secondnumber:=(fp.FloatToString(secondnumber)) 'converts float number to string·····
····· ser.str(string("· secondnumber·· float to string result = "))·
····· ser.str(secondnumber)··· 'display converted float to string value
·
····· ser.tx(13)'carriage return
····· waitcnt (40_000_000 + cnt)
Comments
so just wrap your integer in fp.FFloat()
firstnumber :=(f.ffloat(firstnumber)) the program works properly.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
adcmultiplier =0.0196
OBJ
ser : "fullduplexserial"
f : "FloatMath"
fp : "FloatString"
VAR
long firstnumber, secondnumber
PUB start
ser.start(31, 30, 0, 9600)
firstnumber :=115 'value from ADC0831 (0 to 255)
firstnumber :=(f.ffloat(firstnumber))
repeat
secondnumber:=f.fmul(firstnumber, adcmultiplier) ' multiplies two decimal numbers
secondnumber:=(fp.FloatToString(secondnumber)) 'converts float number to string
ser.str(string(" secondnumber float to string result = "))
ser.str(secondnumber) 'display converted float to string value
ser.tx(13)'carriage return
waitcnt (40_000_000 + cnt). O