EE331

µProcessor Hardware & Software

Final Report

Digitally Controlled Angular Position Servo

Objective

The purpose of this project is to replace the analogue angular position controller that was given and breadboarded after the midterm with a digitally controlled system. The digital control system used will be the HC11 development board.

Physical System Components

The motor to be controlled is a Hi-Tech servo, modified to allow continuous rotation by cutting out the stops. Also, the internal control circuitry of the servo was removed, and the connections of the potentiometer were brought outside the motor , along with the two terminals of the internal brushed DC motor. To allow forward and backward rotation, a dual rail supply was created by referencing the input of an LM675 high current op amp halfway between the positive and negative terminals of a 12V wall supply, creating a ±6V supply with a virtual ground. This supply fed another LM675, whose input was connected to the TLC7226 R2R ladder DAC, and whose output was connected to the motor. The set point pot (VR1) and motor pot (VR2) were connected to PE4 and PE5 on the HC11, respectively.

Digital Components

Two main peripherals of the HC11 used to implement motor control were the internal timer, using the OC2 module, and the internal analogue to digital converter. The timer was used to trigger an A/D conversion every 1ms. The A/D was used to read in the voltage of VR1 and VR2, and the difference between them was converted to offset binary and output to the DAC.

The OC2 is a hardware compare module. It uses the internal 16-bit timer of the HC11, and compares the current count of the HC11 with the value stored in TOC2. If the values are the same, and OC2 is enabled, an interrupt is generated. In the interrupt, a flag is set signalling the main loop to begin an A/D conversion. Then the delay value is added to the TOC2 register, the interrupt cleared, and the system returns from the interrupt.

The ADC is used to convert the voltage are the wiper of pots VR1 and VR2 to an 8-bit digital value. The HC11 internal ADC uses a successive approximation approach, utilizing an internal 8-bit capacitive DAC. The ADC is set to run in multi mode, and converts PE4-PE7 and stores the values in ADR1-ADR2. In this case, VR1 is stored in ADR1 and VR2 is stored in ADR2. A conversion is started by writing the modes (multi or single channel, continuous or non-continuous scanning) and a start bit to the ADCTL register. The read subroutine the waits for the conversion complete flag to be set.

HC11 Peripherals Tested But Not Used

Several other approaches to D/A conversion were investigated but not used in the course of the term. First, the principles of a SAR style ADC were investigated, by using the R2R DAC and a comparator. The analogue voltage was fed to one pin of the comparator, and the output of the DAC to another. By monitoring the output of the comparator, and successively writing different values to the DAC, the digital value approaches that of the true analog value. The downside of this external approach is that it requires the use of the R2R DAC and an external comparator, which increases the cost and complexity of the circuit, and more importantly, because of the settling time of the DAC this method is much slower than the onboard ADC.

Also investigated was a ∆∑ DAC. An output pin of the HC11 was modulated, and when passed through a low-pass filter produces an analogue waveform. By varying the duty cycle of the switching, different voltages can be produced. While simple and low parts count, this method is problematic, as the RC constant of the LPF has to be chosen with the operating frequency in mind, which limits the frequency range that can by output without distortion.

Changes Made To The Reference Setup

Because the DAC is only able to output ±3.2V, and that maximum voltage is only output when the difference between VR1 and VR2 is ±5V and decreases as the motor approaches the set point, the time to reach the set point was excessively long with unity gain on the output op amp. To speed up the motor, gain was increased to 4.5 by changing R8 to 100kΩ. This allowed the motor to be driven from the full ±6V supply, greatly increasing its speed.

As well, the code was altered from the given sample code. A great number of unnecessary variables were removed, and the flow of code was cleaned up. Also, instead of storing the reading of VR1 and VR2 into variables AN6 and AN7, they were just loaded into accumulators A and B directly and then processed.

The flow of the program can be seen in the attached flow chart, and is quite simple. When the program is run, all the initializations are done, and the main loop is entered. In the main loop, an A/D conversion is done, and the values of the two pots are subtracted. This is the error signal that is to be applied to the motor. This value is exclusive ORed with 0x80 to convert from 2’s complement to offset binary, and then output to the DAC and the LEDs. This error signal causes the output buffer op amp to apply a voltage to the motor, spinning it. This causes the position of the pot to change, and this continues until the both pots have the same value. Once the conversion is done and the value output, the main loop waits for the interrupt flag to be set before beginning a new sample.

In the ISR that triggers, a flag is set that indicates that it is time to begin a new sample, the OC2 interrupt flag is cleared, and the delay value is added to the TOC2 register.

Figure 1 - Software Flow Chart

Conclusion

The system performed as expected. When the set point was changed on VR1, the motor changed position as expected. Turning the pot CW caused a CW rotation in the motor, and a CCW rotation of the set pot caused an equal CCW rotation of the motor. The speed was good due to the increase in amplifier gain, and no overshoot or motor oscillation was observed. Some oscillation was noticed on output of the op amp, but this was caused by the analogue circuit layout, the digital output did not display any unexpected results. It’s possible that this could be eliminated by a better breadboarding layout, a PCB or alternate snubbing approach.