2011-11-16 06:11 AM
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 000So If the input signal is like 50Hz that means :21 000 000 / 50 = 420 000So 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 000So for 50 Hz its like:10 500 000 / 50 = 210 000Conclusion - 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 #pwm2011-12-11 10:19 PM
Go back to the docs and look for TIMx_PSC. Then set TIMx_ARR based on a much lower frequency.
2011-12-12 06:41 AM
Set
TIM_TimeBaseStructure.TIM_Prescaler = 21000 - 1; and try the math again.2011-12-30 02:12 AM
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