?? encoder_8c-source.html
字號:
<!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: encoder.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><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="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>encoder.c</h1><a href="encoder_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file encoder.c \brief Quadrature Encoder reader/driver. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'encoder.c'</span>00005 <span class="comment">// Title : Quadrature Encoder reader/driver</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2003-2004</span>00007 <span class="comment">// Created : 2003.01.26</span>00008 <span class="comment">// Revised : 2004.06.25</span>00009 <span class="comment">// Version : 0.3</span>00010 <span class="comment">// Target MCU : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>00016 <span class="comment">//</span>00017 <span class="comment">// This code is distributed under the GNU Public License</span>00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00019 <span class="comment">//</span>00020 <span class="comment">//*****************************************************************************</span>00021 00022 <span class="preprocessor">#ifndef WIN32</span>00023 <span class="preprocessor"></span><span class="preprocessor"> #include <avr/io.h></span>00024 <span class="preprocessor"> #include <avr/signal.h></span>00025 <span class="preprocessor"> #include <avr/interrupt.h></span>00026 <span class="preprocessor">#endif</span>00027 <span class="preprocessor"></span>00028 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00029 <span class="preprocessor">#include "<a class="code" href="encoder_8h.html">encoder.h</a>"</span>00030 00031 <span class="comment">// Program ROM constants</span>00032 00033 <span class="comment">// Global variables</span>00034 <span class="keyword">volatile</span> <a class="code" href="structstruct__EncoderState.html">EncoderStateType</a> EncoderState[NUM_ENCODERS];00035 00036 <span class="comment">// Functions</span>00037 00038 <span class="comment">// encoderInit() initializes hardware and encoder position readings</span>00039 <span class="comment">// Run this init routine once before using any other encoder functions.</span><a name="l00040"></a><a class="code" href="encoder_8h.html#a2">00040</a> <span class="keywordtype">void</span> <a class="code" href="encoder_8c.html#a1">encoderInit</a>(<span class="keywordtype">void</span>)00041 {00042 u08 i;00043 00044 <span class="comment">// initialize/clear encoder data</span>00045 <span class="keywordflow">for</span>(i=0; i<NUM_ENCODERS; i++)00046 {00047 EncoderState[i].<a class="code" href="structstruct__EncoderState.html#o0">position</a> = 0;00048 <span class="comment">//EncoderState[i].velocity = 0; // NOT CURRENTLY USED</span>00049 }00050 00051 <span class="comment">// configure direction and interrupt I/O pins:</span>00052 <span class="comment">// - for input</span>00053 <span class="comment">// - apply pullup resistors</span>00054 <span class="comment">// - any-edge interrupt triggering</span>00055 <span class="comment">// - enable interrupt</span>00056 00057 <span class="preprocessor"> #ifdef ENC0_SIGNAL</span>00058 <span class="preprocessor"></span> <span class="comment">// set interrupt pins to input and apply pullup resistor</span>00059 cbi(ENC0_PHASEA_DDR, ENC0_PHASEA_PIN);00060 sbi(ENC0_PHASEA_PORT, ENC0_PHASEA_PIN);00061 <span class="comment">// set encoder direction pin for input and apply pullup resistor</span>00062 cbi(ENC0_PHASEB_DDR, ENC0_PHASEB_PIN);00063 sbi(ENC0_PHASEB_PORT, ENC0_PHASEB_PIN);00064 <span class="comment">// configure interrupts for any-edge triggering</span>00065 sbi(ENC0_ICR, ENC0_ISCX0);00066 cbi(ENC0_ICR, ENC0_ISCX1);00067 <span class="comment">// enable interrupts</span>00068 sbi(IMSK, ENC0_INT); <span class="comment">// ISMK is auto-defined in encoder.h</span>00069 <span class="preprocessor"> #endif</span>00070 <span class="preprocessor"></span><span class="preprocessor"> #ifdef ENC1_SIGNAL</span>00071 <span class="preprocessor"></span> <span class="comment">// set interrupt pins to input and apply pullup resistor</span>00072 cbi(ENC1_PHASEA_DDR, ENC1_PHASEA_PIN);00073 sbi(ENC1_PHASEA_PORT, ENC1_PHASEA_PIN);00074 <span class="comment">// set encoder direction pin for input and apply pullup resistor</span>00075 cbi(ENC1_PHASEB_DDR, ENC1_PHASEB_PIN);00076 sbi(ENC1_PHASEB_PORT, ENC1_PHASEB_PIN);00077 <span class="comment">// configure interrupts for any-edge triggering</span>00078 sbi(ENC1_ICR, ENC1_ISCX0);00079 cbi(ENC1_ICR, ENC1_ISCX1);00080 <span class="comment">// enable interrupts</span>00081 sbi(IMSK, ENC1_INT); <span class="comment">// ISMK is auto-defined in encoder.h</span>00082 <span class="preprocessor"> #endif</span>00083 <span class="preprocessor"></span><span class="preprocessor"> #ifdef ENC2_SIGNAL</span>00084 <span class="preprocessor"></span> <span class="comment">// set interrupt pins to input and apply pullup resistor</span>00085 cbi(ENC2_PHASEA_DDR, ENC2_PHASEA_PIN);00086 sbi(ENC2_PHASEA_PORT, ENC2_PHASEA_PIN);00087 <span class="comment">// set encoder direction pin for input and apply pullup resistor</span>00088 cbi(ENC2_PHASEB_DDR, ENC2_PHASEB_PIN);00089 sbi(ENC2_PHASEB_PORT, ENC2_PHASEB_PIN);00090 <span class="comment">// configure interrupts for any-edge triggering</span>00091 sbi(ENC2_ICR, ENC2_ISCX0);00092 cbi(ENC2_ICR, ENC2_ISCX1);00093 <span class="comment">// enable interrupts</span>00094 sbi(IMSK, ENC2_INT); <span class="comment">// ISMK is auto-defined in encoder.h</span>00095 <span class="preprocessor"> #endif</span>00096 <span class="preprocessor"></span><span class="preprocessor"> #ifdef ENC3_SIGNAL</span>00097 <span class="preprocessor"></span> <span class="comment">// set interrupt pins to input and apply pullup resistor</span>00098 cbi(ENC3_PHASEA_DDR, ENC3_PHASEA_PIN);00099 sbi(ENC3_PHASEA_PORT, ENC3_PHASEA_PIN);00100 <span class="comment">// set encoder direction pin for input and apply pullup resistor</span>00101 cbi(ENC3_PHASEB_DDR, ENC3_PHASEB_PIN);00102 sbi(ENC3_PHASEB_PORT, ENC3_PHASEB_PIN);00103 <span class="comment">// configure interrupts for any-edge triggering</span>00104 sbi(ENC3_ICR, ENC3_ISCX0);00105 cbi(ENC3_ICR, ENC3_ISCX1);00106 <span class="comment">// enable interrupts</span>00107 sbi(IMSK, ENC3_INT); <span class="comment">// ISMK is auto-defined in encoder.h</span>00108 <span class="preprocessor"> #endif</span>00109 <span class="preprocessor"></span> 00110 <span class="comment">// enable global interrupts</span>00111 sei();00112 }00113 00114 <span class="comment">// encoderOff() disables hardware and stops encoder position updates</span><a name="l00115"></a><a class="code" href="encoder_8h.html#a3">00115</a> <span class="keywordtype">void</span> <a class="code" href="encoder_8c.html#a2">encoderOff</a>(<span class="keywordtype">void</span>)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -