Float Math Errors?? Large, random numbers...
bjohnson23
Posts: 6
in Propeller 1
Hello,
Please forgive me if I miss any vital information, I'm still a bit new to this.
I am using the P8X32A-Q44 Microcontroller to read an inclinometer and an encoder and then spit the incoming values from both
of those to a terminal very quickly. I'm using the "F32_1_6" float math object and the "FloatString" object from the OBEX for all computations and conversion to string for displaying.
My problem is that about 1 in every 1000 readings that I get in is suddenly a huge number (always the same number), something like 6E27...
I thought maybe my fmath object was getting overloaded somehow because I'm having it loop through all the computations as fast as it can go, so I added a second fmath object running on another cog and am sending half of all the computations being done to that cog instead. This didn't seem to help, it may have lowered the number of anomalies but it's difficult to tell as it is random.
Does anyone know what is causing these sudden values? For what I'm trying to do, I need a constant stream of values coming in and they all reference that preceding value so it is very important that I do not have these anomalies in my data.
I am writing in Spin.
Thank you very much for your help,
if you need any other info just let me know
Please forgive me if I miss any vital information, I'm still a bit new to this.
I am using the P8X32A-Q44 Microcontroller to read an inclinometer and an encoder and then spit the incoming values from both
of those to a terminal very quickly. I'm using the "F32_1_6" float math object and the "FloatString" object from the OBEX for all computations and conversion to string for displaying.
My problem is that about 1 in every 1000 readings that I get in is suddenly a huge number (always the same number), something like 6E27...
I thought maybe my fmath object was getting overloaded somehow because I'm having it loop through all the computations as fast as it can go, so I added a second fmath object running on another cog and am sending half of all the computations being done to that cog instead. This didn't seem to help, it may have lowered the number of anomalies but it's difficult to tell as it is random.
Does anyone know what is causing these sudden values? For what I'm trying to do, I need a constant stream of values coming in and they all reference that preceding value so it is very important that I do not have these anomalies in my data.
I am writing in Spin.
Thank you very much for your help,
if you need any other info just let me know
Comments
Have you tried printing out intermediate values to figure out where the numbers start being wrong?
Are you dividing by zero anywhere?
What is the exact huge number you're getting? FloatString can't detect NaN, and just prints out some huge number when it gets a NaN.
The exact value I'm getting is 5.69E+17.
Okay, I will use just one cog for all the math. I didn't realize it did that.
I am calling the F32 object every time I reach a certain pulse count from my encoder as it is spinning and it spins pretty fast, so I was thinking maybe I was trying to call it when it was still in the middle of the last computation. But even when I slow the encoder down or make it send less often the value will still sometimes show up. It occurs very randomly/rarely though which is strange... I tried swapping out the microcontroller too because I had no clue what could be causing it but that didn't help either.
And yes I have tried printing all intermediate values and it doesn't always happen at the same spot. It seems to occur randomly during any one of my float calculations.
If that doesn't fix it, can you give me that 5.69e17 number in hexadecimal? Don't f.ftrunc it - just pretend it's an integer, and print it out in hex. Also, I don't have a Propeller with me now to test this, but what do you get if you print out the result of "f.fdiv(1.0, 0.0)" as both a float and a hex number?
-Phil
Yes the error was that I was accessing the F32 from multiple cogs and it was sometimes causing an error when they overlapped.
I created a second F32 for my second cog and it works perfectly!
Thank you very much, you have been very helpful in solving this issue
The locks prevent issues like those you encountered without the need for a second instance of the object.