Page 210 - Programming Microcontrollers in C
P. 210
Analog-to-Digital Converter Operation 195
EXERCISES
1. Write a program that uses an output compare system to generate
an accurate waveform with a 1000.0 second period.
2. Devise a convenient method to test the performance of the pro
gram in Exercise 1 above.
3. Write a program to generate two waveforms. One output is to be at
twice the frequency of the other. The duty factors of the two sig
nals are to be equal to 50%. The frequency of the slowest wave is
to be 1000 Hz. The phase of the higher frequency signal is to be
such that its rising edge is to occur 260 microseconds following
the rising edge of the first signal.
4. Two DC motors are running. Each motor has an optical interrupter
on its shaft with 15 interrupts per revolution of the shaft. All but one
of the interrupts occupy one-sixteenth of the circumference of the
rotation. The fifteenth interrupt occupies one-eighth of the circum
ference. Using input capture registers, measure the speed of the two
motors, and provide a slow down or speed up signal that can be used
on either motor to synchronize the rotation of the two motors with
the wide interrupter positions on the shafts being in lock-step.
5. What microcontroller characteristics will control the maximum speed
at which the motors in Exercise 4 can run? The minimum speed?
Analog-to-Digital Converter Operation
The analog-to-digital converter (ADC) found on the M68HC05
family is moderately simple in its operation. There are a few impor
tant items that must be remembered when dealing with the ADC.
Most important is that the ADC must be turned on for at least 100
microseconds prior to reading a value. If 100 microseconds has not
elapsed, it is guaranteed that the value read will be in error. The ADC
is turned on by setting the ADON bit in the ADC control/status regis
ter. This register is referred to as AD_CTST. The following code
sequence will turn the ADC on:
AD_CTST=0;
AD_CTST.ADON=1;