Math/Floating point math HELP
marzec309
Posts: 146
OK. The PROP is still fairly new to me and I'm trying to get it to solve some sin equations using the Float32Full Object. I just cant seem to make any sense of it. I think I'm overflowing. Here's what I'm attempting to do.
Find the sin of a degree 1 to 90, then Multiply the result by the peak volts. This will run on a cog by itself to produce a Sine Wave.
Simplified code:
Vp := 2047
Repeat
repeat index from 1 to 90
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := v + 2047
repeat index from 89 to 0
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := v + 2047
repeat index from 1 to 90
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := 2047 - v
repeat index from 89 to 0
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := 2047 - v
Is there a better way to do this, Or is there a way to limit the resolution to prevent an overflow. I know assembly would be better at this but I have never used it.
So far I've got it doing Half of what i want. I Hard coded every value from 0 to 360 degrees with a simple waitcnt command between each line of code, to control the frequency but i would like to be able to calculate those values at run time so i can have the prop regulate the Vp value.
Find the sin of a degree 1 to 90, then Multiply the result by the peak volts. This will run on a cog by itself to produce a Sine Wave.
Simplified code:
Vp := 2047
Repeat
repeat index from 1 to 90
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := v + 2047
repeat index from 89 to 0
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := v + 2047
repeat index from 1 to 90
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := 2047 - v
repeat index from 89 to 0
SIN := math.sin(Index)
v := math.FMul(Vp,SIN)
Vout := 2047 - v
Is there a better way to do this, Or is there a way to limit the resolution to prevent an overflow. I know assembly would be better at this but I have never used it.
So far I've got it doing Half of what i want. I Hard coded every value from 0 to 360 degrees with a simple waitcnt command between each line of code, to control the frequency but i would like to be able to calculate those values at run time so i can have the prop regulate the Vp value.
Comments
Note that adding a decimal point (".0") makes constants into floating point.
Post Edited (Mike Green) : 8/13/2009 3:52:47 PM GMT
My Goal is to create a 12VAC source, that i can step up to 120VAC with a transformer. By monitoring the High voltage side of the transformer, the prop will adjust the amplitude of the low voltage AC. Thus giving me a regulated 120VAC True Sine Wave inverter. I don't think I will be able to push much current as the dc current will be roughly 10 times the ac load. But should do the trick. will post more info as it progresses or if i run into another problem, I'm sure i will.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
MOORE'S LAW: The capabilities of electronics shall double every 18 months.
cloyd's corollary: Hardware is easy, software is hard.
John Abshier