The goal of this chapter is to control the position of a servomotor from the STM32C031C6. A servomotor is a motor that rotates to the angle we command and holds it there, rather than turning continuously. Inside it are a DC motor, a gear train, a potentiometer and a control circuit, and all we supply as a command is one signal: a pulse whose width carries the position we want. To produce that pulse we’ll use TIM14’s PWM (pulse-width modulation) output again, as we did for the motor, but this time the period is about 20 ms rather than the fast switching a motor’s speed needed. We’ll read the position we want from a potentiometer with the ADC (analog-to-digital converter), as we did in the ADC chapter.
This chapter covers a class day and the x-hour after it. We’ll design the timer for the servo’s pulse, check on the AD2 oscilloscope that the pulse is the one we designed, and then connect the servo to its own 5 V supply and watch it follow the potentiometer. The x-hour is for completing that exercise. In Lab 8 this servo carries the arm of a solar tracker. Section 13.4 collects the pulse convention, the timer arithmetic and the driver for looking up later.
Design TIM14 for a 50 Hz pulse: choose a prescaler and an auto-reload value that fit the 16-bit register, and judge the resulting resolution against what the servo can use.