Datasheet

Analog-to-Digital Converter (ATD)
MC68HC812A4 Data Sheet, Rev. 7
208 Freescale Semiconductor
16.11 Using the ATD to Measure a Potentiometer Signal
This exercise allows the student to utilize the ATD on the HC12 to measure a potentiometer signal output
routed from the UDLP1 board to the HC12 ATD pin PAD6. First the ATDCTL registers are initialized. A
delay loop of 100 ยตs is then executed. The resolution is set up followed by a conversion set up on
channel 6. After waiting for the status bit to set, the result goes to the D accumulator. If the program is
working properly, a different value should be found in the D accumulator as the left potentiometer is varied
for each execution of the program.
16.11.1 Equipment
For this exercise, use the M68HC812A4EVB emulation board.
16.11.2 Code Listing
NOTE
A comment line is delimited by a semicolon. If there is no code before
comment, a semicolon(;) must be placed in the first column to avoid
assembly errors.
; ----------------------------------------------------------------------
; MAIN PROGRAM
; ----------------------------------------------------------------------
ORG $7000 ; 16K On-Board RAM, User code data area,
; start main program at $7000
MAIN:
BSR INIT ; Branch to INIT subroutine to Initialize ATD
BSR CONVERT ; Branch to CONVERT Subroutine for conversion
DONE: BRA DONE ; Branch to Self, Convenient place for breakpoint
; ----------------------------------------------
; Subroutine INIT: Initialize ATD ;
; ----------------------------------------------
INIT:
LDAA #$80 ; Allow ATD to function normally,
STAA ATDCTL2 ; ATD Flags clear normally & disable interrupts
BSR DELAY ; Delay (100 uS) for WAIT delay time.
LDAA #$00 ; Select continue conversion in BGND Mode
STAA ATDCTL3 ; Ignore FREEZE in ATDCTL3
LDAA #$01 ; Select Final Sample time = 2 A/D clocks
STAA ATDCTL4 ; Prescaler = Div by 4 (PRS4:0 = 1)
RTS ; Return from subroutine