I am using a stm32f030k6t6 microcontroller and I have a problem with my pwm function on TIM17..
It is very strange: when I power up my controller, sometimes my pwm act as PWM1 and sometimes as PWM2.
I didn't code any condition about this in my program, so there is absolutely no reason for my controller to act as PWM1 or PWM2 when it wants. (I've programmed it as PWM1 in my code).
I am using TIM17 CH1 (CH1N is disabled by default), on PA7 (AF5).
(I am using 2 others PWM, TIM3 CH3 and CH4, PWM1 too, and they are working fine..)
What could possibly the cause of the problem? I was wondering if this could be caused by the voltage that is not stable at power up... But still, I've programmed 12 controllers with this program, and 3 of them are working as PWM1, 9 as PWM2, without any reason. The circuit is exactly the same...
Is it a default of the microcontroller (of this version..) ?
This problem drives me mad.. If someone could help, I would be grateful!
Here is the code:
* Initializes Pins for PWM
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // PA7 (PWM)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_Init(GPIOB, &GPIO_InitStructure); //
GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_5); //
* Configure PWM
* TIM17 CH1
// Time Base Configuration for TIM17
TIM_TimeBaseStructure.TIM_Period = (PWM_TOTPERIODS - 1); // = (3M / 10000) - 1 = 299
TIM_TimeBaseStructure.TIM_Prescaler = (SYSTEMFRQ / PWM_PREDIVISED_FREQ) - 1; // = 48M / 3M - 1 = 15
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
// Channel 1 configuration on TIM17
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = PWM_PHASE; // = 1, because 0% should not be allowed
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM17, &TIM_OCInitStructure); // Channel 1 configuration done
// Enable outputs on TIM17
// TIM17 enable counter