cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S003k3 TIM1 PWM problem

dexter_khm
Associate II
Posted on May 08, 2015 at 15:44

Hello every one. I have a workable code of pwm on STM8S105K4T6 and now I paste it in STM8S003k3 fnd it won't work.

&sharpdefine CCR1_Val  ((u16)2047) // Configure channel 1 Pulse Width Blue

&sharpdefine CCR2_Val  ((u16)2047) // Configure channel 2 Pulse Width

static void TIM1_Config(void)

{

   TIM1_DeInit();

  /* Time Base configuration */

  /*

  TIM1_Period = 4095

  TIM1_Prescaler = 0

  TIM1_CounterMode = TIM1_COUNTERMODE_UP

  TIM1_RepetitionCounter = 0

  */

  TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 4095, 0);

  /* Channel 1, 2,3 and 4 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_HIGH

  TIM1_OCIdleState = TIM1_OCIDLESTATE_SET

  TIM1_OCNIdleState = TIM1_OCIDLESTATE_RESET

  

  */ 

  /*TIM1_Pulse = CCR2_Val*/

  TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, CCR2_Val,

               TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, 

               TIM1_OCNIDLESTATE_RESET);

  /*TIM1_Pulse = CCR4_Val*/

  TIM1_OC4Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE, CCR1_Val, TIM1_OCPOLARITY_LOW,

               TIM1_OCIDLESTATE_SET);

  /* TIM1 counter enable */

  TIM1_Cmd(ENABLE);

  /* TIM1 Main Output Enable */

  TIM1_CtrlPWMOutputs(ENABLE);

}

Can any one tell me what is wrong here.

#stm8s003k3-tim1-pwm-problem
1 REPLY 1
dexter_khm
Associate II
Posted on May 08, 2015 at 20:26

Sorry my fault code is fine. I just forget remap Timer 1 -channel 4[AFR6] where my status led is