EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: fedimakni on July 15, 2025, 04:37:17 am

Title: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 04:37:17 am
Hello,

I am using a raspberry pi to control 2 BLDC motors.
I need to generate 12 PWM signals to control all the gate drivers which they control the mosfets.

I was thinking if there is an IC which you can control through SPI and then it outputs PWM signals but i couldn't find that.

Could you share if there is any solution for that?

Thank you.

Note:
BLDC drivers operate with 7S battery
Gate drivers are powered through 12V
I can remove the gate drivers if there is another solution that can control the mosfet directly
I can't rely on PWM through SW because of the higher resources usage and the inconveniences they have so a hardware PWM is preffered
Raspberry Pi 4 has only 2 HW PWM pins
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: Psi on July 15, 2025, 04:48:48 am
12 is quite a few fast PWM channels for one IC. They probably exist but might not be very cost effective verses using 2 chips

What frequency pwm are you driving the fets at? This is a key parameter as BLDC motor fets can be driven very fast in racing drones or at a much more normal speed for an electric drill. etc..
If you need super fast PWM control, consider that you need an input signal at least 12x faster.

For super fast control you'd normally use a MCU with 12 pwm outputs.

A lot of the ICs that take SPI/i2c and output N programmable PWM channels are intended for LEDs or servos, and max out around 2khz.
You probably need 10khz-100khz for BLDC motor control.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: Paradroid on July 15, 2025, 05:17:45 am
You should look at the PIO state machines of the RPi Pico. These can be programmed to control several IO pins from a single state machine, which should be ideal for BLDC motors where you don't need 3 independendent PWMs, but synchronized PWMs (fixed phase shift). Depending on the complexity of software that you've planned to run on the RPi 4, you may be able to eliminate that board completely, as the RP2040 and RP2350 MCUs are quite powerful.

Jens
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 05:24:29 am
Paradroid
Thank you for your reply, but i am using RPi 4 not the pico as i mentioned in my post

Psi
Yes you are right i need around 20-40KHz frequency to drive it so most of the LED drivers are not suitable.
I was thinking about using a separate ESP32 but i am trying to minimize the usage of external uC other than the RPi 4
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 06:17:45 am
DashApple

I was thinking about that too, but fixed frequency seems to be a little problematic
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: langwadt on July 15, 2025, 08:25:08 am
using an rpi4 to directly control BLDC motors makes no sense, it is like using a chainsaw to do plastic surgery, it might have plenty of horsepower but it is completely unsuited for the job
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: Siwastaja on July 15, 2025, 08:42:48 am
You need to build a motor controller. Motor controller is not 6 PWM signals driving gates.

Plenty of examples and literature on designing and building a BLDC controller. A cheap microcontroller will suffice for the driving logic. You can then use e.g. UART to communicate with the Raspberry Pi. Or SPI or I2C if they feel better to you.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 08:56:18 am
langwadt

I didn't get your comment !

If you mean the RPi4 is too powerful for that. you missed the point that i didn't say that the project is going to be ONLY controlling the motors.
I just need to provide relevant details no need to say that i have LIDAR or IMU or screen or ....
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 08:58:47 am
Siwastaja
I know how to control BLDC motors this is not something new to me.
The only difference is that i used STM32 or ESP32 in the past which has multiple PWM pins, but now i need to use RPi so that's why i am asking.
If you have any idea regarding my question so let's discuss that.
Thank you.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: langwadt on July 15, 2025, 09:20:06 am
Siwastaja
I know how to control BLDC motors this is not something new to me.
The only difference is that i used STM32 or ESP32 in the past which has multiple PWM pins, but now i need to use RPi so that's why i am asking.
If you have any idea regarding my question so let's discuss that.
Thank you.

if you think an rpi4 is suited for the job and all you need to figure out is how to generate 12 pwms, I doubt you know how a BLDC controller works
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: Siwastaja on July 15, 2025, 09:22:06 am
I know how to control BLDC motors

No, you clearly don't.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 09:23:37 am
Siwastaja
HHHH So you know better than me, if i did that or not??

So enlighten me with your experience, what i don't know please
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 09:25:53 am
langwadt
Do you have proper answer instead of trying to be funny or mocking?
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 09:29:10 am
langwadt

Why you think RPi is not suitable for the job?
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: PCB.Wiz on July 15, 2025, 09:43:42 am
I can remove the gate drivers if there is another solution that can control the mosfet directly
You have not given the motor specs, but there are parts like TI"s DRV8311 that includes MOSFETS and controls the motor directly, with a variant that has inbuilt SPI with dead time managed inside the IC.
They say up to 200kHz PWM.
Other variants accept a single PWM per motor, and use a state engine and hall effects for motor control.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: fedimakni on July 15, 2025, 09:48:47 am
PCB.Wiz

Thank you for your message,
I was really thinking about that.
My motor is simply around 15A current and powered by 7S battery (as specified)
DRV8311 seems to be not suitable as the Absolut max voltage is 24V

I was thinking of discrete solution with external mosfets and gate drivers as that can provide flexibility and control over heat if the mosfets are external.

Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: langwadt on July 15, 2025, 09:59:33 am
langwadt

Why you think RPi is not suitable for the job?


you need hard realtime performance with reponse times and lantencies in microseconds not milliseconds, that's not a job for an rpi4
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: Psi on July 15, 2025, 10:06:49 am
Siwastaja
I know how to control BLDC motors this is not something new to me.
The only difference is that i used STM32 or ESP32 in the past which has multiple PWM pins, but now i need to use RPi so that's why i am asking.
If you have any idea regarding my question so let's discuss that.
Thank you.

if you think an rpi4 is suited for the job and all you need to figure out is how to generate 12 pwms, I doubt you know how a BLDC controller works

Not everything is about making a professional product.
Sometimes it's just good to build random shit you're interested in, even if it's not the best way to do it, you learn a lot.

I try not to discourage people from building stuff.
Title: Re: Generate 12PWM signals from Raspberry Pi 4
Post by: kloetpatra on July 15, 2025, 10:12:52 am
yes rpi4 is not suited for the job: