Categories: Firmware Guide-PIC18

DC motor Interfacing with PIC Microcontroller

As the name implies DC motors are electrical machines which work under DC power. It converts electrical energy to mechanical energy. Because of several of its advantages including the high-speed control facilities, DC motors were universally used in myriad applications. Advancement in electronics has recently caused a shift from DC motors to AC powered motors. Even then, the DC motors are preferred in applications starting from toys to electric vehicles. In this chapter, dc motor interfacing with PIC microcontroller is described in detail.

DC Motor

DC motors are low cost electrical to mechanical converters used in applications. They are preferred over other motors including stepper motors because of their low cost and speed. The phenomenon called electromagnetism is the driving principle behind a DC motor. When a current carrying conductor is placed in the external magnetic field, it will experience a force proportional to the applied magnetic field.

A DC motor is a combination of a stator which contains stationary magnets and an armature which is an iron core with insulated wire wound around it. The strength of magnetic field developed in the system is determined by the amount of current sent to the coil, number of windings and nature of the material of the coil. In some DC machines, the stator uses electromagnets to improve control over the motor. The advent of power electronics has helped DC motors to improve its functions by maintaining an effective lower voltage.

Electrical Connections between stator and rotor: There are three such connections which are series, shunt and compound connections. In a series connection, the armature and field windings are connected in series with a dc power source. The initial torque in such case is always high and therefore such a connection is preferred in applications such as elevators and trains where the motor has to initiate high inertia loads. The shunt or parallel connection has good speed regulation capabilities but does not have the starting torque as produced by a serially connected motor. In a parallel connection, the field windings and the armature are connected in parallel with a dc supply. In applications where both high starting torque and good speed regulation is needed, the compound connection is used. As the name implies it incorporates shunt and serial connection of field and armature.

DC Motor Interfacing with PIC Microcontroller

DC motors need much more current than a microcontroller can provide, so it needs separate drivers. Different DC motors need different voltages and operating high voltage motor from a low voltage controller is not a feasible option. Following things should be taken into account while designing the circuit.

  • It should be able to handle high current, normally more than 250mA
  • Filter back emf for coil safety

We can select a power transistor for handling high current and a diode across the motor for solving back EMF problem. The diode will prevent current in reverse direction thus blocking back EMF.

DC motor interfacing circuit with PIC microcontroller

In this case, 12V is the Motor voltage, the power transistor can drive the motor with this specifications. D880, TIP121 are examples. This circuit will drive the Motor in one direction only and can be used to vary the speed using PWM.

Firmware

Here, the circuit is connected to RB0 pin of the microcontroller. We need to make this pin output mode.

TRISBbits.TRISB0 = 0;               // Set RB0 as output

Now, put it in HIGH mode whenever we need to run the motor

PORTBbits.RB0 = 1 ;                 // Turn ON the motor

H Bridge

In order to solve the inability to rotate in both directions, we use H drive. The name H bridge comes from the structure of the circuit. The shape of the circuit is like the letter H from English alphabets.

To rotate the motor, we need to close either S1 with S4 or S2 with S3. These will result in the rotation in two directions. Below is an actual circuit used for H bridge.

DC Motor H-drive circuit

When D is grounded and A is Vcc, transistors Q1 and Q4 will become ON and current passes through Motor from left to right. To pass current from right to left, B should be grounded and terminal C in Vcc. This will result in rotation of Motor in opposite direction.

Driver ICs

There are several Motor driver chips and any current driver with sufficient current output can be used for this purpose. But for using it in both directions, we need to use H-bridge driver IC like L293D. This IC can be used for rotating in either direction. An example circuit using L293D is below.

L293D DC motor driver circuit

 

Speed control of dc motor

The speed of DC motor is controlled by PWM (pulse width modulation) technique. The width of signals generated by the PWM varies, and these signals are used to drive the motors which in turn varies the speed based on the ON state.

Above image illustrates the variation of speed based on the width of the pulse. As the ON state of pulse elongates the speed of the motor increases. If the ON pulse is small, this decreases the ON time and motor speed decreases.

 

 

Share