Control Large Gearm...
 
Notifications
Clear all

Control Large Gearmotors with PWM & Arduino

20 Posts
7 Users
0 Reactions
10.9 K Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 7 years ago
Posts: 1186
Topic starter  

Pulse Width Modulation (PWM) is the ideal method of controlling large DC gearmotors, but driving these motors can often be challenging and expensive. Today I will show you an inexpensive and efficient H-Bridge motor controller - the Cytron MD10C.

I’ll also show you how raising the PWM frequency can make your motor controller design far more efficient.

Article with code: https://dbot.ws/dcpwm

We have used PWM to control small DC motors many times but what happens when you need to control a bigger motor? The L298N is the usual “go-to” motor controller but it doesn’t have the current capability to handle anything that draws over 3.5 amperes., so it won’t work with large motors.

Most large H-Bridge controllers are expensive, many cost as much or even more than the motor they are driving. But there are a few inexpensive options, and I’ve got a great one for you today.

The Cytron MD10C is a single-motor H-Bridge controller that can support motors that draw up to 13 amperes continuous, with peaks of up to 30 amperes! Amazingly this device is not only cheap, it also is so efficient that it doesn’t even require a heatsink to source those impressive current levels.

It is a very easy controller to use with an Arduino. I’ll show you how to hook it up as well as how to code for it. But it doesn’t stop there.

We’ll put our motor controller to the test and observe its performance. I will then “fine-tune” it to run a LOT more efficiently, and I’ll demonstrate its capabilities by driving a 10 Kg (22 lb) weight around the room!

We’ll then look at an improved Arduino design to control our DC gearmotors.

Here what we will cover in today's video:

00:00 - Introduction
03:04 - H-Bridge Design
04:57 - Cytron MD10C
08:03 - Arduino PWM Sketch
13:57 - Arduino PWM Test
18:25 - High Frequency PWM Test
23:11 - First Load Test
26:13 - Arduino High Frequency PWM Sketch & Test


"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Quote
codecage
(@codecage)
Member Admin
Joined: 7 years ago
Posts: 1065
 

@dronebot-workshop

What am I missing?

On line 23 in the "pwm_motortest.ino" file and on line 26 in the "pwm_motortest_hi.ino" file you define the Analog pin "diy_pwm" as A2.  I thought this was A0.  Or is it somehow modified by the library for LCD_Key?


SteveG, a.k.a. CodeCage


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 7 years ago
Posts: 1065
 

I think the "diy_pwm" define statement is an artifact from the Cytron code you said you had to modify to get the code to run.  I have eliminated that code and it seems to compile and upload just fine.  Haven't connected it to my Cytron motor drivers yet, but it appears that that define statement can be safely deleted.

But the display changes its DIR variable on pressing the "left" button and the PWM variable goes "up" and "down" when the appropriate button is depressed.


SteveG, a.k.a. CodeCage


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 7 years ago
Posts: 1065
 

@dronebot-workshop

The analog pin used on the LCD Keypad is actually A0 and not A2.  It is actually defined via the LCD_Key library and not in the pwm_motortest.ino or the pwm_motortest_hi.ino sketches.


SteveG, a.k.a. CodeCage


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 7 years ago
Posts: 1065
 

@dronebot-workshop

In trying to help a fellow forum member, I have recreated your demo and have things working even with the item I have identified above.  I now would like to hook my scope up to see the two traces you were showing.

My question is exactly where did you connect the two traces of your scope?  I'm assuming the first probe was directly from the PWM signal come from digital pin 3 on the Arduino, but I'm having trouble figuring out where the second scope probe is connected,


SteveG, a.k.a. CodeCage


   
ReplyQuote
(@mrclassicman)
Member
Joined: 5 years ago
Posts: 20
 

I was going to do the same thing! From his video it seems he goes directly to the output of the MC10 driver board. This would show the PWM signal going to the motors. 

 

Terry



   
ReplyQuote
(@daveszy)
Member
Joined: 3 years ago
Posts: 2
 

@codecage instead of "diy_pwm" what is its name?



   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 7 years ago
Posts: 1065
 

@daveszy 

From my statement above I just eliminated that define statement, so there was "no other name" assigned.  It has been sometime since all this was fresh in my mind, so the details are a little sketchy.


SteveG, a.k.a. CodeCage


   
ReplyQuote
(@daveszy)
Member
Joined: 3 years ago
Posts: 2
 

@codecage thanks



   
ReplyQuote
(@t1jump)
Member
Joined: 1 year ago
Posts: 4
 
I'm looking for some clarification on the lesson about Controlling Large Gearmotors with PWM and changing the Arduino PWM frequency. I have a motor controller that requires a PWM range from 1000us to 2000us. The servo.h library outputs this range, so is there some issue with using servo.h to control larger motors?
 
Is there some other reason to set the PWM frequency as shown in the lesson (i.e. set to 3000 in the tutorial, or is this something different)?
 
 
Thank you,
T1Jump


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 502
 

@t1jump 

Posted by: @t1jump

I'm looking for some clarification on the lesson about Controlling Large Gearmotors with PWM and changing the Arduino PWM frequency.

Which video/article are you referring to?

 


The one who has the most fun, wins!


   
ReplyQuote
(@t1jump)
Member
Joined: 1 year ago
Posts: 4
 

@tfmccarthy The video at the top of this discussion (



   
ReplyQuote
(@davee)
Member
Joined: 5 years ago
Posts: 2042
 

Hi @t1jump,

   I presume the article you are referring to is https://dronebotworkshop.com/dc-gearmotors-pwm/

   I haven't followed this article closely, but at first glance, this article appears to discuss the effect of changing the PWM frequency. Others may wish to contribute some practical experience.

PWM is often used to control the amount of power applied to a device, such as a motor or the inductor of a coil in a switch-mode power supply. Grossly oversimplifying the principle, the amount of power supplied is controlled by rapidly switching between an 'on' state, when full power is connected to the device, and an 'off' state, when no power is applied. Changes in power applied are achieved by changing the ratio of the time that the switch is 'on', to that when it is 'off'.

For example, when the switch is repeatedly 'off' for 1 millisecond, and 'on' for 3 milliseconds, then the average amount of power would be 75% of the power delivered when it was continuously 'on'.

The idea being that if the switch has two states, 'on' when it carries full current without inserting any resistance into the circuit, and 'off' when no current flows, then the switch will never dissipate any heat.

----

In some cases, this basic idea is close to reality, but when the device receiving power is an inductor, such as the coil of a motor, the situation becomes rather more complicated, albeit the wise electronics designer can often put the inductance property to their advantage. The effect of the inductance is to oppose changes of current, such that when the switch is changed from 'off' to 'on', the current 'slowly' increases from zero to maximum, and when the switch is subsequently changed back to 'off', then the current continues to flow, the quantity 'slowly' decaying back to zero. Note that the time-scale associated with 'slow' depends upon the size of the inductance, so this description needs some basic mathematics, etc. to explain it properly, which is beyond the scope of this reply. 

However, the interesting point is that by switching at a time scale that is chosen for the inductor, then it is theoretically possible to use the 'slow' part of the current changes to control the current flow, without converting any of the power flow into heat, as would be the case if a resistor was used to control the current.

---

In practice, most coils are made of metals like copper, which exhibit a low but appreciable resistance, which will cause some power loss, but usually much less than using an appropriate resistor.

--

Following the over simplified train of thought, the larger the inductance, the 'slower' the current changes will be. And a larger inductance, implies more turns of wire in the coil, which implies a longer wire, and more (unwanted) wire resistance. So a small inductor is often desirable. (In the case of the motor, the strength of the magnetic field depends upon the number of wire turns in the coil, so the designer must meet even more constraints, but let's forget that for a moment.)

However, a small inductor implies switching between 'on' and 'off' at a higher frequency. And the switch is usually a transistor, whose losses and 'problems' increase with switching (PWM) frequency. Different transistors can have widely different characteristics, so the designer must consult the data sheets to understand the limitations of each particular device.

The above text has referred to a single switch, whilst many such 'switches' are often packaged into integrated circuits designed for specific purposes such as motor controllers and power supplies, but the general process is unchanged, with the designer relying on the data sheets for guidance.

Hence, the designer must balance the optimum characteristics of the capability of the switch, the properties of the motor or other device receiving the power and so on. In some cases, it is possible to follow a well-tested and documented design, whilst in others a mixture of theory and practical tests may be required to determine an optimal product. (Competent switch-mode power supply designers can often demand a premium salary for a reason!)

---------------

 So, your 'Is it possible/advisable to use a different PWM frequency?' type of question depends upon both the motor and the controller. I am sorry, I cannot give you a simple answer. I hope you can now begin to appreciate the reason.

If you specify your exact set-up, then it is possible another forum member will have the same equipment, and may be able to provide some specific experience. However, in general, you may have to rely on the relevant data sheets, and some experiments, to find out for yourself, perhaps using Bill (@dronebot-workshop)'s article that you referenced as a starting point.

Good luck and best wishes, Dave



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 502
 

@t1jump 

Ah! Right you are! If I had just looked up...

I'm such a genius.

Sorry 'bout that.

Now I'm on the same page.

 


The one who has the most fun, wins!


   
ReplyQuote
(@t1jump)
Member
Joined: 1 year ago
Posts: 4
 

Hi Dave,

Thanks for the dive into PWM, and this further sets me to think there must be something different between the PWM "power" pulses and the PWM "control" pulses. When a servo motor (or other motor controllers) state they need a PWM signal between 1000us and 2000us, (1000us = full CCW and 2000us = full CW with 1500us as stop/brake) to control motor speed and direction, this must be different than the PWM discussed in the above video? I've always controlled gear motors with the standard servo PWM range so I'm guessing the "power" PWM range is handled by the motor controller?

Here is an example of a BLDC and motor controller to add some specifics to this discussion:

Rev Robotics Neo Vortex Motor ( https://www.revrobotics.com/rev-21-1652/)
Rev Robotics Smart Flex Motor Controller ( https://www.revrobotics.com/rev-11-2159/)

 

Thanks,

T1Jump 



   
ReplyQuote
Page 1 / 2