Author Topic: Generate 12PWM signals from Raspberry Pi 4  (Read 711 times)

0 Members and 1 Guest are viewing this topic.

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Generate 12PWM signals from Raspberry Pi 4
« 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
 

Online Psi

  • Super Contributor
  • ***
  • Posts: 11324
  • Country: nz
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #1 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.
« Last Edit: July 15, 2025, 05:18:04 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Paradroid

  • Contributor
  • Posts: 19
  • Country: de
    • iComp website
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #2 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
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #3 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
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #4 on: July 15, 2025, 06:17:45 am »
DashApple

I was thinking about that too, but fixed frequency seems to be a little problematic
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 5398
  • Country: dk
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #5 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
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 10308
  • Country: fi
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #6 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.
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #7 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 ....
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #8 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.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 5398
  • Country: dk
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #9 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
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 10308
  • Country: fi
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #10 on: July 15, 2025, 09:22:06 am »
I know how to control BLDC motors

No, you clearly don't.
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #11 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
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #12 on: July 15, 2025, 09:25:53 am »
langwadt
Do you have proper answer instead of trying to be funny or mocking?
 

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #13 on: July 15, 2025, 09:29:10 am »
langwadt

Why you think RPi is not suitable for the job?
« Last Edit: July 15, 2025, 09:41:38 am by fedimakni »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 2816
  • Country: au
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #14 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.
 
The following users thanked this post: fedimakni

Offline fedimakniTopic starter

  • Regular Contributor
  • *
  • Posts: 97
  • Country: tn
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #15 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.

 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 5398
  • Country: dk
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #16 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
 
The following users thanked this post: Paradroid

Online Psi

  • Super Contributor
  • ***
  • Posts: 11324
  • Country: nz
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #17 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.
« Last Edit: July 15, 2025, 10:08:28 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 
The following users thanked this post: fedimakni

Offline kloetpatra

  • Regular Contributor
  • *
  • Posts: 85
  • Country: de
Re: Generate 12PWM signals from Raspberry Pi 4
« Reply #18 on: July 15, 2025, 10:12:52 am »
yes rpi4 is not suited for the job:
  • rpi4 has only 2 hardware PWM channels
  • OS does not guarantee real-time response: PWM updates and sensor feedback cannot be handled with consistent microsecond timing
  • PWM updates are not jitter-free
  • no shoot-through prevention / dead-time insertion between high/low side FETs
  • no center-aligned PWM
  • no synchronized feedback (no hardware trigger, no adc, no foc, no bemf)
  • no overcurrent protection
  • no fault shutdown
« Last Edit: July 15, 2025, 10:16:12 am by kloetpatra »
 
The following users thanked this post: fedimakni, Paradroid


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf