Trade-offs between programmable SoCs vs. dedicated MCUs in motor controlPage 2 of 2
Speed measuring equipment: Tachometers are widely used for measuring the rotational speed of a motor. The shaft of the motor is connected to a tachometer that is similar to a DC generator (i.e., it produces electrical energy from mechanical energy), outputting a DC voltage 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 generate digital outputs for every rotation. They also do not degrade due to wear and tear like tachometers. Feeding the rotary encoder’s output to a microcontroller provides a straightforward way to monitor and control the speed of a motor with a rotary encoder as a sensor.
Figure 6: Interfacing Rotary encoder with a DC motor
Motion Controller block: A motion controller is needed to compare the reference speed with the actual speed and feed the error signal back to the motor. Since the above discussed rotary encoder returns two quadrature phase signals A and B, we need to implement logic to decode these signals and sense the current speed of the motor. By computing the difference between the sensed speed and the actual speed, we can feed a correction factor to the motor so that it achieves the required speed. Since controlling the power supply to a motor controls its rotational speed, the correction factor to be fed involves giving a suitable voltage correction to the given supply voltage.
Using a programmable SoC for motor control
The following sections describe this speed control application in detail, with the Cypress PSoC 3/5 used as the motion controller. Though many controllers may be used to perform this operation, the PSoC includes a flexible visual embedded design methodology that includes preconfigured, user-defined peripherals and hierarchical schematic entry. It also includes high-precision programmable analog blocks including 12- to 20-bit delta-sigma ADCs, a digital logic library, power management, and connectivity resources useful for motor control applications.
If we intend to decode the signals from the rotary encoder and do further processing, we typically have to use an interrupt routine in a normal microcontroller, which prevents other functions from being executed when this interrupt routine is being serviced.
With a programmable SoC device, the microcontroller has a separate digital block/hardware block that can decode these quad-phase signals (A and B) and store the current count value (i.e., automatically increment and decrement).
In the feedback loop, if we interface the motor shaft (whose speed is to be measured) with the shaft of a rotary encoder through motor adapters (this might load the motor), the encoder’s shaft will rotate at the same speed as that of the motor. The outputs of these encoders can be fed to the quadrature decoder module available in the PSoC 3/5 for further processing for a complete implementation of a typical motor control system.
A sample motor control application
One of the common requirements for motor-related applications is “Speed Measurement”. As said earlier, the current count value can be stored in the decoder module. Using this, we can measure the speed of the motor by measuring the count value for every minute, since speed of a motor is usually measured in rotations per minute.
For example, after every minute we can reset the count value or we can use the difference in counts for our calculation. Instead of waiting for a minute, the count 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 by measuring per minute. Therefore, the speed of the motor can be calculated as
For instance, let us assume that we need to maintain the speed of a stepper motor at 6000 rpm. Considering an open-loop system, we would just have a controller outputting a square wave signal to the stepper motor to rotate it in one direction at 6000 rpm. However, when we add a load to the motor, the speed of the motor decreases below the actual value at which it should run. Hence, we cannot achieve the desired speed and there is no way to adjust it.
In order to maintain the speed at a specific value irrespective of changes in the motor load, we need to follow the principle of a closed-loop system. To sense and feedback the current rotating speed, we use a rotary encoder, as discussed earlier. Our choice of encoder depends upon the speed of rotation and the speed accuracy needed. The signals from the rotary encoder are decoded using the Quad Decoder module available using the PSoC Creator tool.
A suitable 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 to 150 rotations per second. If the encoder gives 4 pulses (encoder characteristic) for every complete rotation, then the clock frequency needed for the decoder module is 150*4*10=6 kHz (10 times as that of A and B signals).
Since we need to track the count value every second, we can generate an interrupt every 1 second. In the interrupt service routine, we can capture the count register value and then clear it (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 it consumes 88 mA with 5 V supply at no load condition, we can interface the output of PSoC 3/5 with the DC motor through a current driving circuit, as shown in Figure 7:
Figure 7: DC motor driven through PSoC
While a 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 encoder rotates along with the motor at the same speed and the output of the encoder is measured using the decoder in the PSoC 3/5. Now the microcontroller detects the speed to be 9000 rpm and compares it with the needed value (i.e., 6000 rpm or 2/3 times the actual speed). The corrective response is -3000 rpm (i.e., -1/3 times the voltage currently supplied to the motor).
This voltage variation can implemented using a PWM. By varying the duty cycle of PWM, the average voltage can be varied. There is a drag-and-drop PWM module in PSoC Creator. The clock frequency to feed to the PWM module depends on the speed resolution needed by the application.
Here the Duty cycle required would be 2/3. Hence, the average output voltage of the PWM module per cycle would be 5*2/3 = 3.33 V. The output of the PWM module is supplied to the current driving circuit that is connected to the DC motor. The DC motor now rotates at the desired speed of 6000 rpm. The rotary encoder again senses the speed, detects 6000 rpm, and feeds it back to the controller. Now the error factor is 0. The PWM maintains its previous state, and the motor maintains its speed.
Suppose that a load is added to the motor, though the duty cycle is maintained at 2/3, the speed of the motor comes down to say 5000 rpm. Now the rotary encoder senses the speed and feeds it to PSoC 3/5. Now, the error factor 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 PWM Digital block through firmware.
Case 2: DC Motor is powered through an MCU. If the DC motor is powered through another controller, then the PSoC controller can be used to feed the current status of the motor to the other controller through an interface such as I2C. If the DC motor is powered through an external battery, it is easy to control its speed through the logic shown in Figure 8. The PWM output from PSoC can be fed to the switch which would switch on and switch the supply to the motor with a certain duty cycle so that it meets the same criteria as before.
Figure 8: DC motor powered through an external source (not PSoC)
For other motor control applications such as position control, we can use an absolute rotary encoder, as it gives the current position of the motor. This output can again be fed back to the controller to find the deviation from the actual signal and, by giving a pulse for a small duration, make sure the motor reaches its target position.
Asha Ganesan earned her Bachelor’s degree in Electronics and Communication at College of Engineering Guindy. She is currently working as an Applications Engineer at Cypress Semiconductor. She is an expert in PSoC 3 and PSoC 5 products and assists customers with their PSoC 3/5 projects. Her email address is firstname.lastname@example.org.
Page 2 of 2Next >
Currently no items