PWM Output Failure on TIM2 Channel 3 Due to Encoder-Driven Counter Operation
TIM2 is configured in Encoder Interface Mode (TIM_ENCODERMODE_TI12). In this mode the timer counter (CNT) is driven by quadrature encoder transitions on channels CH1 and CH2 instead of the internal timer clock. PWM generation on TIM2 channel 3 relies on the same timer counter reaching the compare value (CCR3). Since no encoder transitions were present during testing, the counter remained at zero (TIM2->CNT = 0). Consequently the compare event never occurred and the PWM output did not toggle, resulting in a constant output level on the oscilloscope. The issue is therefore caused by the timer counter source being encoder-driven rather than clock-driven.
I am using an STM32U535VET6 with the following configuration:
1. TIM2_CH1 (PA0) → Encoder Input A
2. TIM2_CH2 (PA1) → Encoder Input B
3. TIM2_CH3 (PA2) → PWM output for a buzzer
TIM2 is configured in Encoder Interface Mode:
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
HAL_TIM_Encoder_Init(&htim2, &sConfig);
Channel 3 is configured as PWM output:
HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
During debugging I observed:
TIM2->SMCR = 3 // Encoder mode active
TIM2->CNT = 0
TIM2->CCR3 = 3200000
TIM2->ARR = 63999999
With no encoder movement, the PWM output on CH3 appears as a constant level on the oscilloscope and no PWM waveform is observed.
My understanding is that in Encoder Mode the timer counter (CNT) is driven by encoder transitions on CH1/CH2 rather than the internal timer clock. Since no encoder pulses are present, CNT remains at zero and never reaches CCR3, so the compare event does not occur.
Questions:
1. Is this understanding correct?
2. When TIM2 is configured in TIM_ENCODERMODE_TI12, can CH3 still generate an independent PWM signal?
3. Does PWM generation on CH3 depend on encoder-driven counter movement in this mode?
4. Has anyone successfully used TIM2 CH1/CH2 as an encoder and TIM2 CH3 as a PWM output simultaneously on an STM32U5 device?
