AnsweredAssumed Answered

How to generate PWM on TIM3 - CH3 on STM32F103 device

Question asked by anton.bogdan on Jan 10, 2016
Latest reply on Jan 11, 2016 by anton.bogdan
Hello all,  i have some mouses around my house and need a pwm driver for a mouse trap   but i have some dificulties generating a pwm signal on PB0 ( Timer 3 channel 3 output)


   RCC_APB2PeriphClockCmd(RCC_APB1Periph_TIM3 |  RCC_APB2Periph_GPIOB , ENABLE);
      
     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; // Timer3 channel 3 on PB0
      GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
      GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
      GPIO_Init(GPIOB,&GPIO_InitStructure);
        
         TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
 
       /**** Timer3 time base setup ****/
       TIM_TimeBaseInitStructure.TIM_Prescaler=30-1;
       TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up ;
       TIM_TimeBaseInitStructure.TIM_Period = 10000;
       TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;
       TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
TIM_Cmd(TIM3, ENABLE);
 
       TIM_OCInitTypeDef TIM_OCInitStructure;
       TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
       TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_Enable ;
       TIM_OCInitStructure.TIM_Pulse = 5000;
       TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 
        TIM_OC3Init(TIM3, &TIM_OCInitStructure); //PB0 - ouptut pwm on channel 3
       TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
        
     TIM3->CCR3=15; // just some duty cycle value

with the code above i am unable to have any type of pwm signal on PB0,  I am doing something wrong?

Outcomes