Subsection 11.6.1 Register Summary: TIM14 in PWM Mode
The table below gives the registers
tim14_pa7_pwm_init() writes. Offsets are from each peripheral’s own base address, and the section numbers are RM0490’s.
| Register | Offset | Field | Purpose | RM0490 |
|---|---|---|---|---|
RCC_IOPENR |
0x34 | GPIOAEN |
Clock to GPIOA | §5.4.11 |
GPIOA_MODER |
0x00 | MODE7 |
PA7 to alternate-function mode (10) |
§6.4.1 |
GPIOA_AFR[0] |
0x20 | AFSEL7 |
Which alternate function: TIM14_CH1 on PA7 | §6.4.9 |
RCC_APBENR2 |
0x40 | TIM14EN |
Clock to TIM14 | §5.4.14 |
TIM14_PSC |
0x28 | PSC |
Prescaler; the counter is clocked at the timer clock divided by PSC+1 |
§17.4.9 |
TIM14_ARR |
0x2C | ARR |
The value the counter runs up to, which sets the period | §17.4.10 |
TIM14_CCMR1 |
0x18 | OC1M |
PWM mode: 0110 holds the pin HIGH until the counter reaches the compare value |
§17.4.6 |
TIM14_CCMR1 |
0x18 | CC1S |
Channel 1 as an output (00) rather than an input |
§17.4.6 |
TIM14_CCER |
0x20 | CC1E |
Let the channel’s waveform reach the pin. Leave it out and the counter runs with nothing on PA7 | §17.4.7 |
TIM14_EGR |
0x14 | UG |
Force an update event, so the buffered PSC reaches its working copy before the first period. Write-only, so the driver’s |= reads back zero and is harmless |
§17.4.4 |
TIM14_CR1 |
0x00 | CEN |
Start the counter | §17.4.1 |
TIM14_CCR1 |
0x34 | CCR1 |
The compare value: how much of each period the pin is HIGH. The only one that changes while the motor turns | §17.4.11 |
TIM14_CCMR1 is the register written twice, because OC1M and CC1S are two fields in it. OC1M is a multi-bit field, so it is cleared and then set rather than OR’d into: OR alone would leave whatever was there and mix the two patterns together. CC1E and CEN are single bits, which is why |= on its own is safe for them. The full register layouts are in Subsection 11.3.2.
