General Purpose Pulse Width Modulation (TIM2 PWM)
Pulse Width Modulation (PWM) is a must-have feature of any microcontroller. PWM has many uses
like motor control, SMPSs, lighting control, sound generation, waveform generation, etc. Unlike other
micros which have limited PWM channels, STM8 has several PWM channels. For instance, STM8S003K
has seven independent PWM channels, three of which belong to TIM2 – a general purpose (GP) timer.
PWMs generated by GP timers are basic PWMs. They can be used for simple tasks like LED brightness
control, servo motor control, etc. that don't require advanced features like dead-time, brake or
complementary waveform generation. In this section, we will see how to use TIM2 to generate simple
PWMs.
Please note that in more advanced STM8 micros, timer I/Os are dependent on alternate function
configuration bits. Check those bits before uploading codes. In some STM8 micros, the I/Os are also
remappable, meaning that the I/Os can be swapped in different GPIOs. Take the help of STM8CubeMx
if needed.
Hardware Connection
Need help?
Do you have a question about the STM8 and is the answer not in the manual?
Questions and answers