<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: Timer Function Library for ATmegaXX8 (timerx8.c)</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<h1>Timer Function Library for ATmegaXX8 (timerx8.c)<br>
<small>
[<a class="el" href="group__driver__avr.html">Drivers (for AVR peripherals)</a>]</small>
</h1><hr><a name="_details"></a><h2>Detailed Description</h2>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include "<a class="code" href="timerx8_8h.html">timerx8.h</a>"</span>
</pre></div> <dl compact><dt><b>Overview</b></dt><dd>This library provides functions for use with the timers internal to the AVR processors. Functions include initialization, set prescaler, calibrated pause function (in milliseconds), attaching and detaching of user functions to interrupts, overflow counters, PWM. Arbitrary frequency generation has been moved to the Pulse Library.</dd></dl>
<dl compact><dt><b>About Timers</b></dt><dd>The Atmel AVR-series processors each contain at least one hardware timer/counter. Many of the processors contain 2 or 3 timers. Generally speaking, a timer is a hardware counter inside the processor which counts at a rate related to the main CPU clock frequency. Because the counter value increasing (counting up) at a precise rate, we can use it as a timer to create or measure precise delays, schedule events, or generate signals of a certain frequency or pulse-width. </dd></dl>
<dl compact><dt><b></b></dt><dd>As an example, the ATmega163 processor has 3 timer/counters. Timer0, Timer1, and Timer2 are 8, 16, and 8 bits wide respectively. This means that they overflow, or roll over back to zero, at a count value of 256 for 8bits or 65536 for 16bits. A prescaler is avaiable for each timer, and the prescaler allows you to pre-divide the main CPU clock rate down to a slower speed before feeding it to the counting input of a timer. For example, if the CPU clock frequency is 3.69MHz, and Timer0's prescaler is set to divide-by-8, then Timer0 will "tic" at 3690000/8 = 461250Hz. Because Timer0 is an 8bit timer, it will count to 256 in just 256/461250Hz = 0.555ms. In fact, when it hits 255, it will overflow and start again at zero. In this case, Timer0 will overflow 461250/256 = 1801.76 times per second. </dd></dl>
<dl compact><dt><b></b></dt><dd>Timer0 can be used a number of ways simultaneously. First, the value of the timer can be read by accessing the CPU register <code>TCNT0</code>. We could, for example, figure out how long it takes to execute a C command by recording the value of <code>TCNT0</code> before and after execution, then subtract (after-before) = time elapsed. Or we can enable the overflow interrupt which goes off every time T0 overflows and count out longer delays (multiple overflows), or execute a special periodic function at every overflow. </dd></dl>
<dl compact><dt><b></b></dt><dd>The other timers (Timer1 and Timer2) offer all the abilities of Timer0 and many more features. Both T1 and T2 can operate as general-purpose timers, but T1 has special hardware allowing it to generate PWM signals, while T2 is specially designed to help count out real time (like hours, minutes, seconds). See the Timer/Counter section of the processor datasheet for more info. </dd></dl>
<p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Modules</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerpwm.html">Timer PWM Commands</a></td></tr>
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga13" doxytag="timerx8::PWM10"></a>
#define </td><td class="memItemRight" valign="bottom"><b>PWM10</b> WGM10</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga14" doxytag="timerx8::PWM11"></a>
#define </td><td class="memItemRight" valign="bottom"><b>PWM11</b> WGM11</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga15" doxytag="timerx8::TIMER_CLK_STOP"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga15">TIMER_CLK_STOP</a> 0x00</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer Stopped. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga16" doxytag="timerx8::TIMER_CLK_DIV1"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga16">TIMER_CLK_DIV1</a> 0x01</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at F_CPU. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga17" doxytag="timerx8::TIMER_CLK_DIV8"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga17">TIMER_CLK_DIV8</a> 0x02</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at F_CPU/8. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga18" doxytag="timerx8::TIMER_CLK_DIV64"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga18">TIMER_CLK_DIV64</a> 0x03</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at F_CPU/64. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga19" doxytag="timerx8::TIMER_CLK_DIV256"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga19">TIMER_CLK_DIV256</a> 0x04</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at F_CPU/256. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga20" doxytag="timerx8::TIMER_CLK_DIV1024"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga20">TIMER_CLK_DIV1024</a> 0x05</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at F_CPU/1024. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga21" doxytag="timerx8::TIMER_CLK_T_FALL"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga21">TIMER_CLK_T_FALL</a> 0x06</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at T falling edge. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga22" doxytag="timerx8::TIMER_CLK_T_RISE"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga22">TIMER_CLK_T_RISE</a> 0x07</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer clocked at T rising edge. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga23" doxytag="timerx8::TIMER_PRESCALE_MASK"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga23">TIMER_PRESCALE_MASK</a> 0x07</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Timer Prescaler Bit-Mask. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga24" doxytag="timerx8::TIMERRTC_CLK_STOP"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga24">TIMERRTC_CLK_STOP</a> 0x00</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer Stopped. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga25" doxytag="timerx8::TIMERRTC_CLK_DIV1"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga25">TIMERRTC_CLK_DIV1</a> 0x01</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga26" doxytag="timerx8::TIMERRTC_CLK_DIV8"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga26">TIMERRTC_CLK_DIV8</a> 0x02</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/8. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga27" doxytag="timerx8::TIMERRTC_CLK_DIV32"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga27">TIMERRTC_CLK_DIV32</a> 0x03</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/32. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga28" doxytag="timerx8::TIMERRTC_CLK_DIV64"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga28">TIMERRTC_CLK_DIV64</a> 0x04</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/64. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga29" doxytag="timerx8::TIMERRTC_CLK_DIV128"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga29">TIMERRTC_CLK_DIV128</a> 0x05</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/128. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga30" doxytag="timerx8::TIMERRTC_CLK_DIV256"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga30">TIMERRTC_CLK_DIV256</a> 0x06</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/256. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga31" doxytag="timerx8::TIMERRTC_CLK_DIV1024"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga31">TIMERRTC_CLK_DIV1024</a> 0x07</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer clocked at F_CPU/1024. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga32" doxytag="timerx8::TIMERRTC_PRESCALE_MASK"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga32">TIMERRTC_PRESCALE_MASK</a> 0x07</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">RTC Timer Prescaler Bit-Mask. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga33" doxytag="timerx8::TIMER0PRESCALE"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga33">TIMER0PRESCALE</a> TIMER_CLK_DIV8</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">timer 0 prescaler default <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga34" doxytag="timerx8::TIMER1PRESCALE"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga34">TIMER1PRESCALE</a> TIMER_CLK_DIV64</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">timer 1 prescaler default <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga35" doxytag="timerx8::TIMER2PRESCALE"></a>
#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga35">TIMER2PRESCALE</a> TIMERRTC_CLK_DIV64</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">timer 2 prescaler default <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga36" doxytag="timerx8::TIMER0OVERFLOW_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER0OVERFLOW_INT</b> 0</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga37" doxytag="timerx8::TIMER1OVERFLOW_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER1OVERFLOW_INT</b> 1</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga38" doxytag="timerx8::TIMER1OUTCOMPAREA_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER1OUTCOMPAREA_INT</b> 2</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga39" doxytag="timerx8::TIMER1OUTCOMPAREB_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER1OUTCOMPAREB_INT</b> 3</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga40" doxytag="timerx8::TIMER1INPUTCAPTURE_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER1INPUTCAPTURE_INT</b> 4</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga41" doxytag="timerx8::TIMER2OVERFLOW_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER2OVERFLOW_INT</b> 5</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga42" doxytag="timerx8::TIMER2OUTCOMPARE_INT"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER2OUTCOMPARE_INT</b> 6</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga43" doxytag="timerx8::TIMER_NUM_INTERRUPTS"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER_NUM_INTERRUPTS</b> 7</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga44" doxytag="timerx8::TIMER_INTERRUPT_HANDLER"></a>
#define </td><td class="memItemRight" valign="bottom"><b>TIMER_INTERRUPT_HANDLER</b> SIGNAL</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga45" doxytag="timerx8::delay"></a>
#define </td><td class="memItemRight" valign="bottom"><b>delay</b> delay_us</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga46" doxytag="timerx8::delay_ms"></a>
#define </td><td class="memItemRight" valign="bottom"><b>delay_ms</b> timerPause</td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga0" doxytag="timerx8::delay_us"></a>
void </td><td class="memItemRight" valign="bottom"><b>delay_us</b> (unsigned short time_us)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga1" doxytag="timerx8::timerInit"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga1">timerInit</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">initializes timing system (all timers) <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga2" doxytag="timerx8::timer0Init"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga2">timer0Init</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">initialize timer0 <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga3" doxytag="timerx8::timer1Init"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga3">timer1Init</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">initialize timer1 <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga4" doxytag="timerx8::timer0SetPrescaler"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga4">timer0SetPrescaler</a> (u08 prescale)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">set timer0 prescaler <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga5" doxytag="timerx8::timer0GetPrescaler"></a>
u16 </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga5">timer0GetPrescaler</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">get timer0 prescaler <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga6" doxytag="timerx8::timer1SetPrescaler"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga6">timer1SetPrescaler</a> (u08 prescale)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">set timer1 prescaler <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga7" doxytag="timerx8::timer1GetPrescaler"></a>
u16 </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga7">timer1GetPrescaler</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">get timer0 prescaler <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga8" doxytag="timerx8::timerAttach"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga8">timerAttach</a> (u08 interruptNum, void(*userFunc)(void))</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Attach a user function to a timer interrupt. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga9" doxytag="timerx8::timerDetach"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga9">timerDetach</a> (u08 interruptNum)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Detach a user function from a timer interrupt. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga10">timerPause</a> (unsigned short pause_ms)</td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga11" doxytag="timerx8::timer0ClearOverflowCount"></a>
void </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga11">timer0ClearOverflowCount</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Clear timer0's overflow counter. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ga12" doxytag="timerx8::timer0GetOverflowCount"></a>
long </td><td class="memItemRight" valign="bottom"><a class="el" href="group__timerx8.html#ga12">timer0GetOverflowCount</a> (void)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">read timer0's overflow counter <br></td></tr>
</table>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="ga10" doxytag="timerx8.h::timerPause"></a><p>
<table class="mdTable" cellpadding="2" cellspacing="0">
<tr>
<td class="mdRow">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top">void timerPause </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top">unsigned short </td>
<td class="mdname1" valign="top" nowrap> <em>pause_ms</em> </td>
<td class="md" valign="top"> ) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing="5" cellpadding="0" border="0">
<tr>
<td>
</td>
<td>
<p>
A timer-based delay/pause function <dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>pause_ms</em> </td><td>Number of integer milliseconds to wait. </td></tr>
</table>
</dl>
<p>
Definition at line <a class="el" href="timer_8c-source.html#l00204">204</a> of file <a class="el" href="timer_8c-source.html">timer.c</a>. </td>
</tr>
</table>
<hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:09 2006 for Procyon AVRlib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
|