chipKIT® Development Platform

Inspired by Arduino™

Strange floating point crashes

Created Mon, 29 Oct 2012 09:42:55 +0000 by mikem


mikem

Mon, 29 Oct 2012 09:42:55 +0000

Hi, Im seeing non-deterministic crashing during floating point divides with Uno32 and mpide-0023-linux32-20121013-test and mpide-0023-linux-20120903 on both OpenSuSE 12.1 and Ubuntu 12.04.

Testing code that runs fine on AVR Uno, I observed the sketch crashes after running for about 5 seconds (during which time the offending line will have been called without crashing 10 to 15 times), and then restarts from the setup(), runs for 5 secs or so......

The line that crashes is:

long stepsToStop = (long)((_speed * _speed) / (2.0 * _acceleration)); // Equation 16

(had to use SPI to find that!) and if I break it down into steps it crashes in the divide:

float s = sq(_speed);
float a = 2.0 * _acceleration;
s = s / a; // CRASHES sometimes here
long stepsToStop = (long)s;

The divide line assembly is simple:

120:/home/mikem/mpide/libraries/AccelStepper/AccelStepper.cpp **** s = s / a; // CRASHES sometimes here 1159 .loc 1 120 0 1160 017c 21284000 move $5,$2 1161 0180 0000000C jal __divsf3 1162 0184 21202002 move $4,$17

so no clues there.

Other observations. The crash does not depend on the values passed to the divide, but in some strange way on the number of times its called, and some other non-deterministic influence. Clock? Some other interrupt? The denominator is NEVER 0 If I put a Serial.println() before the crash line, it crashes after a larger number of iterations If I put a Serial.println() after the crash line it does not affect the crash frequency Putting noInterrupts()/interrupts() around the divide does not change behaviour (should that work anyway?) It is non deterministic: it will crash usually about the 10th time it is called, sometimes the 15th or so, but sometimes not at all. Sometime it will crash 5 secs in on the first run after uploading, but the second run (without a new upload) will succeed! The code its in does not use malloc, pointers or interrupts or timers

So its timing critical, its a hard crash, in code that works on AVR.

Ideas?


EmbeddedMan

Mon, 29 Oct 2012 11:56:01 +0000

Maybe stack related? What if you create a large static variable that uses up most of RAM - does the crash happen faster?

Hopefully Jason K will see this - it's right up his alley.

He will want to have access to the source and ELF file that results from the build so he can debug.

*Brian


mikem

Tue, 30 Oct 2012 09:53:36 +0000

More info:

same behaviour with mpide-0032-windows-20121013-test on Windows XP.

You can replicate this by getting AccelStepper 1.23 from http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.23.zip, compile the example Bounce sketch. On UNo32 the sketch crashes and restarts as described after running for about 5 seconds.

Using the same MPIDE environment but building for AVR Uno, the resulting sketch runs fine, as it also does when building with standard Arduino environment.


mikem

Tue, 30 Oct 2012 10:07:32 +0000

Hmmm, now Im chastened.

Turns out this problem appears to be due to power consumption/drain on the digital output pins. I was testing with a small stepper directly connected to D2-D5/GND, as I do with Arduinos. With the stepper connected to Uno32 it crashes inside the divide function. With no stepper connected it works fine.

Seems wierd to me. But dont take any further actions on this issue.

Cheers.