PDA

View Full Version : floating point math


proto pro
01-04-03, 02:20 PM
Hello all!
I'm a newbe, so please forgive my ignorince.
I am trying to use the isopod to read the x-y voltages (2v-3v) of a joystick,
convert these cartisian values to polar and output as PWM.
Being new to both FORTH and IsoMax I am having much dificulty understanding
the documentation, mainly how to use FATAN. Can someone give an explanation
of how a value read from the ADC is used with FATAN? I have tried D>F but I get
a "stack empty" measage. I am hoping more detailed documentation will be
released soon!
Thank you,
Dave

RMDumse
01-04-03, 03:15 PM
The reading you get from the A/D will be a single cell, or a16-bit value. FATAN works on Floats on the Float stack. Therefore you take the value from the data stack, and move it to the floating point stack by using S>F (single to float). Once on the floating point stack, you can perform all the floating point operations on it you want. If you want to then return it to the interger stack (retaining only the integer part mind you), you can bring it back with F>D to get a double, and if you don't want the value to be a single again, get rid of the upper half of the precision (the double part) by just dropping that half with the word DROP.

D>F takes a double off the data stack and moves it to the floating point stack. If you do that, and only provide a single, you'll probably get the "stack empty" message for trying to take two things from where you've only put one.

proto pro
01-21-03, 12:37 PM
Thanks for the help! I am understanding this FORTH enough to make a stab at it. I read in the book Starting Forth by Leo Brodie, that integer math is much faster than floating point math, so I wrote my Cartisian to Polar conversian program both ways and compaired the looping time by monitoring, with an O-scope, a pulse sent to PB7. I don't see any diference in time it takes to loop through ether calculation! I have reduced the cycles insruction to 50 so I'm shure this is not the cause, in fact, I have found, if I set the cycles instruction too low, say 5, it will loop even slower.
My question is: If I just want to DSP; read an analog, do some arithmetic function on it and output it as a pwm, and repeat as many times per second as posible, hopefully around 400 Hz, Is it best to use IsoMax or MaxForth?

RMDumse
01-21-03, 01:59 PM
Either way is fine.

A IsoPod(TM) user reported he was doing over 35000 floating point operation a second. You should be fine at your 400 Hz. If you want periodicity, then IsoMax will keep a regular "beat" at 400 Hz (for instance). If you want to just use Forth, and put in a loop, it will run as fast as it can. That's fine if you only have that one thing to do. It's when you need VPMA (Virtually Parallel Machine Architecture) concepts to help you seemlessly multitaks, that IsoMax(TM) shines.