Lecture 11 - PWM and the STM32

We usually want to use PWM, or Pulse-Width-Modulation, to control things that we want to control the power draw/transfer of. We can linearly control the power of the device, and as such it can linearize devices with non-linear characteristics (like motors).

An Aside on Servos

A servo is a DC motor with a gearbox and controller. The controller expects a 50Hz PWM, and varying the pulse-width will set the angle of the servo. They are meant to control angle of the motor, not really things like velocity and acceleration.

Look at the CCR registers for our interrupts to help create a PWM. We did one for A4, but the general idea is that we have CCR1 be the "turn on" interrupt, and the CCR2 be the "turn off" interrupt, with some frequency dependent on ARR. See what we did for Lecture 6 - Timers and Interrupts for more information.

The STM has PWM modes, but they aren't really needed. They can be used to measure and record input PWM signals to deal with them. They are also handled in the TIM2 or similar. It's also set in the CCR for our TIM register.