Skip to main content

Subsection 13.2.2 Part 2: How We Command the Servo

The signal that commands the servo’s position is the pulse from the reading (Figure 13.1.4): 1 ms to 2 ms wide, repeated every 20 ms. By convention 1.5 ms commands the middle position, and 1 ms and 2 ms command the two ends.

Activity 13.2.2. Between the pulses.

The pulse is at most 2 ms wide and the period is 20 ms, so for most of every period the signal is LOW. Does the servo hold its position during that time? And what happens if the pulses stop coming?
Between two pulses the servo holds the position that the last pulse commanded. As long as the same pulse keeps arriving at the servo, it stays at that one position and is held there. If you shut the signal down there is no power on the motor. So a servo rotates to the commanded position and then stays there as long as you apply the same pulses. The signal is a position signal, and you have to keep sending it. That makes this a different use of PWM from the motor’s: there the duty cycle set an average voltage that went to the motor, and here we are using PWM as a way to communicate with the controller rather than sending it to the motor directly.
The controller cannot tell apart pulse widths that are very close together. The datasheet for the Tower Pro SG92R lists a dead band width of 1 µs: a change in pulse width smaller than that produces no change in the commanded position. We’ll need that number when we choose how to configure our timer to produce the pulses.
Almost every pin on the Nucleo is capable of PWM, driven by one timer or another (Figure 13.2.7). We look up which timer drives a given pin, and which alternate function to select, in the datasheet; the pinout in Figure 13.2.7 then says where that pin is on the header.
Figure 13.2.7. The Nucleo-C031C6’s headers, with each pin marked by what it can do. Almost every pin can carry a PWM output, driven by one timer or another; Table 12 of the STM32C031C6 datasheet, Pin assignment and description, says which timer and which alternate function for each pin.

Activity 13.2.3. Which pins can TIM14 drive?

Which timer a pin can carry, and under which alternate function, is a property of the STM32C031C6 chip, so it is in the chip’s datasheet: Table 12, Pin assignment and description, on page 30 names the functions, and the alternate-function tables on pages 36 to 39 give the AF number. Which chip pin is at which position on the Arduino header is a property of the Nucleo board, and that is the Nucleo pinout.

(a)

TIM14 has one PWM output, its channel 1, named TIM14_CH1 in the datasheet, and the chip can route that output to any of several pins. Fill in the table: every pin that can carry TIM14_CH1, the alternate function (AF) number it is under, and, if the pin reaches the Arduino header, its name there. Table 12 of the STM32C031C6 datasheet, Pin assignment and description, page 30, names the functions; the alternate-function tables on pages 36 to 39 give the AF number.
Pin AF Arduino header name, if any
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

(b)

We used one of the pins you identified to carry the motor’s PWM in the motor chapter. Which pin is it, what is its name on the Arduino header, and which parts of the initialization will we be able to reuse today?