2014-08-31 05:00 AM
2014-08-31 05:20 AM
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.2014-08-31 09:49 AM
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) '' ??
2014-08-31 10:33 AM
It reads the latch TIM3->CCR1, which at the capture events is loaded with TIM3->CNT
2014-09-01 04:01 AM
2014-09-01 05:52 AM
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.