cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 PWM outputs wrong signal to mosfets

mehmet.karakaya
Associate III
Posted on July 02, 2014 at 14:34

hello dear forum

I drive an H bridge with STM32F103 I want that until I enable the H bridge the PWM outputs to be low ( I runbelow reset_motor() function until motor enabled ) however the Upper mosfets are driven with logic 1 until I enable the motor here is my code please which lines to be changed how ? thank you

void
PWMinit2(
void
){ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
GPIO_Init(GPIOC, &GPIO_InitStructure); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
GPIO_Init(GPIOB, &GPIO_InitStructure); 
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 99; 
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_TimeBaseStructure.TIM_Period = 7200; 
TIM_TimeBaseStructure.TIM_ClockDivision = 0; 
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; 
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure); 
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; 
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; 
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; 
TIM_OCInitStructure.TIM_Pulse = 6000; 
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; 
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; 
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; 
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; 
TIM_OC1Init(TIM8, &TIM_OCInitStructure); 
TIM_OC2Init(TIM8, &TIM_OCInitStructure); 
reset_motor(); 
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; 
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; 
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; 
TIM_BDTRInitStructure.TIM_DeadTime = 120; 
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; 
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low; 
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; 
TIM_BDTRConfig(TIM8, &TIM_BDTRInitStructure); 
TIM_CCPreloadControl(TIM8, DISABLE); 
TIM_ARRPreloadConfig(TIM8, ENABLE); 
TIM_ITConfig(TIM8, TIM_IT_Update , ENABLE); 
/* TIM1 counter enable */
TIM_Cmd(TIM8, ENABLE); 
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM8, ENABLE); 
reset_motor(); 
} 
void
reset_motor(
void
){ 
TIM_CCxCmd(TIM8, TIM_Channel_1, TIM_CCx_Disable); 
TIM_CCxNCmd(TIM8, TIM_Channel_1, TIM_CCxN_Disable); 
TIM_CCxCmd(TIM8, TIM_Channel_2, TIM_CCx_Disable); 
TIM_CCxNCmd(TIM8, TIM_Channel_2, TIM_CCxN_Disable); 
}

0 REPLIES 0