Skip to main content

Subsection 11.3.3 Part 3: Where Those Registers Are Located in the Hardware

Figure 11.3.6. One frozen moment of the trace you watched earlier (Figure 11.2.29). The window is about two milliseconds wide, so it holds roughly three periods of the 1.6 kHz waveform and the duty cycle barely changes across the screen.
The width of the HIGH part changed as the motor sped up and slowed down, while the period did not. So which of the two numbers we set up (the value the counter runs to, or the value it is compared against) is the program rewriting every two seconds?
The answer is the compare value. The program writes a new one every two seconds as the ramp climbs and falls, and it never touches the auto-reload register after the initialization, which is why the width of the HIGH portion moves while the period stays exactly where it is. A program that rewrote the auto-reload value instead would change the frequency of the waveform rather than its duty cycle, and the motor would not speed up at all. Figure 11.3.8 shows the whole path from the clock to the pin, and Figure 11.3.9 is where both of those numbers are in the manual’s own drawing.
Figure 11.3.8. The path from the clock to PA7, as a simplified block diagram. The prescaler sets the rate at which the counter counts. The counter counts up to the value in the auto-reload register and starts over, which sets the period. The comparator compares the counter with the value in the compare register, which sets how long the output stays HIGH. The result then passes through the output mode (the OC1M field of TIM14_CCMR1) and the enable bit (CC1E in TIM14_CCER) before it reaches the pin. The first five blocks are registers we have already set; the last two are new today.
Figure 11.3.9. Where the two numbers actually are (RM0490, Figure 176). The counter runs along the bottom and the compare value is shown above it, and the comparator to the right of them is what flips the output partway up each period, which is why TIM14_CCR1 sets how long the pin stays HIGH and TIM14_ARR, the value the counter runs up to, sets how long the period is.
We already worked out what CC1E does (it lets the channel’s output reach the pin). What the figures have not shown yet is the output stage the comparator’s result travels through on its way to PA7: the enable bit is the last thing it passes through.
Figure 11.3.11. How the signal gets out to the pin (RM0490, Figure 177). The waveform produced by the comparator in Figure 11.3.9 arrives at the left and reaches the pin at the right only if the output enable circuit lets it through, which is what the CC1E bit does. One difference from the printed manual worth knowing: RM0490 labels these boxes TIM1_CCER, which is a slip carried over from the chapter on TIM1. The figure is in the TIM14 chapter and the register our code writes is TIM14’s. We have put it back to TIMx_CCER, the manual’s own way of writing “whichever timer you are using”, which is how the same figure already labels TIMx_CCMR1 at the lower left, under the OC1M box.
We’ll look at those registers once more as RM0490 §17.4 actually prints them, because that is the form you’ll be reading in the lab and in the rest of this chapter: a row of numbered bits with a name written across the ones that belong to each field.
Figure 11.3.13. The timer’s four registers as rows of bits, the way RM0490 §17.4 prints them: the counter itself, and the three numbers we set around it. The prescaler sets the rate the counter counts at, the auto-reload register sets the period, and the capture/compare register sets the HIGH time.