PCA9685 with MD10c R3 and raspberry PI

Hi,

I want to use the i2c pwm module PCA9685 to drive 4 motors with 4 MD10c R3 pwm HBridge motor drivers.

The motors are the RB-CYT-177 cytron power window motors with 5" wheels

When I do the connections and run the python file,

the motors act weird. (running fast or slow even when I send out 0PWM, depending on the frequenty divider)

I think the adafruit_PCA9685 library is only for “real” servo motors. My motors are just regular motors.

How can I make the PCA9685 pcb work as a normal PWM signal generator instead of PWM for servo ?

my simple code is :

import Adafruit_PCA9685
import time

pwm = Adafruit_PCA9685.PCA9685()

pwm.set_pwm_freq(60)

while True:
print(“Run :”)
pwm.set_pwm(0,4096,0)
time.sleep(10)
print(“Stop :”)
pwm.set_pwm(0,0,4096)
time.sleep(10)

Depending on the values, the motor accelerates, decelerate or pauses, even when it should be in stop. … I do not see a pattern in it. The I2C itself I consider it works because I see the motor behaves different when using other values.
My power supply is very heavy, it can deliver 15A 13.5V continuesly so that is not the issue.

Any advice or help would be really apricated.

Thanks,

Hello @Doebi and welcome to the RobotShop community,

Servo control is not the same as DC motor control because the PWM signal for servos is different from regular PWM. Servo PWM is used to control the position of a servo and regular PWM is used to control the speed of a DC motor.

Frequency/period are specific to controlling a specific servo. A typical servo motor expects to be updated every 20 ms with a pulse between 1 ms and 2 ms, or in other words, between a 5 and 10% duty cycle on a 50 Hz waveform. With a 1.5 ms pulse, the servo motor will be at the natural 90 degree position. With a 1 ms pulse, the servo will be at the 0 degree position, and with a 2 ms pulse, the servo will be at 180 degrees.

image
https://www.jameco.com/Jameco/workshop/Howitworks/how-servo-motors-work.html

Now, for DC motors the dudty cycle varies the speed of the motor.

The frequency of the signals is also different, servo PWM has a relatively low frequency (40-200 Hz) while regular PWM (for DC motors) should be around 16kHz to 20kHz

In short, you shouldn’t control a DC motor with something designed to produce a hobby servo signal.

My power supply is very heavy, it can deliver 15A 13.5V continuesly so that is not the issue.

Keep in mind that what really matters is how much current your controller can withstand, the PCA9685 max current per pin is 25mA and while your motors are rated <15A@12V and have a stall current of <28A@12V.

The solution is to use the right controller for your motors. The product page lists some great options:

  • For Arduino lovers, you can utilize 10A shield to drive this motor.
  • For normal control, try MD10C (single channel) or MDD10A (dual channels).
  • For RC (Radio Control) lovers, check out the MDDS10 , smart drive dual-channel .

Hi geraldinebc15,
Thanks for your answer.
I understand now there’s a difference between the pwm for servo and for DC motors
The motordrivers I have are in fact 4x the MD10C.
What I don’t seem to find is a I2C board that can deliver up to 8 PWM signals, suitable for DC motor controllers (like you stated around 16khz to 20khz). I would like to have that in 1 pcb.
Unsure how to find out this kind of I2C expansion board.
Of course I could use a arduino an program it as dedicated slave but I would love to keep my project with only 1 mcu to program and that’s my pi 4.

So if you could help me sort out what extension board is suitable, let me know, would be appriciated.

Thanks

The motordrivers I have are in fact 4x the MD10C.

Oh, sorry I missed that.

What I don’t seem to find is a I2C board that can deliver up to 8 PWM signals, suitable for DC motor controllers

Note that the PWM signal needed is not RC PWM (servo PWM)

My power supply is very heavy, it can deliver 15A 13.5V continuesly so that is not the issue.

Keep in mind that as the motor controller you have is regenerative so if you have a switching power supply it will shut down when regenerative current from motor is detected so it is recommended to use a battery. Or, as suggested by the manufacturer if using a switching power supply is needed, you should connect in parallel a battery with the same rated voltage to absorb the regenerative current.

Do you need to control the motors independently?

If not you could use a dual-channel motor controller and connect two and two in parallel.

If you need to control them independently, and since you were already considering using an external PWM signal generator I would suggest simply using two motor controllers.

Hi, thanks for the answer.

The more I read, the more I’m getting confused about it. Maybe it’s because of the language (I speak dutch). My bad

Do you need to control the motors independently?

Yes, for the moment I want 4 motors to run independently,
but I plan to have up to 8 motors in total.

Well as far as I can see I need to deliver a PWM to the MD 10C R3
The MD 10C R3 has 3 logic pins : GrouND, DIRection, PulsWidhModulation.
So I want to have PWM board to do this for me.
The pi 4 itself can in my knowledge not manage this on it’s own board. That’s why
I want to make the job done with an I2C PWM board with 8 or more PWM.

If you need to control them independently, and since you were already considering using an external PWM signal generator I would suggest simply using two motor controllers.

Well, I want to control them independently, for the moment 4 motors actualy, and I do have 4 MD 10C R3 boards.

So what I try to figure out, from the first answer I’ve got : what I2C PWM board can be used by the raspberry pi 4 to pwm feed my 4 MD 10C R3 motor control boards

Thanks for your patience and suggestions.
Greetings

The more I read, the more I’m getting confused about it. Maybe it’s because of the language (I speak dutch). My bad

No worries, I explained myself poorly. I updated it so there are no misunderstandings.

Yes, for the moment I want 4 motors to run independently. but I plan to have up to 8 motors in total.

All 8 motors need to be controlled independently?

If that’s the case you should look for a DC motor controller with multiple channels. You currently have the MD10C which only has one channel but there are motor controllers that support two or four channels and it would be best if the controller accepts RC PWM so you can use the I2C PWM board you have, for example the Sabertooth or the MDDS10.

Well, I want to control them independently, for the moment 4 motors actualy, and I do have 4 MD 10C R3 boards.

Unfortunately, the MD 10C R3 boards do not support RC PWM.

You could try using this library:

To generate the PWM signals using the RPi but it is very limited.

You could also use the I2C PWM board you have to generate the signals (you would have to change the functions for your application) but the frequency is limited to 1.6 KHz which is not the best (16-20kHz is recommended).

Solved it by using a old arduino mega 2560 (I see current price around 30EUR),
reprogrammed its timer registers and now I have 13 channels PWM up 31372.55 Hz to and 2 channels PWM up to 62500 Hz , controlled by the RPi 4 using I2C.

Currently tested by 1 motor, running real smooth.
Next step is to use the same mega also for the direction signal needed by the MD10C R3 boards, pins enough. Does spare me pins on the RPi 4 for future expansion.

Thanks for the help

1 Like