Hello,
Recently, I have been playing around with timer interrupts.
I made a simple modification to the "LED blink" sketch listed at:
http://leaflabs.com/docs/maple/timers/
I added a single SerialUSB.println() statement.
The code compiles and uploads successfully to RAM (based on getting a complete message after the upload finishes), but the Maple seems to hang the first time handler_led() is called. I have not tried uploading to FLASH.
What functions can be called within handler_led()? I know that analogRead() calls work (ie, do not crash the board), but I have not been able to see the value returned by my call to analogRead().
I am using a Maple Rev 3 board, Maple IDE 0.6.0, Windows XP Pro SP3, Java 1.6.0 update 20 ("version 6"; yes, I know that update 21 is available), on a 1 GHz Pentium III (512 meg RAM).
Thanks!
Stephen from NYC
P.S. Here is the first time I am trying to enter code:
Here is the original UNmodified code:
#define LED_PIN 13
#define LED_RATE 500000 // in microseconds; should give 0.5Hz togglesvoid handler_led(void);
int toggle = 0;void setup()
{
// Set up the LED to blink
pinMode(LED_PIN, OUTPUT);// Setup Timer
Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer2.setPeriod(LED_RATE); // in microseconds
Timer2.setCompare1(1); // overflow might be small
Timer2.attachCompare1Interrupt(handler_led);
}void loop() {
// Nothing! It's all in the interrupts
}void handler_led(void) {
toggle ^= 1;
digitalWrite(LED_PIN, toggle);
}
Here is the modified code:
#define LED_PIN 13
#define LED_RATE 500000 // in microseconds; should give 0.5Hz togglesvoid handler_led(void);
int toggle = 0;void setup()
{
// Set up the LED to blink
pinMode(LED_PIN, OUTPUT);// Setup Timer
Timer2.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer2.setPeriod(LED_RATE); // in microseconds
Timer2.setCompare1(1); // overflow might be small
Timer2.attachCompare1Interrupt(handler_led);
}void loop() {
// Nothing! It's all in the interrupts
}void handler_led(void) {
toggle ^= 1;
digitalWrite(LED_PIN, toggle);// this is the only line added to the sketch
SerialUSB.println("Hello at 0.5 Hz");
}