PIC Microcontrollers Provide 2 Cost-Effective Methods for Brushed DC Motor Control

In controlling the speed of a brushed DC motor, there are two cost-effective methods using a PIC microcontroller: optical encoder and Back EMF.

Industrial Motion Controllers provide precise speed and accuracy for operating rotating machines with microcontrollers and speed algorithms. A variety of mechatronic applications ranging from power windows to desktop electric robotic arms require motor control. With a variety of DC motors on the market, the brushed DC motor requires less complicated electronic controls to operate. In controlling the speed of a brushed DC motor, there are two cost-effective methods using a PIC microcontroller: optical encoder and Back EMF.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Brushed DC Motors are used in variety of consumer, automotive, and industrial applications. They can vary in size and shape. (Source: Anaheim Automation)

Brushed DC Motor Construction

A brushed DC motor is an electric rotating machine that uses commutation, or the method of switching DC current through the various windings of the electromechanical part. The internal physical part that performs the commutation is a commutator. The commutator is a cylinder wrapped with multiple metal contact segments attached to the armature of the rotating machine. Brushes or soft carbon-based electrical contacts touch the commutator. The windings on the armature are attached to the multiple metal contact segments of the commutator. A brushed DC motor’s speed can be easily measured by an optical encoder and a PIC microcontroller.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Simple pictorial diagrams showing the construction of a typical commutator. The brushes are mounted on opposite sides of the commutator to prevent motor winding shorting. (Source: hyperphysics)

Measuring Motor Speed with an Optical Encoder

An optical encoder, along with a PIC microcontroller, provides a simple method of measuring a brushed DC motor’s speed. To accomplish this speed measurement function, a PIC microcontroller’s Capture Compare (CCP) and Pulse Width Modulation (PWM) modules can be used to an operate a brushed DC motor. The optical encoder or interrupter provides a high-speed digital signal (pulses) to a slotted disk allowing light to pass through it. The slotted disk is attached to the brushed DC motor’s shaft. The PIC microcontroller’s Timer1 module will measure the optical encoder’s feedback of serial pulses. With this serial digital signal, the brushed DC motor’s speed is determined by measuring the time between the optical encoder’s pulses.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

The optical encoder or interrupter is a tiny optoelectronic component capable of producing a series of digital pulses that can be read by a PIC Microcontroller. The slots on the disk interrupt the light based on brushed DC motor’s rotation. (Source: Don Wilcher)

Viewing these pulses can be accomplished by attaching an oscilloscope to the optical encoder’s output signal pin.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

An oscilloscope can easily be attached to pin 24 (RC5 port) of a PIC16F917 microcontroller to observe the digital pulses. (Source: Microchip)

Here’s a lab setup using the PICDEM Mechatronics Development board for viewing the digital signals produced by the optical encoder.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Viewing the optical encoder’s output pulses on an oscilloscope. (Source: Don Wilcher)

The oscilloscope measurement setup revealed the following serial pulses produced by the optical encoder sensor.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

The Vp (peak voltage) of the optical encoder displayed on the oscilloscope is 4.81V DC. (Source: Don Wilcher)

In addition to providing the jumpers, wiring, and circuit schematic diagrams, and the programmer, the PICDEM Mechatronics development board kit has the software for nine hands-on labs. The software is written in assembly language code and can easily be modified using Microchip’s MPLAB-X IDE tool. The assembly code for the optical encoder lab is quite extensive and well commented. The following assembly code subroutine operates the brushed DC motor. The brushed DC motor is operated by a power MOSFET half bridge circuit along with the two internal timing – signal modules.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Partial assembly code for operating the brushed DC motor. (Source: Microchip)

For the encoder’s pulses, the assembly code subroutine for accomplishing the measuring task is shown next.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Partial assembly code for measuring the brushed DC motor speed using the optical encoder. (Source: Microchip)

The potentiometer on the PICDEM Mechatronics development board provides an input control for adjusting the brushed DC motor’s speed. The smooth linear speed ramp-up is accomplished by the PIC16F917 microcontroller’s PWM module. The power MOSFET half bridge driver circuit operates the brushed DC motor efficiently and effectively using the PIC microcontroller’s PWM module.

Back EMF Method

Another method of speed measurement and control of a brushed DC motor is Back EMF (Electromotive Force). An electric generator operation is accomplished by turning a brushed DC motor’s shaft mechanically. A small voltage is present at the leads of the brushed DC motor. When a brushed DC motor is running and the sourcing voltage is removed for a brief amount of time, the voltage generated by the inertia will be proportional to its speed. This voltage is the Back EMF.

Back EMF is typically not as accurate as optical encoder feedback because of the motor’s mechanical construction and unregulated voltage. However, in many non-critical applications the accuracy doesn’t have to be very precise in speed measurement. Back EMF is more cost-effective than other speed feedback mechanism because of the low parts count which consist of a resistor and capacitor. The resistor and capacitor form a low pass filter which reduces the small voltage transients or electrical noise produced by the brushed DC motor’s commutator. The removal of this electrical transient is critical to the speed measurement made by the microcontroller.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Back EMF low pass filter consists of R32 and C36 components located on the PICDEM Mechatronics development board. (Source: Don Wilcher)

The circuit schematic diagram looks quite similar to optical encoder design with the exception of the low pass filter wired to pin 7 (port AN4) of the PIC16F917 microcontroller.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

The speed is measured by the brushed DC motor’s Back EMF voltage. The signal is applied to pin 7 (port AN4) of the PIC16F917 microcontroller through a low pass filter (R32 and C36). (Source: Microchip)

The measurement setup has a slight change where the oscilloscope is attached to the Back EMF pin on the PICDEM development board instead of the Optical Interrupter test point. The Back EMF waveform shows a small switching time-off period of the motor’s commutator.

DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

The small switching time-off period of the brushed DC motor’s commutator: Back EMF waveform. (Source: Don Wilcher)

The assembly code for measuring the Back EMF provides the following sequence measurement events for the brushed DC motor:

  • Setup the LCD Special Function Registers
  • Turn on the P-channel power MOSFET
  • Start speed measurement loop: cycle through loop every 32ms
  • Track time intervals gone by within speed measurement loop
  • Read the Back EMF voltage
  • Adjust the brushed DC motor speed based on the potentiometer’s (POT1) setting
  • Display the brushed DC motor’s speed on the LCD every 1.048 seconds
DC motor, Brushed DC Motor, PIC, microcontroller, ESC, Embedded Systems Conference, DC

Assembly code subroutine for measuring the brushed DC motor speed using the Back EMF voltage. (Source: Microchip)

In looking at motor speed control operation, there are no noticeable differences. Comparing the two signal waveforms, the optical encoder method provides a clean approach to measuring brushed DC motor speed. Additional information on brushed DC motors, reference designs, and development kits may be found on Microchip’s Motor Control and Drive website.

Don Wilcher is a passionate teacher of electronics technology and an electrical engineer with 26 years of industrial experience. He’s worked on industrial robotics systems, automotive electronic modules/systems, and embedded wireless controls for small consumer appliances. He’s also a book author, writing DIY project books on electronics and robotics technologies.

 

Comments (0)

Please log in or register to post comments.
By submitting this form, you accept the Mollom privacy policy.
  • Oldest First
  • Newest First
Loading Comments...