STM8S103的三路PWM波形
2017-02-16 来源:eefocus
博客是个不错的记事本 把我怕忘掉的,都记下来
STM8S物美价廉,TIM2可同时产生三路PWM波形来,最快可达5MHZ
#include 'stm8s.h'
uint16_t CCR1_Val = 500;
uint16_t CCR2_Val =
250;
uint16_t CCR3_Val = 100;
static void TIM2_Config(void);
void
main(void)
{CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);//16/1=16MHZ
TIM2_Config();
while (1)
{}
}
static void TIM2_Config(void)
{
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 200);
TIM2_OC1Init(TIM2_OCMODE_PWM1,
TIM2_OUTPUTSTATE_ENABLE,CCR1_Val, TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(ENABLE);
TIM2_OC2Init(TIM2_OCMODE_PWM1,
TIM2_OUTPUTSTATE_ENABLE,CCR2_Val, TIM2_OCPOLARITY_HIGH);
TIM2_OC2PreloadConfig(ENABLE);
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val,
TIM2_OCPOLARITY_HIGH);
TIM2_OC3PreloadConfig(ENABLE);
TIM2_ARRPreloadConfig(ENABLE);
TIM2_Cmd(ENABLE);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif
上一篇:STM8S 功耗总结