Project 16 – Driving two DC geared motors with MD10C by using SKPS

PROJECT 16

DRIVING TWO DC GEARED MOTOR WITH MD10C BY USING SKPS

Back to Project 15                                                                                                     Go to Project 17

———————————————————————————————————————————————————-

INTRODUCTION

———————————————————————————————————————————————————-

Enhanced 10Amp DC Motor Driver (MD10C) is an enhanced version of the MD10B which is designed to drive high current brushed DC motor up to 10A continuously. It offers several enhancements over the MD10B such as support for both locked-antiphase and sign-magnitude PWM signal as well as using full solid state components which result in faster response time and eliminate the wear and tear of the mechanical relay. Some example of application is used to drive motor for robot arms or smaller mobile robot part. In addition, by further interface with PS2 Controller Starter Kit (SKPS), we can control the motors with PS2 controller through Universal Asynchronous Receiver/Transmitter (UART) which will establish a serial communication between PIC and SKPS.

In this project, we will learn about how to drive two DC geared motor with MD10C by using SKPS. Thus, we will treat these two motors as the left wheel motor and right wheel motor. Therefore, we will use PS2 controller to control two DC motors in various type of movements such as move forward, move backward, rotate to left, rotate to right. In addition, we will use joystick to control these two motors in different movement with constant speed and variable speed. Meanwhile, we will use PIC16F887 in this tutorial for SK40C with LCD 2×16 to display some important messages when certain button of PS2 controller was pressed. In addition, the sample code that used for PIC16F877A will also be attached at the end of this tutorial.


———————————————————————————————————————————————————-

COMPONENT NEEDED

———————————————————————————————————————————————————-

SK40C1x ENHANCED 40 PINS PIC START-UP KIt (SK40C)
lcd280x373 1x LCD DISPLAY (2X16) – BLUE BACKLIGHT (DS-LCD-162A-B)
 MD10C(2)-280x3732x ENHANCED 10A DC MOTOR DRIVER (MD10C)
ps2-controller-starter-kit-3089-280x373 1x PS2 CONTROLLER STARTER KIT (SKPS)
dc-geared-motor-107-800x800 2x DC GEARED MOTOR (SPG30-300K)
Sony-PS2.jpg 1x PS2 CONTROLLER (PS-GP-1)
Jumper(male-male)MALE-TO-MALE JUMPER WIRES (WR-JW-MM65) 

 

4232-280x373 FEMALE-TO-FEMALE JUMPER WIRES (WR-JW-FF10)
lipo-rechargeable-battery-11-1v-2200mah-79-280x373 1x LIPO RECHARGEABLE BATTERY (LIP-11.1-2200)
adapter-12v-2a-3187-222x296 1x ADAPTER 12V 2A (AD-12-2)
pro-skit-4-in-1-screw-driver-set-2119-280x373 

1x SCREW DRIVER SET (TO-SD-803) 

 

  

———————————————————————————————————————————————————-

CONNECTION

———————————————————————————————————————————————————-

For the latest MD10C, it is compatible with both Sign-Magnitude PWM and Locked-Antiphase PWM mode. Meanwhile, the only differences between these two modes are its connection. For Sign-Magnitude PWM, we need to connect its PWM pin to PWM output port of PIC and then connect its DIR pin to digital output port of PIC. However, for Locked-Antiphase PWM mode, we need to set its DIR pin as logic HIGH and then connect its PWM pin to PWM output port of PIC.

Therefore, in the following, I will briefly explain the connection for these two modes in separate part:

MODE 1: SIGN-MAGNITUDE PWM

To operate in Sign-Magnitude PWM mode, we need to use two different control signals to control the speed and direction of the motor. Thus, in this mode, PWM pin is used to control the speed while DIR pin is used to control the direction of the DC motor. Meanwhile, to further interface with SKPS, we need to connect SKPS to SK40C for serial communication. For this, we need cross connect the RX and TX pin between SKPS and SK40C.

Please refer to the connection diagram below:

Figure 1: Full connection diagram in Fritzing for Sign-magnitude PWM mode 

The following tables show the summary of the connection for sign-magnitude mode:

MD10C Terminal pinsConnection Descriptions
POWER (+)Connected to positive terminal of the 12V battery
POWER (-)Connected to negative terminal of the 12V battery
MOTOR Output AConnected to motor terminal A
MOTOR Output BConnected to motor terminal B

Table 1: Connection for MD10C terminal pins

*Note: Please ensure that the polarity of the 12V battery is correctly connected to MD10C to prevent permanent damage.

SK40C (PIC16F887)MD10C (Left motor)MD10C (Right motor)SKPS
VDD (+5V)5V
GNDGNDGNDGND
Vin (12V supply from power adapter)VINVIN
RC0DIR
RC1PWM
RC2PWM
RC3DIR
RC6 (TX)RX
RC7 (RX)TX

Table 2: Connection between SK40C-MD10C-SKPS

*Note: The field that mark with ‘-‘ is means that no connection needed.

MODE 2: LOCKED-ANTIPHASE PWM

To operate in Locked-Antiphase PWM mode, we need only single control signal to control both the speed and direction of the motor. Thus, in this mode, PWM pin is always connected to logic high while the DIR pin is connected to the PWM signal. Therefore, when the PWM signal has 50% duty cycle, the motor will stop. Meanwhile, if the PWM has less than 50% duty cycle, the motor will turn in one direction and turn in another direction if the PWM signal has more than 50% duty cycle. Furthermore, to further interface with SKPS, we need also connect SKPS to SK40C for serial communication as for Sign-Magnitude mode.

Please refer to the connection diagram below:

Figure 2: Full connection diagram in Fritzing for Locked-Antiphase PWM mode 

The following tables show the summary of the connection for locked-antiphase mode:

MD10C Terminal pinsConnection Descriptions
POWER (+)Connected to positive terminal of the 12V battery
POWER (-)Connected to negative terminal of the 12V battery
MOTOR Output AConnected to motor terminal A
MOTOR Output BConnected to motor terminal B

Table 3: Connection for MD10C terminal pins

*Note: Please ensure that the polarity of the 12V battery is correctly connected to MD10C to prevent permanent damage.

SK40C (PIC16F887)MD10C (Left motor)MD10C (Right motor)SKPS
VDD (+5V)5V
GNDGNDGNDGND
Vin (12V supply from power adapter)VINVIN
RC0PWM
RC1DIR
RC2DIR
RC3PWM
RC6 (TX)RX
RC7 (RX)TX

Table 4: Connection between SK40C-MD10C-SKPS

*Notes: The field that mark with ‘-‘ is means that no connection needed.

 

———————————————————————————————————————————————————-

ADDITIONAL INFORMATIONS

———————————————————————————————————————————————————-

Some additional informations about MD10C have been discussed inside Project 10: Driving DC brush motor with MD10C. Please refer it from there. For further informations, please refer to MD10C User Manual.

Apart from that, some informations about SKPS have been discussed inside Project 15: Interface with SKPS. Please refer it from there. For further informations, please refer to SKPS User Manual.

 

———————————————————————————————————————————————————-

CODE OVERVIEW

———————————————————————————————————————————————————-

MODE 1: SIGN-MAGNITUDE PWM

For Sign-Magnitude PWM, the basic ideas of programming are to control the two signals to control the speed and direction. Referring to the connection description above, we connect PWM of MD10C to RC1 for right motor and RC2 for left motor so that we can control the speed by setting the duty cycle of the PWM because RC1 and RC2 are the ports that can function as PWM. Meanwhile, to control the direction of motor, we need to connect the DIR of MD10C to digital ports such as RC0 and RC3. Then, we control the direction by set it logic HIGH or LOW for different direction.  The following shows some descriptions of the sample code for PIC16F887:

1. Firstly, we need to include the important library and write the configuration words for PIC16F887. In the SK40C tutorial, it uses HI-TECH C Compiler V9.70, so I just write the configuration words for this version in the sample code as shown below:

2. Secondly, we need to define the ports name and also the SKPS protocol in the “system.h” file as shown below:

(i) Definition of oscillator frequency, UART, LCD and SK40C elements.

 

(ii) Definition of SKPS protocols

3. Thirdly, before we write the main program, we write first the important library file for LCD, UART, PWM and SKPS. Therefore, we just need to include it inside the main program so that we can easily call for it once we want to use it in the main program. 

*Note: Please download the completed sample code from the attachment on this project webpage to view these codes.

4. After that, we are ready to write the main program. In the sample code, it will start the program by initialize the microcontroller. Here is the sample code:

5. After that, we start to write main function to start the program with displaying the start-up message and then ask the user to press “START” to continue. Here is the sample code:

6.  Next, we write the program to run the motor in different type of movement. In the sample code, it has two parts which are control with constant speed and variable speed.

(a) Here is the sample code to drive two motors in constant speed with 4 types of movement (forward, backward, rotate to left, rotate to right) depend on motor terminal connection:

(b) Here is the sample code to drive two motors in variable speed with 4 types of movement in Sign-Magnitude mode:

i. Move forward (depend on motor terminal connection) by joystick

ii. Move backward (depend on motor terminal connection) by joystick

 

iii. Rotate to left (depend on motor terminal connection) by joystick

 

iv. Rotate to right (depend on motor terminal connection) by joystick

 

(c) Here is the sample code to stop the motor:

 

MODE 2: LOCKED-ANTIPHASE PWM

For Locked-Antiphase PWM, the basic ideas of programming is to control only single signal to control both the speed and direction. Referring to the connection description above, we connect DIR of MD10C to RC1 for right motor and RC2 for left motor so that we can control both the speed and direction by changing the duty cycle of PWM. Thus, the motor will stop at 50% duty cycle, run in one direction if less than 50% duty cycle and run in another direction if more than 50% duty cycle. Meanwhile, the PWM of both MD10C is always set as logic HIGH by programming. The sample code is similar to Sign-Magnitude mode, but only with some modification on pin name definition and movement algorithm as shown in the following descriptions:

1. Firstly, we follow Step 1 as for Sign-Magnitude mode to write the device configuration words.

2. Secondly, we need to modify the code of the definition of pin name from Sign-Magnitude PWM in certain segment as shown below. After that, we just follow the remaining code as for Sign-Magnitude mode.

3. Then, we continue to write the same code by following the Step 3 to Step 5 as for Sign-Magnitude mode.

4. Next, we will write the program to run the motor in different movement in this mode. In the sample code, it also has two parts which are control with constant speed and variable speed.

(a) Here is the sample code to drive two motors in constant speed with 4 types of movement (forward, backward, rotate to left, rotate to right) depend on motor terminal connection in Locked-Antiphase mode:

(b) Here is the sample code to drive two motors in variable speed with 4 types of movement in Locked-Antiphase mode:

i. Move forward (depend on motor terminal connection) by joystick:

ii. Move backward (depend on motor terminal connection) by joystick:

iii. Rotate to left (depend on motor terminal connection) by joystick

iv. Rotate to right (depend on motor terminal connection) by joystick

(c) Here is the sample code to stop the motor:

Back to Project 15                                                                                                    Go to Project 17

———————————————————————————————————————————————————-

ATTACHMENT

1. P16 User Manual.pdf
2. Project_16_code.zip

Buy

, , ,

Related Post

Controlling 10A DC Motor Driver Using Arduino Nano

Control and Monitor via SMS Part 2

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

PIC16F VS PIC18F:Analysis of PIC Mid-Range 8 bit family and Advanced 8-bits Family

6 thoughts on “Project 16 – Driving two DC geared motors with MD10C by using SKPS

  1. Hey! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the great work!

    Here is my weblog – Leesa

  2. Can I request for the MD10C Friztzing part? I don’t know how to design this in Fritzing Part Editor…Thanks…

  3. hello.. is it possible to change the MD10C to SC16A for servo control using this module? somebody can help me?

  4. Not directly because SC16A uses UART to communicate, while MD10C using digital output and PWM only. Modification of hardware and code is needed. Please do continue the discussion in our technical forum as we seldom check the comments section in tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *