Folks,
I've using TeensyTimerTool and it is showing odd behavior. If I put a scope on the LED_PIN, in the code shown below, if I use loop(), it works fine. I get a very nice 8ms change in the LED_PIN. But in that version of loop() then I'm changing the volatile from the ISR which I thought was a no-no.
If I change the second function loop1(), to loop() (and remove the original loop, then there is no pause, and the LED_PIN changes as rapidly as loop can er, loop.
where am i going wrong?
owen
I've using TeensyTimerTool and it is showing odd behavior. If I put a scope on the LED_PIN, in the code shown below, if I use loop(), it works fine. I get a very nice 8ms change in the LED_PIN. But in that version of loop() then I'm changing the volatile from the ISR which I thought was a no-no.
If I change the second function loop1(), to loop() (and remove the original loop, then there is no pause, and the LED_PIN changes as rapidly as loop can er, loop.
where am i going wrong?
owen
Code:
#include "TeensyTimerTool.h"
#define LED_PIN 13
using namespace TeensyTimerTool;
Timer timer1(TMR1);
Timer timer2(GPT1); // First channel on TMR1 aka QUAD timer module. (TMR1 - TMR4, four 16bit channels each)
// loop stuff
volatile boolean _pause = false;
boolean pause = false;
// LED
boolean blinkOn = false;
void setup() {
pinMode(LED_PIN, OUTPUT);
timer1.beginPeriodic(tickLoop, 1);
timer2.beginPeriodic(foo, 8000);
pause = false;
_pause = false;
}
// this makes a nice 8 ms square wave
void loop() {
noInterrupts();
pause = _pause;
interrupts();
while(_pause) {}
_pause = true;
digitalWrite(LED_PIN, blinkOn);
blinkOn = !blinkOn;
}
// this makes dogmeat
void loop1() {
noInterrupts();
pause = _pause;
interrupts();
while(pause) {}
pause = true;
digitalWrite(LED_PIN, blinkOn);
blinkOn = !blinkOn;
}
void foo() {
_pause = false;
}
void tickLoop() {
// does lost of other things
}