Help with phsa
Hi,
When I put this code into my program:
time := (phsa - 624) #> 0···············
a := time
the time variable will·display a number like 773 in hyper terminal.
However, when I display a, it will show a number such at 1e-42.
Can someone please explain to me why a does not read the same as time?
When I put this code into my program:
time := (phsa - 624) #> 0···············
a := time
the time variable will·display a number like 773 in hyper terminal.
However, when I display a, it will show a number such at 1e-42.
Can someone please explain to me why a does not read the same as time?

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
I need to put a filter on my thinking. Yep, I converted to string!
What are you using to convert to string?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
a is multiplying ok, but it appears to be the "b" that is not adding correctly.
Strange, here is the code:
long a
long b
long c
long time
dira[noparse][[/noparse]17] := outa[noparse][[/noparse]17] := 1
waitcnt(clkfreq/10_000 + cnt)
phsa~
dira[noparse][[/noparse]17]~
waitcnt(clkfreq + cnt)
time := (phsa - 624) #> 0
Debug.Str(String(13, "time = "))
debug.dec(time)
Debug.Str(String(" which correlates to "))
a := fMath.FMul(time, 1.5279)
b := fMath.FAdd(a, 36.1526)
debug.dec(b)
Debug.Str(String(" ohms"))
Debug.Str(String(13, "a = "))
Debug.dec(a)
Debug.Str(String(13, "b = "))
Debug.dec(b)
Debug.Str(String(13, "c = "))
Debug.dec(c)
Debug.Str(String(13, "Dec version of time = "))
Debug.dec(time)
Debug.Str(String(13, "Dec version of a = "))
Debug.dec(a)
waitcnt(clkfreq + cnt)
Post Edited (Andrew C) : 12/16/2009 12:11:08 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
In the floatstring object there is a function to convert a float to a string which would be useful when outputting to the terminal.
There is a float demo showing the use of floatstring that comes with the prop tool.
Cheers,
Graham
p.s. to make your code more readable surround it with code tags [noparse][[/noparse]code ] and [noparse][[/noparse]/code ]
(but remove the spaces between the square brackets)
Thank you! I'm learning more again. Here is the code I used to help understand:
'' File: 1Test.spin OBJ fM: "Float32" ' Use floating math routines p: "FullDuplexSerialPlus" ' Use with Parallax Serial Terminal fS: "FloatString" ' Use floating math to String routines CON _clkmode = xtal1 + pll16x ' System clock → 80 MHz _xinfreq = 5_000_000 VAR long num1 long num2 long x long y Pub Init p.Start(31, 30, 0, 9600) ' Initialize the serial terminal fM.start ' Initialize the floating point math in a cog waitcnt(clkfreq * 3 + cnt) ' Wait 3 seconds to press "Enable" on Serial Terminal main ' start the main program PUB main p.str(string(16)) ' Clear the terminal screen p.str(string("Begin output", 13)) num1 := clkfreq p.dec(num1) p.str(string(13)) ' CR/LF 'x := 1.1 'Begin output 'y := 2.2 '80000000 'num2 := x * y '-259040215 (because variables are fp) 'p.dec(num2) 'End output 'x := fM.ffloat(1.1) 'Begin output 'y := fM.ffloat(2.2) '80000000 'num2 := fM.FMul(x, y) '1568564747 (because answer is in fp) 'p.dec(num2) 'End output 'x := 1.1 'Begin output 'y := 2.2 '80000000 'num2 := fM.FMul(x, y) '1568564747 (because answer is in fp) 'p.dec(num2) 'End output x := 1.1 'Begin output y := 2.2 '80000000 num2 := fM.FMul(x, y) '2.42 (correct) p.str(fS.FloatToString(num2)) 'End output (needs to convert answer to fp) p.str(string(13)) x := 2 y := 3 num2 := x * y p.dec(num2) 'displays "6" correct (because answer is integer) p.str(string(13)) 'x := 1.1 'Begin output 'y := 2.2 '80000000 'num2 := fM.FMul(num1, 1.0) '2.42 (correct) 'p.str(fS.FloatToString(num2)) '6 (correct) '4.624469e-36 (because num1 is integer) x := 1.1 'Begin output y := 2.2 '80000000 num2 := fM.FMul(fM.FFloat(num1), 2.0) '2.42 (correct) p.str(fS.FloatToString(num2)) '6 (correct) '160000000 (correct - converted num1 to float before multiplying) p.str(string(13,"End output"))Post Edited (Andrew C) : 12/16/2009 2:49:19 AM GMT