\documentclass[11pt,dvips]{article}
\usepackage{epsfig}
\usepackage{fancyheadings}
\setlength{\parskip}{2ex}
%\setlength{\parindent}{0em}
\hoffset=-55pt
\voffset=-60pt
\textheight=9in
\textwidth=6.5in
\parindent=0pt
\parskip=10pt
\pagestyle{fancy}
\lhead{\bfseries EE 308 Quiz 3}
\chead{\bfseries }
\rhead{\bfseries Spring 1999}
\lfoot{\bfseries }
\cfoot{\thepage}
\rfoot{\bfseries }
\setlength{\headrulewidth}{0.5pt}
\begin{document}

%\begin{LARGE}
\begin{center}
{\bf USING THE HC12 A/D CONVERTER}
\end{center}

\begin{enumerate}
\item Power up A/D Converter ({\tt ADPU = 1} in {\tt ATDCTL2})
\item Set {\tt ATDCTL4 = 0x01} (Gives 2~MHz AD clock with 8~MHz E-clock)
\item Select 8-channel mode  ({\tt S8CM = 1} in {\tt ATDCTL5})
\item Set {\tt CD = 0} in {\tt ATDCTL5} ({\tt CD = 1} for factory test only)
\item Select {\tt MULT} in {\tt ATDCTL5}:
\begin{itemize}
\item {\tt MULT = 0}:  Convert one channel eight times
\begin{itemize}
\item Choose channel to convert with {\tt CC, CB, CA} of {\tt ATDCTL5}. 
\end{itemize}
\item {\tt MULT = 1}:  Convert eight channels
\end{itemize}
\item Select {\tt SCAN} in {\tt ATDCTL5}:
\begin{itemize}
\item {\tt SCAN = 0}:  Convert eight samples, then stop
\item {\tt SCAN = 1}:  Convert continuously
\end{itemize}
\item After writing to {\tt ATDCTL5}, the A/D converter starts, and the {\tt
SCF} bit is cleared.  After eight conversions are complete, the {\tt SCF}
flag in {\tt ATDSTAT} is set.  You can read the results of the conversions
in {\tt ADR[0-7]H}.

\item If {\tt SCAN = 0}, you need to write to {\tt ATDCTL5} to start a new
sequence.  If {\tt SCAN = 1}, the conversions continue automatically, and you
can read new values in  {\tt ADR[0-7]H}.
\item To get interrupt after eight conversions completed, set {\tt ASCIE} bit
of {\tt ATDCTL2}.  After eight conversions, {\tt ASCIF} bit in {\tt ATDCTL2}
will be set, and an interrupt will be generated.

\item With 8~MHz E-clock and {\tt ATDCTL4 = 0x01}, it takes 9~$\mu$s to
make one conversion, 72~$\mu$s to make eight conversions.

\newpage

\item On HC12 EVBU, AD channels 0 and 1 are used to determine start-up program
(D-Bug12, EEPROM or bootloader).  Do not use AD channels 0 or 1 unless
absolutely necessary (you need 7 or 8 channels).  If you do need AD channels 0
and/or 1, power up EVBU, then remove jumpers which select start-up program.

\item $$ {\tt ADR} = \frac{V_{in} - V_{RL}}{V_{RH}-V_{RL}} \times 255$$
Normally, $V_{RL}$ = 0~V, and $V_{RH}$ = 5~V, so
$$ {\tt ADR} = \frac{V_{in}}{\rm 5~V} \times 255$$
Example:  {\tt ADR0H = 112} \verb+=>+ $V_{in}$ = 2.20~V

\item You can get more accuracy by averaging multiple conversions.  If you
need only one channel, set {\tt MULT = 0}, then average all eight result
registers:

\begin{verbatim}
   int avg;

   avg = (ADR0H + ADR1H + ADR2H + ADR3H + ADR4H 
                + ADR5H + ADR6H + ADR7H) >> 3;
\end{verbatim}

\end{enumerate}


%\end{LARGE}

\end{document}
