AnsweredAssumed Answered

stm8s TIM1 PWM not working

Question asked by levy.udi.001 on Apr 18, 2016
Latest reply on Jan 29, 2018 by Todd Phelps
Hi,
I'm trying to operate TIM1 on STM8S003F3P6, I am using the standard peripheral library code, but I am only able to produce pwm on TIM1_CH3 (PC3) pin, the other pins do not produce any waveforms at all. I'm sure this is not a hardware issue- because when I toggle the pin as a gpio- it works fine, what am I missing here?

The code is:

static void TIM1_Config(void)
{
  /* TIM1 Peripheral Configuration */ 
  TIM1_DeInit();
  
  /* Time Base configuration */
     /*
  TIM1_Prescaler = 0
  TIM1_CounterMode = TIM1_COUNTERMODE_UP
  TIM1_Period = 65535
  TIM1_RepetitionCounter = 0
     */


  TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 65535,0);


  /* Channel 1, 2 and 3 Configuration in PWM mode */
  /*
     TIM1_OCMode = TIM1_OCMODE_PWM2
  TIM1_OutputState = TIM1_OUTPUTSTATE_ENABLE
  TIM1_OutputNState = TIM1_OUTPUTNSTATE_ENABLE
  TIM1_Pulse = CCR1_Val
  TIM1_OCPolarity = TIM1_OCPOLARITY_LOW 
  TIM1_OCNPolarity = TIM1_OCNPOLARITY_LOW        
  TIM1_OCIdleState = TIM1_OCIDLESTATE_SET
  TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET
     */
 
  
  TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE,
               CCR1_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,
               TIM1_OCNIDLESTATE_RESET);


  /* TIM1_Pulse = CCR2_Val */
  TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
               CCR2_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,
               TIM1_OCNIDLESTATE_RESET);


  /* TIM1_Pulse = CCR3_Val */
     TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
               CCR3_Val, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_SET,
               TIM1_OCNIDLESTATE_RESET);


  /* Automatic Output enable, Break, dead time and lock configuration */
  /*
     TIM1_OSSIState = TIM1_OSSISTATE_ENABLE
  TIM1_LockLevel = TIM1_LOCKLEVEL_1
  TIM1_DeadTime = 117
  TIM1_Break = TIM1_BREAK_ENABLE
  TIM1_BreakPolarity = TIM1_BREAKPOLARITY_HIGH
  TIM1_AutomaticOutput = TIM1_AUTOMATICOUTPUT_ENABLE
     */




  /* TIM1 counter enable */
  TIM1_Cmd(ENABLE);


  /* Main Output Enable */
  TIM1_CtrlPWMOutputs(ENABLE);
}





Outcomes