2012-03-08 06:09 AM
Hi!
I am outputting a PWM signal from TIM3/ch1 (pin PA6). The signal would be a clock signal for external chip btw and I need it to be switchable. All is working nicely. However, after the initialization code (see below), the initial state of the PWM pin is going high but I need it to stay low. How can I change that? I stepped through the TIM_OC1Init function in the standard library and found that the output goes high when I enable the output in TIM3->CCER (CC1E). Thank you in advance!void Init_PWM(void){
/* Compute the prescaler value */
PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 960;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/* TIM3 enable counter */
//TIM_Cmd(TIM3, ENABLE);
}//Init_PWM