Teensey and TimerOne Problem

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()
{

}

The default values are the first option in each menu. Those are what will be selected on a fresh installation of the Arduino IDE and Teensyduino.

Thanks,

That what I have, so I guess its something else.... :confused:

Does the function need to clear the interrupt flag?

Good point, thanks for the reply.
The example doesn't and I think (based on the comment below from the Teensey website) that you only need it if reading a variable which an interrupt code writes.

I've tried both with and without turning interrupts off and then back on (as below) with the same result. It seems to be a problem with Timer1 as [GitHub - JChristensen/Timer: A fork of Simon Monk's Arduino Timer library]Simon Monks Timer Library](GitHub - JChristensen/Timer: A fork of Simon Monk's Arduino Timer library) works OK

 noInterrupts();
//Code which accesses a varaible written by an interupt 
 interrupts();

// to read a variable which an interrupt code writes, we
// must temporarily disable interrupts, to be sure it will
// not change while we are reading. To minimize the time
// with interrupts off, just quickly make a copy, and then
// use the copy while allowing the interrupt to keep working.