cancel
Showing results for 
Search instead for 
Did you mean: 

Low freq PWM output

csdominik
Associate III
Posted on November 16, 2011 at 15:11

Hello, 

I try the examples about PWM input form st.com, but it works only for big frequency signals. (like it is said in readme.txt). 

What should I change with settings TIM4 for example, to be able to check the low frequency signals on its CH2 input? By low freq I mean 50Hz.

I think about TIM_ICInitStructure.TIM_ICPrescaler coefficient. But form my calculations:

1st example - when Timer clock is 160 000 000 Hz :

Even if I chose TIM_ICPSC_DIV8 I get:

168 000 000 / 8 =  21 000 000

So If the input signal is like 50Hz that means :

21 000 000 / 50 = 420 000

So its approximately 430 000 clocks for 1 duty. While the TIM4 is 16-bit timer, so the max counter value is : 65 535. Its like 6 times overflow. 

2nd example - when my timer clock is 84 000 000:

TIM_ICPSC_DIV8 -> 84 000 000 / 8 = 10 500 000

So for 50 Hz its like:

10 500 000 / 50 = 210 000

Conclusion - there is 210 000 clock cycles for 1 duty of input PWM. The timer will overflow about 3 times.

It there any solution for this problem?

Should I change TIM_TimeBaseStructure for TIM4 before setting TIM_ICInitStructure ?

Or there is another way?

#tim4 #pwm
3 REPLIES 3
picguy2
Associate II
Posted on December 12, 2011 at 07:19

Go back to the docs and look for TIMx_PSC.  Then set TIMx_ARR based on a much lower frequency.

Posted on December 12, 2011 at 15:41

Set

TIM_TimeBaseStructure.TIM_Prescaler = 21000 - 1;

and try the math again.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
elijah
Associate II
Posted on December 30, 2011 at 11:12

I've programmed servomotor PWM control. Just set prescaler to generate 1MHz, then set counters to generate 50Hz impulses from 500 to 2500 microseconds long with 1 microsecond resolution. This way allows me  to have up to 4 independed channels from TIM4. Just use prescaler.

http://www.youtube.com/watch?v=9Ad16DxCP3c&feature=player_embedded