Trade-offs between programmable SoCs vs. dedicated MCUs in motor control - Embedded.com

Trade-offs between programmable SoCs vs. dedicated MCUs in motor control

Editor's note: This article explains the basics of motor controller design and then uses two case studies to evaluate the use of a programmable SoC versus a dedicated controller solution.

Control systems are important in today’s embedded and industrial applications ranging from small hand held devices to bulky mechanical machines. Most automatic control systems use negative feedback for controlling a physical parameter such as position, velocity, torque, voltage, current, intensity, etc.

The parameter to be controlled is sensed by transducers and fed back to the input for comparison with a reference value. Subtraction of the sampled output signal from that of the reference input is called negative feedback. The difference signal , called the 'error', is then amplified to drive the system (referred to as 'actuation' ) in such a manner that the output approaches the reference value.

In other words, the system is designed to minimize the error signal and so is a closed-loop control system. Electro-mechanical systems form the broadest sector among traditional control systems where motor control is a commonly-used application.

In general, a motor control system is classified into sub-systems such as speed, position, or direction control. Let us begin with a simple speed control system where we are applying a constant voltage (V) to the motor. Any motor, by default, rotates at a particular speed (x) for a particular supply voltage (V). If a load is applied to the motor for the same voltage (V), the motor may slow down to speed (y). Thus, we cannot control the motor’s speed or make the motor rotate at a constant speed irrespective of any external factors. This is an open loop system. Hence, we need a feedback mechanism that can sense the speed of the motor and compensate for those factors.

Click on image to enlarge.

Figure 1: Closed-loop system controlling the speed of a motor

Figure 1 shows a closed-loop motor control system. Here, the motion controller compares the signal obtained from the feedback system with the actual input given to obtain an error signal that is then amplified and applied to the motor. In this system, the Motion Controller and Amplifier blocks to feed the correction factor to the motor can be implemented by a mixed-signal controller and optical rotary encoders can be used as sensors, since the output signal from this component can be easily decoded through controllers. Further explanation on each of these system blocks is offered below.

DC and stepper motors
An electric motor converts electrical energy into mechanical energy. Some common motors used in various industries include:

DC Motor: The simplest DC motors use a coil winding on a shaft, with fixed permanent magnets (Figure 2 ). When a voltage (V) is applied to the coil, current (i) flows through it. Since there is an existing magnetic field (B), a force (F) acts on the coil (by Flemings Right Hand rule), which makes it rotate. As soon as the coil reaches one of the permanent magnet's poles, it experiences a repulsive force and moves toward the other pole. This involves continuous rotation whose speed is determined by the applied DC voltage.

Figure 2: Working of a DC motor

Stepper motor: A permanent magnet stepper motor consists of a permanent magnet rotor, coil windings, and magnetically conductive stators.
Energizing a coil winding creates an electromagnetic field with a north and south pole. The stator carries the magnetic field. The magnetic field can be altered by sequentially energizing or “stepping” the stator coils, and this generates rotary motion.

The working of a two-phase motor is illustrated in Figure 2 . In step 1, phase A of a two-phase stator is energized. This magnetically locks the rotor in the position shown, since unlike poles attract. In step 2, phase A is turned off and phase B is turned on, causing the rotor to rotate 90° clockwise. In step 3, phase B is turned on but with the polarity reversed from Step 1, causing another 90° rotation. In Step 4, phase A is turned off and phase B is turned on, with polarity reversed from Step2. Repeating this sequence causes the rotor to rotate clockwise in 90° steps.

In stepper motors, the speed at which the motor rotates is determined by the speed at which steps 1 to 4 are executed.

Figure 3: Working of a Stepper Motor

Rotary Encoders
The next part of the motor control system is a feedback sensor that can sense the status of a motor and feed it back to a controller. A rotary encoder is a simple electro-mechanical device that can produce suitable pulses for each step of rotation on its shaft. It can be classified into two types: absolute and incremental encoders.

Absolute Encoders:  Absolute encoders give a fixed output for each position of the motor shaft. For example, if the encoder can detect the position of the shaft at angles 0°(fixed), 45°, 90°, 135°, 180°, 225°, 270°, 315° (total 8 positions – 45° resolution), a 3-bit value is assigned to each position, say from 000 to 111.

Incremental Encoders: With an incremental encoder, only the relative position of the motor can be determined (i.e., only the direction and angle of rotation relative to the previous position). An incremental encoder gives out two signals, A and B, both which will have a default value when no rotation is made, say logic 0 or logic 1. When a small angle rotation on the shaft is made, both signals A and B transit to the other logic for a short duration and come back to the default value. For every such rotation, transitions occur in both the A and B signals. Depending on the direction of rotation, a transition in A leads to a transition in B or vice versa. Figure 4 shows A and B signals for both clockwise and counter-clockwise rotation.

Figure 4: Transitions in signals A and B

Rotary encoders can also be further classified depending on the operating principle used. They are:

Mechanical Encoders:  Transitions in signals A and B occur as they come into contact with metallic ground (logic 0), one after the other.

Magnetic Encoders: The rotor turns with the shaft and contains alternating and evenly spaced north and south poles around its circumference. A sensor detects these small shifts in the position and the direction of rotation, depending on the direction of flux lines.

Optical Encoders: The rays from a light-emitting diode pass through a disk that has transparent and opaque sections attached to the shaft. The rays are detected by two photo-detectors (sensors A and B) which then generate quad-phase pulses A and B.

Figure 5 shows a sample mechanical encoder.

Figure 5: Mechanical Rotary Encoder

Page 2 of 2

Speed measuring equipment: Tachometers are widely used formeasuring the rotational speed of a motor. The shaft of the motor isconnected to a tachometer that is similar to a DC generator (i.e., itproduces electrical energy from mechanical energy), outputting a DCvoltage proportional to the speed of rotation of the motor (Figure 6 ). The voltage generated from the tachometer is used for further processing.

Today,many designers are migrating towards rotary encoders as they generatedigital outputs for every rotation. They also do not degrade due to wearand tear like tachometers. Feeding the rotary encoder’s output to amicrocontroller provides a straightforward way to monitor and controlthe speed of a motor with a rotary encoder as a sensor.

Figure 6: Interfacing Rotary encoder with a DC motor

Motion Controller block:  Amotion controller is needed to compare the reference speed with theactual speed and feed the error signal back to the motor. Since theabove discussed rotary encoder returns two quadrature phase signals Aand B, we need to implement logic to decode these signals and sense thecurrent speed of the motor. By computing the difference between thesensed speed and the actual speed, we can feed a correction factor tothe motor so that it achieves the required speed. Since controlling thepower supply to a motor controls its rotational speed, the correctionfactor to be fed involves giving a suitable voltage correction to thegiven supply voltage.

Using a programmable SoC for motor control
Thefollowing sections describe this speed control application in detail,with the Cypress PSoC 3/5 used as the motion controller. Though manycontrollers may be used to perform this operation, the PSoC includes aflexible visual embedded design methodology that includes preconfigured,user-defined peripherals and hierarchical schematic entry. It alsoincludes high-precision programmable analog blocks including 12- to20-bit delta-sigma ADCs, a digital logic library, power management, andconnectivity resources useful for motor control applications.

Ifwe intend to decode the signals from the rotary encoder and do furtherprocessing, we typically have to use an interrupt routine in a normalmicrocontroller, which prevents other functions from being executed whenthis interrupt routine is being serviced.

With a programmableSoC device, the microcontroller has a separate digital block/hardwareblock that can decode these quad-phase signals (A and B) and store thecurrent count value (i.e., automatically increment and decrement).

Inthe feedback loop, if we interface the motor shaft (whose speed is tobe measured) with the shaft of a rotary encoder through motor adapters(this might load the motor), the encoder’s shaft will rotate at the samespeed as that of the motor. The outputs of these encoders can be fed tothe quadrature decoder module available in the PSoC 3/5 for furtherprocessing for a complete implementation of a typical motor controlsystem.

A sample motor control application
One of thecommon requirements for motor-related applications is “SpeedMeasurement”. As said earlier, the current count value can be stored inthe decoder module. Using this, we can measure the speed of the motor bymeasuring the count value for every minute, since speed of a motor isusually measured in rotations per minute.

For example, afterevery minute we can reset the count value or we can use the differencein counts for our calculation. Instead of waiting for a minute, thecount value can even be measured every second and then multiplied by 60,although this may not give as exact a value as can be obtained bymeasuring per minute. Therefore, the speed of the motor can becalculated as

Equation 1

Forinstance, let us assume that we need to maintain the speed of a steppermotor at 6000 rpm. Considering an open-loop system, we would just have acontroller outputting a square wave signal to the stepper motor torotate it in one direction at 6000 rpm. However, when we add a load tothe motor, the speed of the motor decreases below the actual value atwhich it should run. Hence, we cannot achieve the desired speed andthere is no way to adjust it.
In order to maintain the speed at aspecific value irrespective of changes in the motor load, we need tofollow the principle of a closed-loop system. To sense and feedback thecurrent rotating speed, we use a rotary encoder, as discussed earlier.Our choice of encoder depends upon the speed of rotation and the speedaccuracy needed. The signals from the rotary encoder are decoded usingthe Quad Decoder module available using the PSoC Creator tool.

Asuitable clock frequency is routed to the Quad Decoder module,depending on the maximum rotations of the motor per minute. For example,if the maximum rotational speed would be 9000 rpm, this translates to150 rotations per second. If the encoder gives 4 pulses (encodercharacteristic) for every complete rotation, then the clock frequencyneeded for the decoder module is 150*4*10=6 kHz (10 times as that of Aand B signals).

Since we need to track the count value everysecond, we can generate an interrupt every 1 second. In the interruptservice routine, we can capture the count register value and then clearit (i.e., for measuring the speed for the next second) and using Equation 1 the speed of the motor can be determined.

Two case studies: PSoC versus MCU implementation
The following two cases list the possible power sources for the DC motor and also the logic to control it.

Case 1: DC Motor is driven through a current buffer using the same PSoC 3/5.For example, if the specification of the DC motor is such that itconsumes 88 mA with 5 V supply at no load condition, we can interfacethe output of PSoC 3/5 with the DC motor through a current drivingcircuit, as shown in Figure 7 :

Figure 7: DC motor driven through PSoC

Whilea constant 5V DC supply is given, the motor rotates at its full speed(i.e. 9000 rpm) as per the example here. The optical rotary encoderrotates along with the motor at the same speed and the output of theencoder is measured using the decoder in the PSoC 3/5. Now themicrocontroller detects the speed to be 9000 rpm and compares it withthe needed value (i.e., 6000 rpm or 2/3 times the actual speed). Thecorrective response is -3000 rpm (i.e., -1/3 times the voltage currentlysupplied to the motor).

This voltage variation can implementedusing a PWM. By varying the duty cycle of PWM, the average voltage canbe varied. There is a drag-and-drop PWM module in PSoC Creator. Theclock frequency to feed to the PWM module depends on the speedresolution needed by the application.

Herethe Duty cycle required would be 2/3. Hence, the average output voltageof the PWM module per cycle would be 5*2/3 = 3.33 V. The output of thePWM module is supplied to the current driving circuit that is connectedto the DC motor. The DC motor now rotates at the desired speed of 6000rpm. The rotary encoder again senses the speed, detects 6000 rpm, andfeeds it back to the controller. Now the error factor is 0. The PWMmaintains its previous state, and the motor maintains its speed.

Supposethat a load is added to the motor, though the duty cycle is maintainedat 2/3, the speed of the motor comes down to say 5000 rpm. Now therotary encoder senses the speed and feeds it to PSoC 3/5. Now, the errorfactor is +1000 rpm (i.e) 1/9th of the original/ free-running speed.Therefore, the duty cycle of PWM is increased by a factor of 1/9(Current duty cycle = 2/3+1/9 =7/9). This factor is written to the PWMDigital block through firmware.

Case 2: DC Motor ispowered through an MCU. If the DC motor is powered through anothercontroller, then the PSoC controller can be used to feed the currentstatus of the motor to the other controller through an interface such asI2C. If the DC motor is powered through an external battery, it is easyto control its speed through the logic shown in Figure 8. The PWMoutput from PSoC can be fed to the switch which would switch on andswitch the supply to the motor with a certain duty cycle so that itmeets the same criteria as before.

Figure 8: DC motor powered through an external source (not PSoC)

Other Applications
Forother motor control applications such as position control, we can usean absolute rotary encoder, as it gives the current position of themotor. This output can again be fed back to the controller to find thedeviation from the actual signal and, by giving a pulse for a smallduration, make sure the motor reaches its target position.

Asha Ganesan earned her Bachelor’s degree in Electronics and Communication atCollege of Engineering Guindy. She is currently working as anApplications Engineer at Cypress Semiconductor. She is an expert in PSoC3 and PSoC 5 products and assists customers with their PSoC 3/5projects. Her email address is .

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.