Teensy LC interval timer limitations?

Status
Not open for further replies.

zachtos

Well-known member
Hello, I am having trouble with interval timers in Teensy LC. Code works great in Teensy 3.1, but in LC, I have two interval timers running at same time. They seem to have issues with volatile booleans sometimes not getting flagged inside the interrupts. Other timers I have are analogWriteFrequency() and analogWriteResolution(10)

Are there any known issues, limitations or conflicts with this hardware set?

Timer1 and Timer3 are something I could do but will not work with my current pin configurations on prototype.

I will see if I can make a shorter version of the bug to send, but it's a very big codeset, and is odd that it works fine on 3.1 teensy, making me think otherwise.
 
Teensy LC has two PIT timers (the type of timer used by IntervalTimer). Teensy 3.x has 4 of them.

The interrupt vector works differently too, but IntervalTimer is supposed to take care of those details.

There may be a subtle bug inside IntervalTimer, but of course I can't investigate without code that reproduces the problem.
 
Well, I think I have determined that there is something fishy with multiple interval timers operating on Teensy LC at the same time. I think the timings are not correct or some kind of odd bug. When I consolidate to just one interval timer (non ideal, but works), then the problems are gone. I guess I'll leave this thread in case someone else runs into issue. If I can find time to look into it more I will post sample bug code.
 
Please understand this does not go onto my list of stuff to investigate until code to reproduce the problem is posted.
 
Hi,
I think I ran into a similar issue with IntervalTimer on Teensy LC and to some extent 3.2 too.

The setup is very basic : a led on pin0 and ground, another led on pin1 and ground, and some wires to put pin11 and/or pin12 to ground by hand at will.
Each led is blinked by two independent timers. Bringing pin12 to ground stops led1's timer, bringing pin11 to ground restarts led1's timer.

The sketch I used is attached.
I'm running Arduino 1.6.11 with teensyduino 1.30.

Comment out line 53,
Code:
t0.begin(f0, 500); //if commented out, led on pin 0 stops blinking as well
then run the sketch :

- pin 0 is blinking a led, driven by IntervalTimer t0
- pin 1 is blinking another led, driven by IntervalTimer t1
>> observed and expected behaviour : *both* leds are blinking

- when pin 12 goes LOW, t1 is ended
*** With Teensy LC :
>> observed behaviour : *both* leds stops blinking
>> expected behaviour : only led on pin1 stops blinking
With Teensy 3.2, observed and expected behaviours are the same.

To overcome this issue with Teensy LC, timer 0 is restarted, even if nothing explicitly stopped it --> Uncomment line 53, compile, re-run.
This time, taking pin 12 to LOW will stop led 1, but led 0 will keep blinking.

- when pin 11 goes LOW, t1 is restarted, i.e. t1.begin(f1, 500)
On both LC and 3.2 :
>> observed behaviour : led on pin 1 does no blink.
>> expected behaviour : led on pin1 goes blinking again.

Am I missing something ?
Or is there something wrong with IntervalTimers ?

Regard,
David
 

Attachments

  • sketch_nov14a.ino
    1.1 KB · Views: 121
Unless I hear anything else, I'm going to consider this problem fixed.

If you use the new code and still have a problem, please understand I need to hear from you if you want to me to do anything more.
 
Another LC/IntervalTimer bug

Hi Paul,

I hope it's not bad form to post a new LC/IntervalTimer bug in this thread.

This does not produce a square wave on pin 4:

Code:
IntervalTimer timer;

void isr( void ) {
  digitalWrite( 4, !digitalRead( 4 ) );  
  timer.begin( isr, 1 );
}

void setup() {
  pinMode( 4, OUTPUT );
  timer.begin( isr, 1 );
}
void loop() {
}

But when I change the
Code:
timer.begin( isr, 1 );
in setup() to
Code:
timer.begin( isr, 2 );
it works fine.

This is Arduino 1.6.9 & Teensyduino 1.38-beta2.
It works fine on a Teensy 3.1.
 
IntervalTimer has a built-in minimum period of 36 F_BUS clocks. On Teensy LC F_BUS is only 24 MHz, which means it will not allow a period less than 1.5 us. On Teensy 3.x, F_BUS is faster unless you run at the very low speeds. That's why you can configure 1 us on Teensy 3.1.

If you want to try overriding this limit, find this line in IntervalTimer.h:

Code:
                if (cycles < 36) return false;
 
Status
Not open for further replies.
Back
Top