AnsweredAssumed Answered

STM8S TIM1 PWM2 not working

Question asked by Toan92.Lee on Jun 25, 2016
Latest reply on Jul 11, 2017 by Tim Bartlett
Hi all. please help me. I program my code in IAR embeded, I built no error, no warning, but it not working. this is my code in main.c :


#include "main.h"




void main(void)
{
  CLK_HSICmd(ENABLE);
  CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
  GPIO_Config();
  TIM1_Config();
  
  while (1)
  {
//TIM1_SetCompare1(349);
  }
  
}


void TIM1_Config()
{
  TIM1_DeInit();
  /* cau hinh timer 1 co dau ra PWM la 10kHz
  - bo chia tan 2
  - duty =30%
   Ftimer=16/2=8Mhz
   TimerPeriod= Ftimer/Fpwm  -1=799  
 
  */
  TIM1_TimeBaseInit(1, TIM1_COUNTERMODE_UP, 799, 0);
  TIM1_SelectOCxM(TIM1_CHANNEL_1,TIM1_OCMODE_PWM2);
  TIM1_OC1PolarityConfig(TIM1_OCPOLARITY_LOW);
  TIM1_CCxCmd(TIM1_CHANNEL_1,ENABLE);
  TIM1_SetCompare1(239);
  TIM1_OC1PreloadConfig(ENABLE);
  TIM1_ARRPreloadConfig(ENABLE);
  
    /* TIM1 counter enable */
  TIM1_Cmd(ENABLE);


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


void GPIO_Config(void)
{
  GPIO_DeInit(GPIOB);
  GPIO_Init(GPIOB,GPIO_PIN_5,GPIO_MODE_OUT_PP_LOW_FAST);
  GPIO_DeInit(GPIOC);
  GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_LOW_FAST);
}

and my code in main.h 

#ifndef __MAIN_H
#define __MAIN_H





/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "user_delay.h"






void TIM1_Config();
void GPIO_Config(void);


#endif /* __MAIN_H */
 


thanks for helping! 

Outcomes