\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 }
\chead{\bfseries }
\rhead{\bfseries Spring 1998}
\lfoot{\bfseries }
\cfoot{\thepage}
\rfoot{\bfseries }
\setlength{\headrulewidth}{0.5pt}
\begin{document}

\begin{Large}

\begin{center}
{\bf Time Units for Timer Subsystem}\\
\end{center}

With 8~MHz E~clock, basic time unit {\tt T} is 0.125~$\mu$s.

Prescaler changes time unit for timer module (input capture, output compare,
timer overflow) to $0.125 \mu{\rm{s}}$ $\times$ prescaler.

For example, {\tt PR2:0 = 011 => {\rm prescaler} = 8}, so TCNT is incremented
every 1~$\mu$s.

When reading input capture, elapsed time = $\Delta {\tt{TCx}}$ $\times$
prescaler $\times$ {\tt T}.

For example, {\tt PR2:0 = 011} and {\tt TC2 - TC1 = 12,500}, then\\
elapsed time = $12,500 \times 8 \times 0.125 \mu{\rm{s}} = 12.5$~ms

Want OC to do something after time {\tt X} seconds, what to add to {\tt TCx}?

$$\frac{\tt X}{{\tt T} \times {\rm prescaler}}$$

For example, to create 1~kHz square wave, half-period is 500~$\mu$s.  If
prescaler is 8, then add:


$$ \frac{500 \mu{\rm{s}}}{{\tt T} \times 8} = 
\frac{500 \mu{\rm{s}}}{1 \mu{\rm{s}}} =  500$$

and {\tt TCx = TCx + 500}

For example, to have pulse width modulation on OC1 with 500~Hz frequency and 80\%
duty cycle, with prescaler = 2:

500~Hz \verb+=>+ 2~ms, so add to TC7:

$$ \frac{2 {\rm{ms}}}{{\tt T} \times 2} = 
\frac{2000 \mu{\rm{s}}}{0.25 \mu{\rm{s}}} =  8000$$

For 80\% duty cycle, add $0.80 \times 8000 = 6400$ to TC1.

\end{Large}

\end{document}
