Crash in timer interupt when data type "float" is used
Posted: Sun Feb 26, 2017 8:58 am
I'm seeing a weird crash here when I try to use "float" in a timer ISR.
Example:
This sketch will crash and generate the following output:
The weird part is, if I comment out this line:
// timer0_float = timer0_int;
then the sketch will run without problems, despite a double precision variable being accessed
So "float" will crash, but "double" is OK to use?
Cheers
Hans
P.S: I'd rather be using floats, they're quite a bit faster than double.
Example:
Code: Select all
hw_timer_t *timer0;
uint32_t timer0_int = 0;
float timer0_float = 0.0;
double timer0_double = 0.0;
void IRAM_ATTR timer0_intr() // Interrupt handler for timer 0
{
timer0_int++;
timer0_float = timer0_int;
timer0_double = timer0_int;
}
void setup() {
timer0 = timerBegin(0, 80, true); // divider 80 = 1MHz
timerAlarmWrite(timer0, 999, true); // Alarm every 1000 µs, auto-reload
timerAttachInterrupt(timer0, timer0_intr, true); // attach timer0_inter, edge type interrupt
timerAlarmEnable(timer0);
Serial.begin(115200);
}
void loop() {
Serial.println(timer0_int);
delay(100);
}
Code: Select all
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0008,len:8
load:0x3fff0010,len:1760
load:0x40078000,len:6668
load:0x40080000,len:252
entry 0x40080034
0
Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception)
Debug exception reason: BREAK instr
Register dump:
PC : 0x40080930 PS : 0x00060036 A0 : 0x800809c8 A1 : 0x3ffc1100
A2 : 0x00000000 A3 : 0x00000001 A4 : 0x20000000 A5 : 0x00000000
A6 : 0x00000400 A7 : 0x00060823 A8 : 0x3ffc2504 A9 : 0x3ffc80f0
A10 : 0x00000001 A11 : 0x00060023 A12 : 0x80082a29 A13 : 0x3ffc81b0
A14 : 0x00000003 A15 : 0x00000000 SAR : 0x00000018 EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x40080930:0x3ffc1100 0x400809c8:0x3ffc11e0 0x40081651:0x3ffc1200
CPU halted.
// timer0_float = timer0_int;
then the sketch will run without problems, despite a double precision variable being accessed
So "float" will crash, but "double" is OK to use?
Cheers
Hans
P.S: I'd rather be using floats, they're quite a bit faster than double.