cancel
Showing results for 
Search instead for 
Did you mean: 

F103 Input capture too slow

gausfresser
Associate II
Posted on June 04, 2014 at 19:27

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-inputcapture
4 REPLIES 4
Posted on June 04, 2014 at 19:43

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 MHz
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gausfresser
Associate II
Posted on June 04, 2014 at 19:50

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?

Posted on June 04, 2014 at 20:00

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 range
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gausfresser
Associate II
Posted on June 04, 2014 at 20:18

OK. I also see in the datasheet that PWM input mode can only be used with TIMx_CH1/CH2 signals, and I have this clock wired to CH3.

So what I would do is just wait 1 ms while the counter counts the pulses, and verify that about 10000 pulses were counted? This way, I don't need interrupts for the input capture that caused the processor to miscount.