Hi everyone,
I have a Teensy 3.5 using FTM1 (like in this thread https://forum.pjrc.com/threads/45413-ISR-latency-Teensy-3-1-and-3-6?p=148851&viewfull=1#post148851) to count the pulses of a 10 MHz TCXO, which seems to work OK (without interval, juste count the pulse until a decided number and then reset the counter) !
However, I went a bit deeper int the FreqCount library and I think it would possible to modify to get the same result : my try is below but it doesn't seem to count perfectly (as it should increment 1 every second and I have a drift over a quite short period of time)
--> Modified FreqCount.ccp
I therefore have to questions :
1. What is the advantage of using FTM1 over LPTMR in order to count pulses ?
2. Is there a better (right?) way to modify the Freqcount library to get the expected result (just a counter that reset itself after a decided amount of pulses and triggering an action)?
Thanks for your help !
I have a Teensy 3.5 using FTM1 (like in this thread https://forum.pjrc.com/threads/45413-ISR-latency-Teensy-3-1-and-3-6?p=148851&viewfull=1#post148851) to count the pulses of a 10 MHz TCXO, which seems to work OK (without interval, juste count the pulse until a decided number and then reset the counter) !
However, I went a bit deeper int the FreqCount library and I think it would possible to modify to get the same result : my try is below but it doesn't seem to count perfectly (as it should increment 1 every second and I have a drift over a quite short period of time)
--> Modified FreqCount.ccp
Code:
uint32_t FreqCountClass::read(void)
{
uint32_t count;
uint8_t status;
status = SREG;
cli();
//count = count_output;
count = counter;
count_ready = 0;
SREG = status;
return count;
}
void FreqCountClass::end(void)
{
timer_shutdown();
counter_shutdown();
}
ISR(TIMER_ISR_VECTOR)
{
uint16_t count_lsw;
uint32_t count;
uint16_t index, length;
count_lsw = counter_read();
if (counter_overflow()) {
counter_overflow_reset();
count_msw++;
if ((count_msw << 16) >= 9999999)
{
count_msw=0;
counter++;
count_ready = 1;
}
}
/*index = gate_index + 1;
length = gate_length;
if (index >= length) {
gate_index = 0;
count = ((uint32_t)count_msw << 16) + count_lsw;
count_output = count - count_prev;
count_prev = count;
count_ready = 1;
restore_other_interrupts();
} else {
if (index == length - 1) disable_other_interrupts();
gate_index = index;
}*/
}
I therefore have to questions :
1. What is the advantage of using FTM1 over LPTMR in order to count pulses ?
2. Is there a better (right?) way to modify the Freqcount library to get the expected result (just a counter that reset itself after a decided amount of pulses and triggering an action)?
Thanks for your help !