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:
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!
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: