IntervalTimer and FreqMeasure resource conflict (Teensy 3.2)?

Status
Not open for further replies.

stvcmhr

New member
I'm working on a motor speed controller using a Teensy 3.2. I'm using FreqMeasure to measure the motor rpm. Used in isolation, this works great. When I enable the IntervalTimer, FreqMeasure gives wrong / erratic results. I suspect that there is some resource conflict with timers?

I'm just using IntervalTimer to call a function after a fixed delay. I've tried the TimerOne and TimerThree libraries, but observe erratic behavior (also a resource conflict?).

Offending code, skinnied down to the essentials:



Code:
#define ZERO_CROSS 18
#define SCR_TRIGGER 23
#define TACHOMETER 3

IntervalTimer scrTimer ;

void zeroCrossTimerService() {
  digitalWrite(SCR_TRIGGER, LOW) ;            // turn off SCR's
  scrTimer.end() ;
}

void zeroCrossService() {
  digitalWrite(SCR_TRIGGER, HIGH) ;           // turn on SCR's
  scrTimer.begin(zeroCrossTimerService, controPulseDuration) ;     // 0 < controlPulseDuration <  8300usec
}

int main() {
  pinMode(ZERO_CROSS, INPUT) ;                     // zero crossing detector
  pinMode(SCR_TRIGGER, OUTPUT) ;                 // scr enable signal
  pinMode(TACHOMETER, INPUT_PULLUP) ;        // tachometer input

  attachInterrupt(ZERO_CROSS, zeroCrossService, RISING) ; // interrupt on each zero crossing

  FreqMeasure.begin() ;                                   // uses TACHOMETER pin to measure frequency

  while(1) {
    actualSpeed = measureSpeed() ;

    ...
    ...
    ...

    delay(100) ;
  }
}


BACKGROUND:

I'm using IntervalTimer to generate a variable width enable signal to a couple of SCR's which are part of a full wave bridge. For those who are interested, this is a controller board I've built for using salvaged treadmill motors in shop tools such as lathes, drill presses, etc.

Basically I generate a zero crossing signal which triggers an interrupt. The isr turns on the SCR control signal, and sets a timer (IntervalTimer) to generate an interrupt after 0 to ~8 milliseconds. The isr for IntervalTimer turns off the SCR control signal.

KUDOS:

The Teensy is an outstanding product, and the libraries and support are great. It has quickly become my go-to platform for embedded development.

Thanks Paul!
 
Last edited:
Unless your motor is going really fast you can just use an interrupt and elapsedMicros.

I'm getting pretty decent results with it on my Electric Gocart, got it to 27MPH yesterday. Slows down like a rolling brick but between me and the cart its almost 1000LBs.
 
FreqMeasure uses the FTM1 timer. IntervalTimer uses one of the 4 PIT timers, so at least for the timer resources there is no conflict.

TimerOne does use FTM1, so it definitely will conflict with FreqMeasure.

Even if the timers don't conflict, you could be running into interrupt blocking issues. Basically, the time certain interrupt code takes to run causes other interrupts to be delayed. In this case, it looks like you're using at least 3 interrupts, for the pin, the timer, and frequency measurement.

The first step is to minimize the time each interrupt function spends doing its work. Do this first!

The next step might involve editing the interrupt priorities. Teensy 3.x has nested priority interrupts, where a lower number means higher priority. If an interrupt is at priority 128 (the default), then other interrupts at 128 or higher are blocked, but interrupts with lower numbers (higher priority) are able to interrupt it. If shortening the interrupt run times isn't an option, sometimes projects like this can be made to work by carefully choosing the relative priority levels for each interrupt.
 
Status
Not open for further replies.
Back
Top