I have a project where I am using an IntervalTimer to do high accuracy square wave signal generation. It's a Teensy 3.6 but I'd like it to work on Teensy LC as well.
It works great, but I am wondering if it is possible to change the interval after the IntervalTimer.begin() function has been called. I expect this to be rare.
I looked through the library and don't see something like a UpdateInterval() function. My read is that I'm passing the microsecond interval as a float for improved resolution, which calls beginCycles, which sets some hardware registers.
I see that "channel->LDVAL = cycles" is probably where the actually setting of the timer register happens, but I'm not sure where the channel object is defined.
This was my attempt to take the relevant portion of the library and manually do it inside my function.
Any simple way to do this? I can tolerate a glitch when changing the timer comparator.
It works great, but I am wondering if it is possible to change the interval after the IntervalTimer.begin() function has been called. I expect this to be rare.
I looked through the library and don't see something like a UpdateInterval() function. My read is that I'm passing the microsecond interval as a float for improved resolution, which calls beginCycles, which sets some hardware registers.
I see that "channel->LDVAL = cycles" is probably where the actually setting of the timer register happens, but I'm not sure where the channel object is defined.
This was my attempt to take the relevant portion of the library and manually do it inside my function.
Code:
float NewInterval = 500000./StrobeFrequency;
if (NewInterval > 0 && NewInterval <= UINT32_MAX / (F_BUS / 1000000.0)) {
uint32_t cycles = (float)(F_BUS / 1000000) * NewInterval - 0.5;
if (cycles >= 36) {
channel->LDVAL = cycles;
}
else Serial.println("ERROR: Interval Cannot be Set.");
}
else Serial.println("ERROR: Interval Cannot be Set.");
Any simple way to do this? I can tolerate a glitch when changing the timer comparator.