STM32H7 Injected ADC timing discrepancy
Hi!
I am experiencing some confusing behaviour on an STM32H743 series chip:
I am running an injected ADC channel on ADC2, with trigger from the HRTIM. The HRTIM is triggering at 8000 Hz (200 MHz clock, prescaler div-2 and period = 12500). The ADC generates an interrupt at injected end-of-conversion, with 64.5 cycles per sample in 16-bit mode. The ADC clock is running at 80 MHz, with prescaler div-4, i.e. 20 MHz.
When setting an oversampling ratio such that the conversion time becomes longer than the time between the trigger pulses, I always get half the expected frequency for the generated interrupts.
For example, with oversampling ratio 64, I can calculate the conversion time as:
t_conv = (64.5 + 8.5) * (1 / (20*1e6)) * 64 = 0.2336 ms
where the 8.5 extra cycles come from the fact that we are in 16-bit mode as per documentation.
From this, the ratio between the conversion time and the time between two consecutive trigger pulses is about 2, i.e. for each conversion I should miss one trigger pulse, and the expected measured frequency would be 4000 Hz. I however measure 2000 Hz instead. I am toggling the measured pin on and off immediately in the interrupt handler, so it's not a matter of accidentally only toggling it half of the time.
This behaviour is consistent regardless of the following which I've tested:
Changing the oversampling ratio, the ADC clock prescaler, single-ended/differential mode, regular vs injected conversion and HRTIM trigger sources.
So for example, with oversampling ratio 1024 I should theoretically get interrupts at 266.66 Hz from my calculations, but I get them at 133.333 Hz, and so on. If I turn oversampling off, and set 1.5 cycles I get 8 kHz as expected, so this only occurs when the conversion time is longer than the time between the trigger pulses.
I do not do any changes to the HRTIM or ADC registers in code. Where is the extra factor 1/2 coming from, and what am I missing?
Thanks!
