EE 308 - LAB 10

Final version for 2000

The 68HC12 Analog to Digital Converter

The analog to digital converter is described in Section 15 of the HC12 reference manual. The analog to digital converter can have up to eight inputs on pins Port AD0 through Port AD7. (Ports AD0 and AD1 are used by DBug-12 at startup to determine whether to execute DBug12 or run code from EEPROM or the bootlaoder. You should not use Ports AD0 or AD1 as A/D inputs unless all other six inputs are being used.) The A/D converter also uses two dedicated pins VRH and VRLfor high and low voltage references respectively. On your HC12 board, VRHis connected to VCC, and VRL is connected to GND. An input voltage of VRL gives an output of 0x00, and an input of VRH gives an output of 0xFF. If we measure a voltage between VRL and VRH, we can compute the value by simple ratios

For example, if VRH = 5 volts, and VRL = 0 volts, and the measurement is 0x2B0, then the measured voltage is

To make sure that you do not damage the A/D converter on your HC12 you should be sure to do the following:

• You should have a 1 to 10 KOhm resistor in series with the A/D input pin to prevent damage if your input voltage rises above VRH.
• You should never allow the voltage at the A/D pin to go below VRL.

1.
Write a program to take a 0 to 5 Volt analog input from PAD3 and output the most significant 8 bits of the converted digital value on Port EB of your HC12. Use your LED's to display this value.

2.
Connect a voltage from a pot to PAD3, so you can vary PAD3 from 0 to 5 Volts. Compare the value displayed on the LEDs with multimeter measurements for several different input voltages.

3.
Write a program which uses the RTI interrupt. The RTI should generate an interrupt every 64 ms. The RTI interrupt service routine should set a flag which tells the main program the interrupt has occurred.

4.
The A/D conversion measurements can be improved by averaging the values in the registers ADR0 through ADR7. In your RTI routine, average the 8 values. Display the 8 most significant bits of the average value on the LEDs connected to Port EB. Is the value more stable than it was when you displayed the unaveraged value?

Bill Rison
2000-04-14