cancel
Showing results for 
Search instead for 
Did you mean: 

Pwm input capture mode in stm32H7 MCU

Edwin kaus
Associate II
Posted on April 22, 2018 at 05:41

HELLO..

I want to measure the frequency and duty cycle of the external signal. I have gone through some example available , and suggestions on website. Everywhere they are using either channel 1 or channel 2 in any of timer , unfortunately in my case signal is given to channel 4 ,  Is it still possible to measure duty cycle and frequency by using channel 4 , if so how to configure the same in stm cubemx ..

Can anybody suggest please , I am fully stuck with this issue ..

Thank you

#pwm-input #stm32h7 #cubemx
5 REPLIES 5
Posted on April 22, 2018 at 16:06

The PWM Input mode pairs Channel 1 and 2.

You could use Input Capture with Channel 4, and Channel 3 (Indirect) to time stamp TIMx_CH4 along the timeline of TIMx and interrupt. You could then delta measurements in an interrupt (or sample with DMA), to measure the period and duty of an input signal.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 22, 2018 at 16:45

Hello ..

Thanks for response ..

I am just confused , Can you please give me some more explanation, suggest some example project if possible . In stm example project they used TIM1 channel 1 as direct & channel 2 as indirect mode .  I am using TIM 8 CHANNEL 4 for frequency capture and duty cycle measurements.

Suggest me how to configure the tim8 and how calculate duty cycle .

Posted on April 22, 2018 at 17:33

Use a free-running timer, use CH3 and CH4 to time-stamp different edges, and subtract values, or prior values.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 22, 2018 at 19:12

Hello ...

Thanks for the information ..

As per my understanding I need to set channel 4 for input capture mode (direct mode) with rising edge , and channel 3 for falling edge(indirect mode) . 

With the above configuration once rising edge detected i will read both channel capture values, then once falling edge detected (so this difference gives active pulse time) , and then next rising edge value give full cycle period .

Is my understanding is right , can I get both duty cycle and period with this configuration.

Posted on April 22, 2018 at 19:26

>>Is my understanding is right , can I get both duty cycle and period with this configuration.

The math and concept here should not be confusing.

If you time 3 consecutive edges A, B, C starting with a rising edge

C - A describes ticks for period

B - A describes ticks for high time

C - B describes ticks for low time

((B - A) * 100) / (C - A) describes high duty in percent

A clock ticking at 1 MHz will have ticks describing micro-seconds

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..