?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Procyon AVRlib: encoder.h Source File</title>
4 <link href="dox.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.2 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>encoder.h</h1><a href="encoder_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file encoder.h \brief Quadrature Encoder reader/driver. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'encoder.h'</span>
12 00005 <span class="comment">// Title : Quadrature Encoder reader/driver</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2003-2004</span>
14 00007 <span class="comment">// Created : 2003.01.26</span>
15 00008 <span class="comment">// Revised : 2004.06.25</span>
16 00009 <span class="comment">// Version : 0.3</span>
17 00010 <span class="comment">// Target MCU : Atmel AVR Series</span>
18 00011 <span class="comment">// Editor Tabs : 4</span>
19 00012 <span class="comment">//</span><span class="comment"></span>
20 00013 <span class="comment">/// \ingroup driver_hw</span>
21 00014 <span class="comment">/// \defgroup encoder Quadrature Encoder Driver (encoder.c)</span>
22 00015 <span class="comment">/// \code #include "encoder.h" \endcode</span>
23 00016 <span class="comment">/// \par Overview</span>
24 00017 <span class="comment">/// This library allows easy interfacing of standard quadrature encoders</span>
25 00018 <span class="comment">/// (used for sensing shaft rotational position and speed) to the Atmel</span>
26 00019 <span class="comment">/// AVR-series processors. The library uses external interrupts to sense</span>
27 00020 <span class="comment">/// and keep track of the encoder's movements. The library is extendable</span>
28 00021 <span class="comment">/// with the maximum number of encoders equal to the total number of</span>
29 00022 <span class="comment">/// external interrupts available on the target AVR processor.</span>
30 00023 <span class="comment">/// </span>
31 00024 <span class="comment">/// \note Due to the wide range of external interrupt capability on</span>
32 00025 <span class="comment">/// AVR processors, it is difficult for this library to automatically</span>
33 00026 <span class="comment">/// adapt to different processors. For this reason, much of the</span>
34 00027 <span class="comment">/// configuration responsibility has been left with the user. See</span>
35 00028 <span class="comment">/// the encoderconf.h configuration file.</span>
36 00029 <span class="comment"></span><span class="comment">//</span><span class="comment"></span>
37 00030 <span class="comment">/// \par Operation:</span>
38 00031 <span class="comment">/// Quadrature encoders have two digital outputs usually called PhaseA and</span>
39 00032 <span class="comment">/// PhaseB. When the encoder rotates, PhaseA and PhaseB produce square wave</span>
40 00033 <span class="comment">/// pulses where each pulse represents a fraction of a turn of the encoder</span>
41 00034 <span class="comment">/// shaft. Encoders are rated for a certain number of pulses (or counts) per</span>
42 00035 <span class="comment">/// complete revolution of the shaft. Common counts/revolution specs are 50,</span>
43 00036 <span class="comment">/// 100,128,200,250,256,500,etc. By counting the number of pulses output on</span>
44 00037 <span class="comment">/// one of the phases starting from time0, you can calculate the total</span>
45 00038 <span class="comment">/// rotational distance the encoder has traveled.</span>
46 00039 <span class="comment">/// </span>
47 00040 <span class="comment">/// Often, however, we want current position not just total distance traveled.</span>
48 00041 <span class="comment">/// For this it is necessary to know not only how far the encoder has traveled,</span>
49 00042 <span class="comment">/// but also which direction it was going at each step of the way. To do this</span>
50 00043 <span class="comment">/// we need to use both outputs (or phases) of the quadrature encoder.</span>
51 00044 <span class="comment">///</span>
52 00045 <span class="comment">/// The pulses from PhaseA and PhaseB on quadrature encoders are always aligned</span>
53 00046 <span class="comment">/// 90 degrees out-of-phase (otherwise said: 1/4 wavelength apart). This</span>
54 00047 <span class="comment">/// special phase relationship lets us extract both the distance and direction</span>
55 00048 <span class="comment">/// the encoder has rotated from the outputs.</span>
56 00049 <span class="comment">///</span>
57 00050 <span class="comment">/// To do this, consider Phase A to be the distance counter. On each rising</span>
58 00051 <span class="comment">/// edge of PhaseA we will count 1 "tic" of distance, but we need to know the</span>
59 00052 <span class="comment">/// direction. Look at the quadrature waveform plot below. Notice that when</span>
60 00053 <span class="comment">/// we travel forward in time (left-&gt;right), PhaseB is always low (logic 0) at</span>
61 00054 <span class="comment">/// the rising edge of PhaseA. When we travel backwards in time (right-&gt;left),</span>
62 00055 <span class="comment">/// PhaseB is always high (logic 1) at the rising edge of PhaseA. Note that</span>
63 00056 <span class="comment">/// traveling forward or backwards in time is the same thing as rotating</span>
64 00057 <span class="comment">/// forwards or bardwards. Thus, if PhaseA is our counter, PhaseB indicates</span>
65 00058 <span class="comment">/// direction.</span>
66 00059 <span class="comment">///</span>
67 00060 <span class="comment">/// Here is an example waveform from a quadrature encoder:</span>
68 00061 <span class="comment"></span><span class="comment">/*</span><span class="comment"></span>
69 00062 <span class="comment">/// /---\ /---\ /---\ /---\ /---\ /---\</span>
70 00063 <span class="comment">/// Phase A: | | | | | | | | | | | |</span>
71 00064 <span class="comment">/// ---/ \---/ \---/ \---/ \---/ \---/ \-</span>
72 00065 <span class="comment">/// -\ /---\ /---\ /---\ /---\ /---\ /---</span>
73 00066 <span class="comment">/// Phase B: | | | | | | | | | | | |</span>
74 00067 <span class="comment">/// \---/ \---/ \---/ \---/ \---/ \---/</span>
75 00068 <span class="comment">/// Time: &lt;---------------------------------------------------&gt;</span>
76 00069 <span class="comment">/// Rotate FWD: &gt;----------------------------------------------&gt; </span>
77 00070 <span class="comment">/// Rotate REV: &lt;----------------------------------------------&lt;</span>
78 00071 <span class="comment"></span>*/<span class="comment"></span>
79 00072 <span class="comment">/// To keep track of the encoder position in software, we connect PhaseA to an</span>
80 00073 <span class="comment">/// external processor interrupt line, and PhaseB to any I/O pin. We set up</span>
81 00074 <span class="comment">/// the external interrupt to trigger whenever PhaseA produces a rising edge.</span>
82 00075 <span class="comment">/// When a rising edge is detected, our interrupt handler function is executed.</span>
83 00076 <span class="comment">/// Inside the handler function, we quickly check the PhaseB line to see if it</span>
84 00077 <span class="comment">/// is high or low. If it is high, we increment the encoder's position</span>
85 00078 <span class="comment">/// counter, otherwise we decrement it. The encoder position counter can be</span>
86 00079 <span class="comment">/// read at any time to find out the current position.</span>
87 00080 <span class="comment"></span><span class="comment">//</span>
88 00081 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
89 00082 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
90 00083 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>
91 00084 <span class="comment">//</span>
92 00085 <span class="comment">// This code is distributed under the GNU Public License</span>
93 00086 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
94 00087 <span class="comment">//</span>
95 00088 <span class="comment">//*****************************************************************************</span>
96 00089
97 00090 <span class="preprocessor">#ifndef ENCODER_H</span>
98 00091 <span class="preprocessor"></span><span class="preprocessor">#define ENCODER_H</span>
99 00092 <span class="preprocessor"></span>
100 00093 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
101 00094
102 00095 <span class="comment">// include encoder configuration file</span>
103 00096 <span class="preprocessor">#include "<a class="code" href="encoderconf_8h.html">encoderconf.h</a>"</span>
104 00097
105 00098 <span class="comment">// constants/macros/typdefs</span>
106 00099
107 00100 <span class="comment">// defines for processor compatibility</span>
108 00101 <span class="comment">// chose proper Interrupt Mask (IMSK)</span>
109 00102 <span class="preprocessor">#ifdef EIMSK</span>
110 00103 <span class="preprocessor"></span><span class="preprocessor"> #define IMSK EIMSK // for processors mega128, mega64</span>
111 00104 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
112 00105 <span class="preprocessor"></span><span class="preprocessor">#ifdef GICR</span>
113 00106 <span class="preprocessor"></span><span class="preprocessor"> #define IMSK GICR // for mega16,32,etc</span>
114 00107 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
115 00108 <span class="preprocessor"></span><span class="comment">// default</span>
116 00109 <span class="preprocessor">#ifndef IMSK</span>
117 <a name="l00110"></a><a class="code" href="encoder_8h.html#a0">00110</a> <span class="preprocessor"></span><span class="preprocessor"> #define IMSK GIMSK // for other processors 90s8515, mega163, etc</span>
118 00111 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
119 00112 <span class="preprocessor"></span>
120 00113 <span class="comment"></span>
121 00114 <span class="comment">//! Encoder state structure</span>
122 00115 <span class="comment"></span><span class="comment">// stores the position and other information from each encoder</span>
123 <a name="l00116"></a><a class="code" href="structstruct__EncoderState.html">00116</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structstruct__EncoderState.html">struct_EncoderState</a>
124 00117 {
125 <a name="l00118"></a><a class="code" href="structstruct__EncoderState.html#o0">00118</a> s32 <a class="code" href="structstruct__EncoderState.html#o0">position</a>; <span class="comment">///&lt; position</span>
126 00119 <span class="comment"></span>} <a class="code" href="structstruct__EncoderState.html">EncoderStateType</a>;
127 00120
128 00121
129 00122 <span class="comment">// functions</span>
130 00123 <span class="comment"></span>
131 00124 <span class="comment">//! encoderInit() initializes hardware and encoder position readings</span>
132 00125 <span class="comment"></span><span class="comment">// Run this init routine once before using any other encoder function.</span>
133 00126 <span class="keywordtype">void</span> <a class="code" href="encoder_8c.html#a1">encoderInit</a>(<span class="keywordtype">void</span>);
134 00127 <span class="comment"></span>
135 00128 <span class="comment">//! encoderOff() disables hardware and stops encoder position updates</span>
136 00129 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="encoder_8c.html#a2">encoderOff</a>(<span class="keywordtype">void</span>);
137 00130 <span class="comment"></span>
138 00131 <span class="comment">//! encoderGetPosition() reads the current position of the encoder </span>
139 00132 <span class="comment"></span>s32 <a class="code" href="encoder_8c.html#a3">encoderGetPosition</a>(u08 encoderNum);
140 00133 <span class="comment"></span>
141 00134 <span class="comment">//! encoderSetPosition() sets the current position of the encoder</span>
142 00135 <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="encoder_8c.html#a4">encoderSetPosition</a>(u08 encoderNum, s32 position);
143 00136
144 00137 <span class="preprocessor">#endif</span>
145 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
146 <a href="http://www.doxygen.org/index.html">
147 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
148 </body>
149 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3