Three-way PWM waveform of STM8S103

Publisher:心灵之窗Latest update time:2017-02-16 Source: eefocusKeywords:STM8S103 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Blog is a good notebook to record everything I am afraid of forgetting.

STM8S is inexpensive and of good quality. TIM2 can generate three PWM waveforms at the same time, with the fastest speed reaching 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


Keywords:STM8S103 Reference address:Three-way PWM waveform of STM8S103

Previous article:STM8S power consumption summary
Next article:STM8S power management - focus on active stop mode

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号