Motor Control
Controlling motors using PWM signals
DC Motors
A direct current, or DC motor is the most common type of motor. DC motors normally have just two leads, one positive and one negative. If you connect these two leads directly to a battery, the motor will rotate. If you switch the leads, the motor will rotate in the opposite direction.
To control the direction of the spin of DC motor, without changing the way that the leads are connected, you can use a circuit called an H-Bridge. An H bridge is an electronic circuit that can drive the motor in both directions. H-bridges are used in many different applications and one of the most common being to control motors in robots. It is called an H-bridge because it uses four transistors connected in such a way that the schematic diagram looks like an "H."
In micro:Xbot we use a TB6612FNG motor controller which has four channels to control two DC motors. For a Four wheel drive robot, we can connect them in pairs where a single signal controls two motors.
The program below can be used to drive two motors and control their direction and speed. To test this program, connect two motors to the motor connectors on either side at the bottom of the board. Once the program is uploaded, the motors start to spin. Make sure they are held in place.
Motors require a lot of current to run. Before uploading the program, connect the battery to battery connector and slide the switch to turn on the board. Once this is done, connect FTDI connector and upload the program.
The above program runs motors in different directions and different speeds. After each run, the motors are stopped and the direction is changed. This is a good practice so that there is not too much stress on the motors. When motors are reversed, the shaft produces reverse mechanical energy and the motors winding get a reverse electrical energy. So, we are fighting the inertia of the system. This produces a large current spike and also reduces the life of the motor.
Though the board and the controller is stable enough to overcome these large spikes, its a good practice to either slow down or stop the motor before reversing.
Last updated