LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > DC Motor Control Project

DC Motor Control Project

Level: Beginner
Hours to Complete: 2.5
Skills Required: Soldering, C Programming, Breadboarding, Familiarity with Xbee Modules
Submitted By: Miguel Rodriguez, Parallax Tech Support

This project introduces the topic of motor control with the help of two H-bridges onboard the Pololu MC33926 motor driver carrier board. You will be controlling them wirelessly through the aid of an XBee module. This application can be used in controlling two-wheeled robots, motorized pulley systems and automatic door control. For the purposes of this demonstration I use a two wheeled robot as my platform of choice, however this set up can be adapted to any application the requires motor control.

 

What’s Needed

  • (2)  Propeller Activity Boards (#32910)
  • (2) DC Gear Motor with Encoders (#28819)
  • (2) Xbee  RF communication Modules (#32404)
  • (1) Pololu MC33926 Motor Driver Carrier Board (#28820)
  • (1) 2 Axis Joystick (#27800)
  • Misc jumper wires

Assembling the Project Components

Building The Project

Before You Start:

Download the Code files and Schematic Images

The first step is to solder a row of pins onto the motor driver board. The Pololu MC33926 board comes with 25 breakaway male header pins. Breakaway 18 pins from the header and insert them into the pin slots on the driver board and solder them on. You can solder the remaining pins onto the board; however, they are optional for this application. (Make sure you wear your safety goggles.) Now solder the 3 terminal blocks on the opposite side of the board. The terminal block’s opening should be facing away from the board. (See image below.)

Now it’s time to build the joystick circuit on one of your Activity Boards. Click here to view the wiring diagram from the Propeller C Joystick tutorial and use it to build your “Joystick” circuit. To attach the XBee modules simply align their pins with the Activity Board ’s socket located over the SD card slot. The two angled edges of the XBee should be facing away from the Activity Board. (See image below.)

After attaching the XBees you will need to connect two jumper wires. One jumper connects the DO pin (Data Out) to pin 9 and the second jumper connects DI (Data In) to pin 8. Make sure that both Activity Boards have XBees installed, and jumpers connected to DO and DI as shown in the following image.

The next step is to connect the motor driver board to your second Activity Board. In this step it is wise to go slow since it’s easy to make a wiring mistake when making this many connections. Always make sure your board is disconnected from its power source before connecting any wiring. Use the legend below and schematic images included in the code download (at the top of the page) to guide you on each connection.
 

Legend:

  • AB = Activity Board
  • MC = Pololu MC33926Motor Driver Board

MOTOR 1:

  • MC Vin to AB Vin (Note: Vin is the pin near the top right corner of AB between P15 and P16)
  • MC GND to AB GND
  • MC VDD to AB 3.3V
  • MC M1IN2 to AB P5
  • MC M1IN1 to AB P4
  • MC(PWM)/M1D2 to AB 3.3V
  • MC(PWM)M1D1 to AB GND
  • MC EN to AB 3.3V
     
  • M1OUT1 to motor RED
  • M1OUT2 to motor BLACK

 

MOTOR 2 :

  • MC M2IN2 to AB P3
  • MC M2IN1 to AB P2
  • MC PWM M2D2 to 3.3V
  • MC PWM M2D1 to GND
     
  • M2OUT1 to motor RED
  • M2OUT2 to motor BLACK

For these connections, use the AB-Pololu-Schematic-05.jpg file in the code download zip.

Take one DC motor and connect M1OUT1 to its red input and M1OUT2 to its black input. Now take the second motor and connect M2OUT1 to its red input and M2OUT2 to the its black input.

Programming and Troubleshooting

Programming:

Now we’re ready to load each board with its corresponding code:

  1. Load the Joystick-C-code.side program onto the Activity Board with the Joystick circuit, then
  2. Load the XBeeMotor-C-code.side program onto the Activity Board hosting the Pololu board.

 

Check List & Troubleshooting:

  1. Double check your wiring one last time by going over the legend and cross checking it with the schematic.
  2. Verify both XBees are socketed in correctly with the angled edges facing away from the board.
  3. Make sure your XBee jumper wires are going from DO to pin 9 and DI to pin 8 on both boards.
  4. Turn both boards on and wait a few seconds for the XBees to initialize. The order in which you turn them on doesn’t matter.
  5. Move the Joystick forward, backward, left and right and verify that the DC motors move accordingly.

If your motors are spinning in the wrong direction:

  • You may have your leads reversed, try swapping the leads going into M2OUT2 and the lead going into M2OUT1 with each other. Do the same for M1OUT2 and M1OUT1.
  • It is also possible that you have each pair of wires going to the wrong motor entirely, in this case try swapping each pair of wires onto the opposite motor.
     

How the Motor Controller Parts Work

]

Activity Board (Joystick Circuit):

Here’s how it all works!

Lets start with the Activity Board featuring the joystick. The joystick module houses two potentiometers, one for each axis of motion. When you move the joystick in different directions you’re actually changing the the resistance of each potentiometer. When a voltage is placed at the modules input the output voltage will fluctuated anywhere from 0 V to 5 V depending on the position of the joystick/potentiometer. Each axis has its own output that feeds into the Activity Board’s analog-to-digital converter (ADC) through pins A2 and A3. This is where the data is digitalized or converter to 1’s and 0’s.
 

Activity Board (Motor Controller):

The Propeller on the second board outputs a PWM signal through P3 and P4, and these two pins are used to control the “forward” motion of the motors – including turning. Pins P2 and P5 are used to control the “reverse” motion of the same two motors. Each pin is associated with each motors direction. For example P3 drives the right motor in a forward direction and P4 drives the left motor in the forward direction. The same goes for P2 and P5 only they drive the right and left motors in reverse. Another way to look at it is P3 drives the right motor forward, P4 drives the left motor forward, P2 drives the right motor in reverse, and P5 drives the left motor in reverse.
 

XBee module:

Remember when you inserted the jumpers from P9 to DO and P8 to DI? This is where they become really important. The jumpers connect the Propeller’s pins to the XBee module, and once the analog data from the joystick is converted to 1’s and 0’s it is relayed to the XBee module by the Propeller IC chip using the jumpers on P9 and P8. At this point, the XBee module receives the data and wirelessly transmits it to the second XBee module.
 

Pololu MC33926 Board:

The Pololu board has two MC33926 H-bridges built onto its PCB. Each H-bridge controls the forward and backward motion of each motor. In order for a motor to go forward, two MOSFETs on opposite ends must be “turned on” creating a very specific path for current to pass. Current must output from one of the H-bridge’s MOSFETs and pass through the motor and into a second MOSFET that leads to ground.(See Hbridge_schematic-06.PNG schematic). When current passes through the motor in one direction, it spins the motor accordingly. When the opposite MOSFETs are “turned on” as show in the schematic, they allow current to pass in the opposite direction which leads to spinning the motor in the opposite direction. The MC33926 IC chip has a logic controller inside that helps determine the speed at which the motors spin, giving the PWM duty cycle.

To learn more on the topics discussed in this project, search: H-bridges, PWM, DC Motors, and XBee modules.

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/dc-motor-control-project/
Links