Frequency count precision and max frequency


what is the max frequency the pulse count input can handle? And how precise is the count result? If we want to implement frequency meter function, counting say pulses for 1 sec, will the count be precise? Say we have 21 456 567 mhz on pin 1, we count for 1 sec and we get 21 456 567 –+1 count?

I suspect the max freq will have to be <30MHz, but that’s just a guess (it’ll have to be les than the APB2 clock, maybe by 2x). The pin capacitance is typically 25pF so that’s quite a serious amount of drive required at high frequencies.

The counts are precise, we use TIM8 gated by TIM1; an interrupt handler triggers every 65536 counts to update the MSB.

However, the period has to be encoded in a single countdown of TIM1, so you won’t get exactly 1 second as a timer period. My head hurts trying to understand the code so I may leave it to Peter to comment on the detail of this and the best period to use.

You’d think that the maximum EXTI frequency would be something the STM32F205 datasheet would mention, but it doesn’t seem to. The minimum input pulse width that the counter will register, though, is documented: 10ns (datasheet Table 45), which for a 1:1 mark/space signal means that the maximum would be 50MHz.

As for precision, every pulse is counted (the gating of TIM8 by TIM1 is in hardware, so not even a CPU clock cycle intervenes), but at least two factors mean that the accuracy is not what you describe. Hugo is correct that the internal timer won’t generate exactly one second: the code chooses the nearest available period, which is (585932048)/1201000*1000 or 0.9999872 seconds. This is off by about one part in 78,000, or 13ppm. However, even this depends on the accuracy of the CPU’s own clock source, which is the imp’s on-board crystal. AFAICT the accuracy of that timebase is itself only +/-10ppm.

You can eliminate the 13ppm variation by choosing a period that’s an exact multiple of 65536/(12010001000) seconds (e.g. 0.65536 seconds) and multiplying up, but even so you will still suffer the 10ppm variation. To measure 20-something MHz accurate to the nearest Hz you’d need an 0.05ppm timebase, which is (presumably) a more expensive proposition that what we built the imp out of.


What would the max frequency be that the pulse pin 1 can output? same as what it can input?

Is it different for different models of imp (002, 003, 004)?