2014-06-04 10:27 AM
I have a high speed clock at 10 MHz going to the processor's TIM4 input capture pin (ch.3). I would like to verify that the clock is running at 10 MHz with the processor's input capture. I coded the processor with the input capture module, and it works fine for lower frequencies (around 1 kHz or so). Once I start to climb the frequency up to the MHz range, the processor starts to miss interrupts and thus gives me an incorrect frequency. I didn't see anywhere in the datasheet that states the maximum frequency that the input capture can read. I have an external clock of 8 MHz, and a core clock of 72 MHz, so I would imagine that I can read a 10 MHz signal. Any ideas?
#stm32f103-inputcapture2014-06-04 10:43 AM
Beyond a few hundred KHz you're into the stupid zone for interrupts as they will saturate the processor.
a) Use PWM input mode where the TIM count is reset, and CCR1/CCR2 latch period and/or duty measurements, and read at your leisure. b) Use External Count mode, and integrate over a fixed period, say 1 ms. There are gating modes, but you could also pace a DMA to sample TIMx->CNT at regular intervals, and compute tick deltas There is also a prescaler on the input capture, up to 8X but this won't help for 10 MHz Also understand that the input pins have a resychronizer circuit on them to get them into the 72 MHz clock domain. An independent clock of 10 MHz is going to drift wrt to the 72 MHz, and you are also going to get beating/aliasing type sampling effects. The counters are integer, 10 MHz is 7.2 cycles of 72 MHz2014-06-04 10:50 AM
Thanks. So since I only really need to check this frequency once at startup, it would be better if I did the PWM input mode?
2014-06-04 11:00 AM
Perhaps, but I'm not sure it offers you the precision/granularity you need. The IC prescaler may well work in PWM Input mode, if you put it in 8X mode it should be evident in the reading. ~57.6 ticks at 72 MHz
I'd prefer to count 10000 ticks in 1ms Some of the STM32 models permit measuring of LSI and LSE against the 8 MHz (HSE) as I recall, but these are in the 30-40 KHz range2014-06-04 11:18 AM