cancel
Showing results for 
Search instead for 
Did you mean: 

measure pulse width(pwm) with input capture

mohamad_armoon
Associate III
Posted on August 31, 2014 at 14:00

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
5 REPLIES 5
Posted on August 31, 2014 at 14:20

2- i want to generate pwm in 50hz . is there any formula to set the value ofPrescaler and period to get 50hz pwm . i don't know how should i setup this value ??

It's an exercise in division, taking the bus clock and getting it down to the desired frequency using the multiple of two factors, the Prescaler and the Period.

If I prescale the bus clock down to 1 MHz, each tick is 1 us, 50 Hz is 20 ms, so that's 20000 ticks of a 1 us clock.

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/%5bSTM32f4discovery%5dSome%20clarification%20about%20PWM&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on August 31, 2014 at 18:49

thanks for your response.

so the prescale depends onMaxtimerclock . so for each timer the prescaler number would be different for generating specific frequency. in this function ofe your code :void TIM3_IRQHandler(void)

if
(TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
{
/* Clear TIM3_CH1 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
Current = TIM_GetCapture1(TIM3);
Delta = Current - Last[0];
Last[0] = Current;
if
(Delta)
Freq[0] = 1000000 / Delta; 
// 1MHz clock 
}

what exactly hapening in ''if'' statement ?? what is the return value of ''

TIM_GetCapture1(TIM3) '' ??

Posted on August 31, 2014 at 19:33

It reads the latch TIM3->CCR1, which at the capture events is loaded with TIM3->CNT

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on September 01, 2014 at 13:01

thanks Clive1.

thanks for answer.

Ok, if i get it right the TIMx_CNT is the timer counter which keep the number of edges .

at last whit this code i can just get the frequency of input signal . but i want to get the pwm duty cycle . how should i get this ???

Posted on September 01, 2014 at 14:52

at last whit this code i can just get the frequency of input signal . but i want to get the pwm duty cycle . how should i get this ???

Ok, as I've told you more than once before, you need to be capturing both edges, from which you should be able to determine both period and duty with 3 consecutive measurements.

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