EE 308 - LAB 10

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

\begin{displaymath}voltage = {\frac{measurement * (V_{RH} - V_{RL})}{255}} + V_{RL}\end{displaymath}

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

\begin{displaymath}\frac{172 * (5 - 0)}{255} + 0 = 3.37 \,\,\, {\rm volts.}\end{displaymath}

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

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

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.

Write a program which uses the RTI interrupt. The RTI should generate an interrupt every 64 ms. The RTI interrupt service routine should increment a counter (or generate some other pattern of your choice). If Bit 0 of Port A is high display this pattern on Port B. If Bit 0 of Port A is low, read the A/D converter for input PAD3 and display this on Port B. (Connect a dip switch to Port A so you can change it.)

The A/D conversion measurements can be improved by averaging the values in the registers ADR0H through ADR7H. In your RTI routine, average the 8 values. Display the average value if Bit 1 of Port A is low, and display a single value if Bit 1 of Port A is high. Are the LEDs more stable in the averaged mode?

Add a 400 Hz PWM signal on Bit 2 of Port P. Make the duty cycle proportional to the input voltage on PAD3. Set the duty cycle in the RTI interrupt service routine. Connect your logic analyzer and verify that the PWM duty cycle is proportional to the input voltage.

Bill Rison, < >
Thu Mar 25 1999

© 1999, New Mexico Tech