Test Programs for MOT2
The following test programs for the MOT2 board will demonstrate aspects of direction, position and speed control.
Direction Test
A simple test program to drive the motor in each direction DCM1 is listed as Program 11.1. When S1 is held on, the motor runs in the forward direction, and in the reverse direction when S2 is operated. In ISIS simulation mode, the motor properties should be set to supply ¼ 6 V, armature resistance ¼ 3 U and load mass ¼ 0.0001, so that the motor responds quickly. A voltage probe can be attached to the bridge common node to measure the current in the sensing resistor (60 mA). The nominal speed should be set to 1000 because the maximum displayed rpm is 999. The simulated servo parameters can be adjusted to check the effect.
Position Control
A program POS2 that moves the motor to a position set on the pot is represented in the flowchart in Figure 11.4, and the source code listed as Program 11.2.
The principle of the program is to read a position from the pot in the range 0e255, as an 8-bit result from the ADC, and move the motor to a corresponding position. To allow the pot to be adjusted before the motor responds, push-button S1 is used to trigger the move. Initially, the motor position is set midway at 127. If the pot is moved to a forward or reverse position, the motor moves the same number of revolutions, i.e. ± 127. The index output of the servomotor is fed back to Timer0 (8-bit counter) in the MCU, which counts the number of revolutions. This is compared with the target value in the monitoring phase, and the motor stopped when the correct number of pulses has been received.
The main problem with motor control, which is illustrated in this example, is that the motor tends to overshoot the target position because of mechanical inertia. An attempt to correct this is incorporated in the program, where the overrun is counted and the motor moved back if necessary. This is achieved by waiting an arbitrary time after the motor has been switched off and checking the count again. However, if the program timing and motor characteristics are not closely matched, the motor may either oscillate about the target position (hunting) or not
achieve an accurate position. This effect can be seen if the program is simulated in ISIS. The motor mass needs to be adjusted to about 0.0002 for the simulation to work properly; this can be varied to see the effect on the overshoot.
In this case, the position can only be controlled to a resolution of one revolution. Using the incremental encoder outputs of the servo would allow this performance to be improved, by counting more pulses per revolution. Another way of achieving better performance is for the current position to be continuously compared with the required position, and the motor driven
at a speed proportional to the error. The motor will slow down as it approaches the target position. This type of process is referred to as PID (proportional, integral and differential) control, where the response of the system can be tuned to give the best compromise between speed of response, accuracy and overshoot. A simpler process called ‘trapezoidal’ control can also be used. This involves ramping the motor speed up and down at the ends of the move, with a constant speed period in the middle.