Difficulty configuring TIM16 for simple PWM output on STM32G483
I am working on an STM32G483VET6 in my own hardware. I am trying to use TIM16 CH1 (pin PE0) to generate a PWM signal which drives a sounder. I believe that in early tests I verified that it was working but I was probably messing around manually with register values in the debugger. I therefore think that my initialisation code is wrong but I can’t see why.
First of all, the pin is correctly connected; if I configure PEO as a GPIO output by setting the MODER bits for PE0 to 2 (output) and set PE0 high or low in the ODR, the output value gets to the sounder.
So far TIM16 is running in PWM mode, I can see the CNT register running up to ARR
and resetting but it the PE0 is tri-state when configured to be the output for TIM16_CH1.
Rather than paste pages of code, these are the values in the relevant GPIOE and TIM16 registers I observe in the stopped debugger when I believe that PE0 should be driven by TIM16_CH1 but is tri-state:
GPIOE registers Bits Value Comment
MODER [0:1] 0x2 Alternate function
AFRL0 0x4 PE0=AF4 (TIM16_CH1)I think the PE0 is correctly mapped to TIM16_CH1.
The HRM says that "tim_ocx output is enabled by a
combination of the CCxE, CCxNE, MOE, OSSI and OSSR bits (TIMx_CCER and
TIMx_BDTR registers).�?
Relevant TIM16 Register values observed are:
Register CCER
CC1NP 0
CC1NE 0
CC1P 0
CC1E 1
Register BDTR
MOE 1
OSSI 0
OSSR 0I think that according to HRM0440 Rev 7 (Table 303), the output control for TIM16_CH1 should be being driven but it isn’t.
Is there anything else that needs setting up to get the pin correctly driven?
