Closed Loop Control
The simulation design uses the index output of the servo module for feedback, because this is easier to implement in a prototype. The signal can be generated by making one opto-sensor mark on the shaft (or magnetic equivalent) or one slot or hole in a disk attached to the shaft. One pulse per revolution will also provide more time between pulses for the control program to complete its processing tasks. The sensor is connected to the Timer0 input, an 8-bit counter/timer register that can be clocked externally or from the system clock, and which we can use to measure the pulse total count, frequency or period, depending on the application.
Closed loop position control involves counting the revolutions as the shaft turns. This sounds straightforward, but the dynamic characteristics of the motor have to be taken into account. For example, the motor can be switched on from the controller, the pulses counted, and the motor turned off when a set number of pulses has occurred. However, the motor will probably overshoot the required position owing to inertia of the rotor and load. A simple solution is to keep counting the slots and turn the motor back by the requisite number of slots. This may have to be repeated several times, causing oscillation. Another improvement is to ramp the speed of the motor up and down at the start and end of the move.
With only one slot, the position can only be determined to the nearest whole revolution. This may be acceptable if a gearbox is fitted (often the case in position controllers), which reduces the angular rotation and speed. For instance, if the gearbox has a reduction ratio of 50:1, the output can be positioned within 1/50 of a revolution. If a shaft encoder is used, a known number of slots per revolution is generated, and a proportionate increase in accuracy obtained. With 100 slots, for example, and the gearbox, the accuracy will be 360/(50 x 100) ¼ 0.072 degrees. This result can then be used to estimate the positional resolution of the load attached. For example, if a robot arm of length 300 mm is attached to this drive, the accuracy at the end of the rotating arm will be the length of arc:
Circumference of working circle ¼ 2pr ¼ 2 x 0:3 x p ¼ 1:885 m Arc of step ¼ 1:885 x 0:072=360 ¼ 0:38 mm ¼ resolution
Speed control will involve measuring the index pulse interval, and comparing it with a target value. The target value can be input from any of the analogue, digital or serial data sources available in MOT2. The PWM duty cycle is then adjusted continuously towards this target.
Since there is some delay in the response of the motor, owing to mechanical inertia, the speed may oscillate around the target value to some extent. This depends very much on the characteristics of the motor and load, which can be varied in the simulation circuit to investigate their effect.