Skip to main content
Ngai yuk kong
Associate II
May 29, 2018 7:43 AM UTC
Question

Input Capture on very high frequency

Posted on May 29, 2018 at 09:43

Hi All,

I am now working on STM32F071 running at 48MHz. I would like to use timer to capture a signal at frequency higher than 400KHz.

Originally I use the input capture interrupt to read the period and duty cycle. The method is ok up to 4xxKHz. Then when the signal frequency becomes higher (600kHz for example), my software in main loop does not have chance to run at all.

I want to ask:

1. Is there any one shot input capture mode so that the software will not keep entering the input capture interrupt ? (if yes, how to set?)

2. What normally people will do if they require to continuously monitor a very high frequency input signal using input capture mode?

Thank you very much.

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    17 replies

    T J
    Senior III
    May 29, 2018 8:51 AM UTC
    Posted on May 29, 2018 at 10:51

    how much higher than 400khz ?

    Ngai yuk kong
    Associate II
    May 29, 2018 10:54 AM UTC
    Posted on May 29, 2018 at 10:54

    over 600kHz

    T J
    Senior III
    May 29, 2018 11:00 AM UTC
    Posted on May 29, 2018 at 11:00

    use a high speed 32 bit counter with prescaler of 1.

    DMA the input capture values into a 1K circular buffer.

    the DMA pointer is your 'flag'

    then use a foreground process check the pointer has changed, to calculate what you need.

    in the foreground

    You could check every tenth value to make it easier to keep up

    AvaTar
    Senior III
    May 29, 2018 9:06 AM UTC
    Posted on May 29, 2018 at 11:06

    It sounds like your core is saturated with the high interrupt load. How long and complex is the handler routine ?

    Nonetheless, the core will saturate at one point only from the entry/exit.

    You could check every tenth value to make it easier to keep up

    Would have suggested it, too.

    Perhaps you can enable the capture interrupt every once in a while (e.g. once per millisecond) for a single-shot.

    Ngai yuk kong
    Associate II
    May 29, 2018 11:11 AM UTC
    Posted on May 29, 2018 at 11:11

    sounds like i have three options:

    1. Use DMA to effectively lower down the interrupt 

    2. Use one shot by manually disable the interrupt inside the input capture ISR

    3. Polling the capture results periodically 

    Ngai yuk kong
    Associate II
    May 29, 2018 11:48 AM UTC
    Posted on May 29, 2018 at 11:48

    One more thing I want to know:

    Is there any side-effect if the input capture overflow flag is set? 

    I see the flag is set but the data seems like still correct..............

    S.Ma
    Principal
    May 29, 2018 11:17 AM UTC
    Posted on May 29, 2018 at 13:17

    If only the frequency measurement is needed, typically prescale the frequency before it is measured.

    If the signal is prescaled by 8, the measured frequency will be 8 times slower (and accurate).

    Otherwise, I would simply activate the input capture when I want a one measurement done. Once the 1 or 2 input capture interrupt are done to yield a result, make the interrupt self-disable itself. The main loop will then know there is a measurement available, read it and decide when is a good time to launch another measurement.

    The trade-off is the response time to frequency change, which would be small here.

    Make sense?

    Different scheme would be needed to measure the duty cycle...

    Ngai yuk kong
    Associate II
    May 30, 2018 2:16 AM UTC
    Posted on May 30, 2018 at 02:16

    I did the self disable in the input capture routine and got fxxk by the supervisor. He said the decision has to be made in the main loop, not inside the interrupt routine. This is the beginning of the story I posted here......

    henry.dick
    Associate II
    May 30, 2018 11:00 AM UTC
    Posted on May 30, 2018 at 13:00

    If you are trying to measure high frequency using input capture interrupts you are going down a very wrong path. Instead configure the timer as a counter for the external pulse train.