Generating primary and complementary PWM using Advanced-control Timers for Motor Control

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
abraaoguia
Posts: 4
Joined: Fri Feb 05, 2021 9:07 pm

Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by abraaoguia » Tue Mar 09, 2021 5:07 pm

Hi,

My master thesis includes controlling a PMSM (Permanent Magnet Synchronous Machine) using a PyBoard. For this I need 6 PWM signals, to control a full 3-phase MOSFET bridge (3 primary PWM signals, and 3 complementary, all of them with deadtimes).

I've been reading a lot about the STM Timers, and from what I understand, Timers 1 and 8 are (each one) capable of doing this. That means that the PyBoard is capable of controlling 2 PMSM's. So I've decided to try to generate the 6 PWM signals using Timer 1.

But seems to be a problem with this. All the Channels that the PyBoard gives for Timer 1 (same for Timer 8) are complementary, none of them are primary. Here is the list of the Pins and Channels that the PyBoard v1.1 Timer 1 has (same Pins and Channels apply for Timer 8) http://micropython.org/resources/pybv11-pinout.jpg:
Timer 1: Pin X8(CH1N), Pin Y6(CH1N), Pin Y11(CH2N), Pin Y7(CH2N), Pin Y12(CH3N), Pin Y8(CH3N)

As we can see in page 517 of the STM's Reference Manual (https://www.st.com/en/microcontrollers- ... umentation), the Timer 1 generates: CH1, CH1N, CH2, CH2N, CH3 and CH3N (that are the 3 primary PWM signals and 3 complementary PWM signals that I need for controlling the motor).

How can I solve this problem? How can I access this primary PWM signals too?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by dhylands » Tue Mar 09, 2021 5:49 pm

You'll probably need to use a different board, like the STM32F4 Discovery: https://www.st.com/en/evaluation-tools/ ... overy.html which gives you access to many more of the peripheral pins.

abraaoguia
Posts: 4
Joined: Fri Feb 05, 2021 9:07 pm

Re: Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by abraaoguia » Wed Oct 06, 2021 2:44 pm

dhylands wrote:
Tue Mar 09, 2021 5:49 pm
You'll probably need to use a different board, like the STM32F4 Discovery: https://www.st.com/en/evaluation-tools/ ... overy.html which gives you access to many more of the peripheral pins.
Hi Mr. Hylands, thanks for the reply!

I came back to the project, and discovered that in fact the Pyboard V1.1 almost can generate the 6xPWM's, also including a 6us deadtime. Timer8 is the best option for this, reaching up to 5xPWMs.

Below are the list of ports and channels, with the used ones highlighted in bold:

Channel 1: Tim2(X1), Tim5(X1), Tim9(X3), Tim2(X6), Tim13(X7), Tim14(X8), Tim8(Y1), Tim10(Y3), Tim11(Y4), Tim12(Y7), Tim4(X9)
Channel 2: Tim2(X2), Tim5(X2), Tim9(X4), Tim13(X7), Tim8(Y2), Tim12(Y8), Tim4(X10)
Channel 3: Tim2(X3), Tim5(X3), Tim2(Y9), Tim4(Y3)
Channel 4: Tim2(X4), Tim5(X4), Tim2(Y10), Tim4(Y4)
Channel 1N: Tim8(X6), Tim1(X8), Tim8(X8), Tim1(Y6)
Channel 2N: Tim1(Y11), Tim8(Y11), Tim1(Y7), Tim8(Y7)
Channel 3N: Tim1(Y12), Tim8(Y12), Tim1(Y8), Tim8(Y8)

If only I could configure the pin Y3 (Channel3) to receive Timer 8 (instead of Timer 4), the Pyboard would be sufficient for motor control. Could this be done with software, or is it a hardware limitation?

Best Regards

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by dhylands » Wed Oct 06, 2021 6:14 pm

The timers available on a particular pin is a hardware limitation.

The STM32F407 datasheet: https://www.st.com/resource/en/datasheet/dm00037051.pdf starting on page 62 shows the functions available on each pin of the microcontroller. That same information should be reflected in the stm32f405_af.csv file. The actual functions available to micropython is the intersection of the pins.csv file and the stm32f405_af.csv file.

abraaoguia
Posts: 4
Joined: Fri Feb 05, 2021 9:07 pm

Re: Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by abraaoguia » Wed Oct 06, 2021 9:35 pm

dhylands wrote:
Wed Oct 06, 2021 6:14 pm
The timers available on a particular pin is a hardware limitation.

The STM32F407 datasheet: https://www.st.com/resource/en/datasheet/dm00037051.pdf starting on page 62 shows the functions available on each pin of the microcontroller. That same information should be reflected in the stm32f405_af.csv file. The actual functions available to micropython is the intersection of the pins.csv file and the stm32f405_af.csv file.
Thanks again for the reply!

Another option would be synchronizing Timer 4 with Timer 8. If it is possible, we could use the pins and channels of Timer 4, as Timer 8 signals.

Can that be done via software?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Generating primary and complementary PWM using Advanced-control Timers for Motor Control

Post by dhylands » Thu Oct 07, 2021 9:04 pm

What type of motor control are you trying to do? (i.e. driving servos?, DC motors via H-Bridge?, steppers?) What types of control signals do you need?

Some timers can be slaves to other timers, but I'm not sure that's exactly what you're looking for. See this document: https://www.st.com/resource/en/applicat ... ronics.pdf for an overview of what the timers can do.

Post Reply