using slow timer with Teensy 3.1 via fixed frequency clock instead of system clock

Status
Not open for further replies.

ThomasB

New member
I want to measure times in milliseconds range up to 1000ms. Using the FlexTimer and the system clock with biggest possible divider would produce too many overflows. So the idea came up to use a slower clock source: the "fixed frequency clock". But choosing this, my timer dosn't count anymore and stays at zero.

So this works:

MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_IREFS | MCG_C1_IRCLKEN;
FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(7);
FTM0_CNT = 0;

but changing to the fixed frequency clock not:

MCG_C1 = MCG_C1_CLKS(0) | MCG_C1_IREFS | MCG_C1_IRCLKEN;
FTM0_SC = FTM_SC_CLKS(2) | FTM_SC_PS(7);
FTM0_CNT = 0;

I think I missed a detail.
 
...no this doesn't meed my needs. I want to measure a kind of PWM signal where two adjacent edges have a distance between 0 to 1000 milliseconds.

Before I did it with an original Arduino and its timers without any problems. Now I want to switch with my application to the teensy.

I'm not sure if I get your explanation fully. I try to use the FLL or PLL. Looking into the datasheet I try various bits/options but the timer only runs with system clock.

Do you mean that with running at 72MHz and taking the 128 prescaler I can only achieve only ~116ms before overflowing at 0xFFFF for the timer. My understanding of the data sheet was that there is a possibility to take a slower clock source than the system clock (MCU= 72MHz) which is available inside the silicon in contrast to the third option of the external clock source ?
 
...ok, like always the devil is in details. Searching through the web, reading the data sheet again I get it.
The following code does my job:


FTM0_SC = 0; // Clear TPM0_SC register
FTM0_CNT = 0; // Reset the TPM0_CNT counter
FTM0_MOD = 0xFFFF; // Set overflow value (modulo)

FTM0_SC = FTM_SC_CLKS(2) | FTM_SC_PS(0) | FTM_SC_TOIE;

NVIC_CLEAR_PENDING(IRQ_FTM0);
NVIC_ENABLE_IRQ(IRQ_FTM0);

The stuff for the interrupt service routine could be defined in the already declared void ftm0_isr(void).
Some things were wrong in my first posts. So the system clock is not the full MCU clock its half of them and also named as internal bus clock. Using this bus clock I could achieve 3.556µs/tick. That's still to fast so I use the fixed frequency option to take the 32kHz crystal as clock source which is nice for longer pulses and could cover my measurement range with a maximum of one time overflow.
 
Last edited:
Status
Not open for further replies.
Back
Top