2015-01-28 12:29 PM
Hi,
I have figured out how to change the period of the Timer 3 on the fly by using TIM3->CNT = someNewValue; and it works good. However, the duty cycle requires updating as well, set up originally as PWM pulse (TIM_Pulse) on Output Channel 1. Here is the code, where dutyCycle is a value from 0.1 to 0.5: TIM_OCInitStructure.TIM_Pulse = (uint16_t)(Period * dutyCycle); TIM_OC1Init(TIM3, &TIM_OCInitStructure); I would like to be able to modify a TIMx register directly to do this. I've looked through the manual but did not see what register(s) I would need to write to do this. Any help/suggestions? Or do I have to re-run the configuration completely? Thank you...2015-01-28 01:07 PM
TIM3->CCR1 = (Period * dutyCycle);
You'd also want it to load at the Update, ie not Preload/Immediate If you change it immediately you'll get phase noise or cycles where it's high or low for the remained of the period. The timer normally has shadow registers which copy to the live ones at the update event.2015-01-28 02:56 PM
clive1,
There is no effect when I try writing that register, with either timer 3 or timer 4: TIM3->CCR1 = (timerPeriod * dutyCycle); TIM4->CCR1 = (timerPeriod * dutyCycle); The duty cycle is at 50% (0.5) when I start, and after 10 seconds I do the write above with a new dutyCycle = 0.15, but there is no change.2015-01-28 03:00 PM