Hi all, I am working on some timer stuff to eventually implement a multi-axis stepper driver. I'm noticing that during the first few seconds of operation I get some weird timer artifacts.
Here is a screenshot showing the behavior: http://dl.dropbox.com/u/19742583/Screen%20shot%202011-05-29%20at%2012.41.46%20PM.png
And here is the sketch that is running:
HardwareTimer timer1(1);
// GPIOA_BASE->ODR |= BIT(3)
void setup() {
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
timer1.pause();
timer1.setPrescaleFactor(72);
timer1.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer1.setCompare(TIMER_CH1, 1);
timer1.setOverflow(0xffff);
timer1.attachCompare1Interrupt(handler1);
timer1.refresh();
// adding a delay(2000) here causes the weirdness to never happen
timer1.resume();
}
void handler1() {
if (digitalRead(0) == LOW) {
digitalWrite(0, HIGH);
timer1.setCompare(TIMER_CH1, timer1.getCompare(TIMER_CH1) + 10);
}
else {
digitalWrite(0, LOW);
timer1.setCompare(TIMER_CH1, timer1.getCompare(TIMER_CH1) + 60);
}
}
void loop() {
}
What I am seeing is that about a .25 seconds after startup I seem to miss the interrupt that turns off the output, so the timer does a full cycle (65ms) and then it happens again about 1 second in. After this it is fine and remains stable. If I add a 2000 ms delay before I resume the timer (starting it) this never happens.
My guess is that the Maple library is setting something up during the first second of operation, but I have not confirmed that.
Does anyone have any ideas as to what might be going on?
Thanks,
Jason von Nieda