Dynamic phase shift
Hi,
My goal is to dynamically change the phase shift between two output signals. Ultimately I would like to do this by rotating an encoder knob, but for the sake of simplicity a software change will do to simplify things. I'm using a Blue pill (STM32F103C8T6).
TIMER 2 is set to Master:
Slave Mode: Disable
Channel1: PWM Generation CH1
Channel2: Output Compare No Output
Trigger Output (TRGO) Parameters:
- Trigger Event Selection: Output Compare (OC2REF)
Output Compare No Output Channel2:
- Mode: Active Level on match
TIMER 3 is set to Slave:
Salve Mode: Trigger Mode
Trigger Source: ITR1
Channel1: PWM Generation CH1
Channel2, 3, 4: Disabled
The code is simple:
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // 1st output signal
HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2); // phase shift value
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); // 2nd output signal
When hardcoded everything works great and I get a phase shift between signals. See the attached image.
But to change it I have to reflash the MCU as I can't get it changed dynamically.
I tried this in a while loop, but it didn't help:
1) TIM2->CCR2 = new_value;
2) stop all timers, set new value of phase shift and restart timers;
3) __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, new_value);
How to do this correctly?
