Generate 12PWM signals from Raspberry Pi 4 - Page 1
Forum section: electronics / projects

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 04:37:17 am
content: 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 batteryGate drivers are powered through 12VI can remove the gate drivers if there is another solution that can control the mosfet directlyI can't rely on PWM through SW because of the higher resources usage and the inconveniences they have so a hardware PWM is prefferedRaspberry Pi 4 has only 2 HW PWM pins

author: Psi
author_rank: Super Contributor
timestamp: July 15, 2025, 04:48:48 am
content: 12 is quite a few fast PWM channels for one IC. They probably exist but might not be very cost effective verses using 2 chipsWhat 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.

author: Paradroid
author_rank: Contributor
timestamp: July 15, 2025, 05:17:45 am
content: 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

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 05:24:29 am
content: ParadroidThank you for your reply, but i am using RPi 4 not the pico as i mentioned in my postPsiYes 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

author: DashApple
author_rank: Contributor
timestamp: July 15, 2025, 05:40:23 am
content: Not sure if its of help but going with LED drivers There is the NXP PCA9955 That's a 16 channel LED driver with a fixed 31.25Khz PWM on each channel with a 0 % to 99.6 % Duty

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 06:17:45 am
content: DashAppleI was thinking about that too, but fixed frequency seems to be a little problematic

author: langwadt
author_rank: Super Contributor
timestamp: July 15, 2025, 08:25:08 am
content: 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

author: Siwastaja
author_rank: Super Contributor
timestamp: July 15, 2025, 08:42:48 am
content: You need to build a motor controller. Motor controller isnot6 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.

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 08:56:18 am
content: langwadtI 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 ....

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 08:58:47 am
content: SiwastajaI 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.

author: langwadt
author_rank: Super Contributor
timestamp: July 15, 2025, 09:20:06 am
content: Quote from: fedimakni on July 15, 2025, 08:58:47 amif 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

author: Siwastaja
author_rank: Super Contributor
timestamp: July 15, 2025, 09:22:06 am
content: Quote from: fedimakni on July 15, 2025, 08:58:47 amNo, you clearly don't.

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 09:23:37 am
content: SiwastajaHHHH So you know better than me, if i did that or not??So enlighten me with your experience, what i don't know please

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 09:25:53 am
content: langwadtDo you have proper answer instead of trying to be funny or mocking?

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 09:29:10 am
content: langwadtWhy you think RPi is not suitable for the job?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 15, 2025, 09:43:42 am
content: Quote from: fedimakni on July 15, 2025, 04:37:17 amYou 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.

author: fedimakni
author_rank: Regular Contributor
timestamp: July 15, 2025, 09:48:47 am
content: PCB.WizThank 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 24VI 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.

author: langwadt
author_rank: Super Contributor
timestamp: July 15, 2025, 09:59:33 am
content: Quote from: fedimakni on July 15, 2025, 09:29:10 amyou need hard realtime performance with reponse times and lantencies in microseconds not milliseconds, that's not a job for an rpi4

author: Psi
author_rank: Super Contributor
timestamp: July 15, 2025, 10:06:49 am
content: Quote from: langwadt on July 15, 2025, 09:20:06 amNot 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.

author: kloetpatra
author_rank: Regular Contributor
timestamp: July 15, 2025, 10:12:52 am
content: yes rpi4 is not suited for the job:rpi4 has only 2hardwarePWM channelsOS does not guarantee real-time response: PWM updates and sensor feedback cannot be handled with consistent microsecond timingPWM updates are not jitter-freeno shoot-through prevention / dead-time insertion between high/low side FETsno center-aligned PWMno synchronized feedback (no hardware trigger, no adc, no foc, no bemf)no overcurrent protectionno fault shutdown