After a long time trying to figure out why my encoder code that uses TimerOne wasnt working correctly on my Teensey 3.2 I've tracked it down to TimerOne not sampling at the correct duration. I've loaded the test program below and if I init Timer1 at less than about 10000 the LED is blinking so fast it appears solid, however anything above about 500000 (0.5 sec) it wont slow down to a blink rate slower than about 0.3 sec no matter what the init setting.
Varying the Teensey CPU in the IDE Teensey option has an affect, but I still cant slow it down.
I've tried two different boards, both behave the same - could it be I've accidentally changed a compile setting (CPU Speed/Optimise) in the IDE ? I cant find any info on what these should be by default.
I've tried TimerThree library, same thing.
Any ideas folks? It has me completely stumped.
I think I'm using the correct value in initialise 1000000 is 1 second right?
#include "TimerOne.h"
const int LedPin=13;
void setup()
{
Timer1.initialize(1000000); // initialize timer1, and set a 1 second period
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
pinMode(LedPin, OUTPUT);
digitalWrite(LedPin,HIGH);
}
void callback()
{
digitalWrite(LedPin,!digitalRead(LedPin)); //Heartbeat flash
}
void loop()
{
}