AnsweredAssumed Answered

STM32F103 TIM PWM on CH2N only

Question asked by Gregorsanec.Toni on Jul 15, 2015
Latest reply on Jul 16, 2015 by Clive One
Hello,

I have configured only PB0 (TIM1_CH2N) for PWM output, but I can't get any signal from the pin. code looks like this:

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE);


  gpio_struct.GPIO_Mode = GPIO_Mode_AF_PP;
  gpio_struct.GPIO_Pin = GPIO_Pin_0;
  gpio_struct.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB,&gpio_struct);
  
  GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);


  /* timebase setup */
  tmr_period = (SystemCoreClock / 25000);
  TIM_TimeBaseStructure.TIM_Period = tmr_period - 1;  
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);


  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = tmr_period/2;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
  
  /* channel 2*/
  TIM_OC2Init(TIM1, &TIM_OCInitStructure); 
  TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);


  /* enable main output */
  TIM_CtrlPWMOutputs(TIM1, ENABLE);


  /* enable timer */
  TIM_Cmd(TIM1, ENABLE);

Thanks

Outcomes