Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 4 months ago.
Why does the LPC1768 sleep() function prolong timer interrupts?
I have the following program, that just blinks an LED on the application board every 2ms using a busy-loop:
#include "mbed.h" #include "LPC17xx.h" #define TICK_TIME_US (2000) static volatile bool tick_lapsed = false; void handle_timer() { tick_lapsed = true; } int main() { DigitalOut led(p23); Ticker ticker; ticker.attach_us(handle_timer, TICK_TIME_US); do { tick_lapsed = false; while(!tick_lapsed); led = !led; } while(true); return 0; }
I've checked with a logic analyser, and the pulse width is indeed 2ms (4ms total period).
But if I change the busy loop to a sleep call:
do { tick_lapsed = false; while(!tick_lapsed) { sleep(); } led = !led; } while(true);
...then the pulse width blows out to 10ms!
I was under the impression that timers should still run during the LPC's sleep mode. How can I configure them to interrupt every 2ms? Even configuring TIMER0 using the registers manually results in nothing below 10ms.