Hello! Is it possible to configure this library so that it can control 3 motors simultaneously? STM has many controllers with at least 18 PWM outputs. Or is it better to use 3 simpler controllers?
It’s possible on a fast MCU, but keep in mind each motor also needs a sensor, and if you’re using current sensing, 3 ADC inputs per motor…
So often the problem is finding a MCU that has enough pins in the right combinations to support all the inputs and outputs you need.
in particular on STM32 you have to check quite carefully which pins you use.
note also that at the moment we don’t support current sensing for multiple motors, you’d have to extend the code to support it.
Then there is also the issue of cabling multiple motors and sensors to a central board.
So in some ways it’s certainly easier to design controllers for a single motor and coordinate them using a master controller…
Are you thinking of trying to synchronize two different timers to give complementary output for one motor? Normally only TIM1 and TIM8 are used for 6PWM, because they each have complementary channels that run on the same timer so they’re guaranteed synchronized. And the 32-pin STM32G431KBUx can only use TIM1, because there’s no pin for TIM8_CH3 (terrible decision by the hardware designers). I’ve used it to control two motors with 3PWM, but have to use the 48-pin CBUx for two 6PWM. I wouldn’t recommend any more than that. One motor can update at about 18KHz in foc_current mode, so three would be 6KHz, which is a bit low. One of my earlier designs runs four motors with 3PWM on CBU6, but that’s only 4.5KHz so max RPM is limited.
Yes, I have managed to control 4 motors with closed loop. You need however a custom PCB design and the code is not trivial.
Cheers,
Valentine
PS Added bonus, here you can also see my cats, CheetoBenito and HexaDecimal.
I’d like to revive this thread with the same question as the original poster. I have been binging the information on this forum nonstop since I found it a few days ago, but I am still upside down on understanding the possibilities/limitations.
Controlling a stepper motor requires four PWM pins, correct? The STM32F405OE has 17 various timers, including four general-purpose timers which “all feature 4 independent
channels for input capture/output compare, PWM or one-pulse mode output. This gives
up to 16 input capture/output compare/PWMs” (page 34 of the data sheet), plus plenty of other inputs for the four sensors.
Valentine, I’ve read many of your posts, and since you had to build a custom PCB at great effort to handle four motors, I’m assuming there is something that prevented you from just using a $20 off-the-shelf board. Would you please explain what it is I’m missing here that makes controlling multiple motors such a challenge? Thank you for your time.
Hi @loudboy ,
it’s essentially two things:
- hardware resources - it’s true that the more powerful STM32 MCUs can have a lot of timers. Even so you have to check the pins actually available in the package you chose, not always all the timer channels are actually available on pins. Even when they are available they are often on pins also used for other things like SPI or ADC. And that’s the next issue - each motor not only requires PWM but also a position sensor and (depending on driver design) current sense. These also all require pins on the MCU, meaning that in the end there are usually many conflicts and it’s only the high pin count and powerful STM32s that realistically have the resources to control 3 or more motors…
- CPU resources: each motor needs a FOC loop and a move loop, and time to read sensors and sample ADCs. The ADC sampling in particular can get extremely complex with its dependencies to timers and adc hardware. So you have to code everything in an efficient and complicated way to make sure things happen in parallel in the hardware while the CPU is doing other calculations. Otherwise the performance of the MCUs isn’t sufficient to get you good control bandwidth and you run into problems.
The combination of these two things means it’s not at all simple to get it working. An experienced embedded developer, especially one who knows STM32 well can certainly take our library as a starting point and get it working on 3 or more motors on her (carefully) chosen MCU…
But it’s not something we can make as simple as running a single motor on a MCU… that’s already a challenge in many cases.
Number of timers and PWM capable pins is a small part, then as @runger noted the code management is very challenging, you can move at low speed but 4 motors stretch the MCU ability to process 4 pid loops in true real-time so you can move them slow, but not fast. Also no $20 board has the pins you want exposed, and also 3pwm vs 6pwm, no stm32 has 4 complementary pairs, so you are stuck with 3pm, which requires a custom setup. Also, how do you control the 4 motors? That’s extra hardware work and mcu overhead.
Best, try doing this yourself and see which hurdles you hit.
Cheers,
Valentine