2020-02-16 08:08 PM
Hello,
I have received conflicting answers to this question so I want to try asking it in a different way. Hopefully you understand my situation but please let me know if I should clarify anything.
I want to use an STM32G431RB. I need to be able to read 4 quadrature encoders and drive 9 PWM outputs.
In order to do this, I believe I need to use at least one timer running Encoder Mode on channels 1 & 2 and PWM Output on channels 3 & 4. Is that possible?
I currently have an STM32F3Discovery board for testing purposes and I have set up PWM generation on TIM2 channels 3 & 4 using STM32CubeIDE. When I measure the pins with an oscilloscope, I read the expected PWM. Then, I set TIM2 Combined Channels to Encoder Mode and, without adding anything else to my code, the oscilloscope shows that the pin is set to high (3V). Could something be off in my code? Is this expected? Is there a way to generate PWM with TIM2 CH3 and CH4 in this setup?
Thank you!
Solved! Go to Solution.
2020-02-16 11:21 PM
> In order to do this, I believe I need to use at least one timer running Encoder Mode on channels 1 & 2 and PWM Output on channels 3 & 4. Is that possible?
No, the hardware is not designed that way. One Timer == one counter register (plus 0 or more timer channels attached to it).
How to clock that counter register? For PWM you need a stable periodic clock to gererate a stable PWM, the internal or some external clock.
But, for Encoder Mode, the counter register is clocked by the encoder pulses. If there are no encoder pulses (e.g. wheel motors turned off), the counter stands still, no PWM.Quadrature Encoder Mode is a type of encoder mode where the counter register counts up or down depending on the input pattern (using CH1 and CH2 channel inputs)
If you cannot allocate all the resources in the proposed chip, you can
2020-02-16 11:21 PM
> In order to do this, I believe I need to use at least one timer running Encoder Mode on channels 1 & 2 and PWM Output on channels 3 & 4. Is that possible?
No, the hardware is not designed that way. One Timer == one counter register (plus 0 or more timer channels attached to it).
How to clock that counter register? For PWM you need a stable periodic clock to gererate a stable PWM, the internal or some external clock.
But, for Encoder Mode, the counter register is clocked by the encoder pulses. If there are no encoder pulses (e.g. wheel motors turned off), the counter stands still, no PWM.Quadrature Encoder Mode is a type of encoder mode where the counter register counts up or down depending on the input pattern (using CH1 and CH2 channel inputs)
If you cannot allocate all the resources in the proposed chip, you can
2020-02-17 01:03 AM
Don't forget about the LPTIM which can work in encoder mode too, freeing up a 4 channel regular timer for PWM generation.