cancel
Showing results for 
Search instead for 
Did you mean: 

USING A GPIO PIN TO TAKE INPUT OF A PWM SIGNAL FOR MEASURING DUTY CYCLE AND FREQUENCY

ritayandhara10
Associate II

I have a stm32g031k8 board. I was trying to give a pwm input signal like a square wave, measuring the frequency and duty cycle and generate pwm signal of that frequency and duty cycle using another timer. I was also changing the frequency and duty cycle of the input signal on the fly and it should change the output signal instantly. I was unable to do it. I was able to measure the frequency but nothing works. Please help me with the procedure. Thank You.

4 REPLIES 4

What Frequency are you attempting to measure.

Should use the PWM Input modes, when CH1 captures period and CH2 the duty. Look for examples using the various boards that come in the CubeG0 package. Perhaps also review the TIM Cook Book

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

Hello @ritayandhara10

You can refer to the TIM_PWMInput example to measure the duty cycle, period

Since you're changing those parameters, you may want to use interrupts to capture the input signal edge and update PWM output signal

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I am giving an input frequency of 10 khz to like 500khz. I was using the timer 1 channel 1 for capturing the rising edge and channel 2 for capturing the falling edges. Then using the timer 2 I was trying to generate a PWM signal

I am giving an input frequency of 10 khz to like 500khz. I was using the timer 1 channel 1 for capturing the rising edge and channel 2 for capturing the falling edges. Then using the timer 2 I was trying to generate a PWM signal.