| 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: servo.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 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> |
||
| 8 | <h1>servo.h</h1><a href="servo_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file servo.h \brief Interrupt-driven RC Servo function library. */</span> |
||
| 9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 10 | 00003 <span class="comment">//</span> |
||
| 11 | 00004 <span class="comment">// File Name : 'servo.h'</span> |
||
| 12 | 00005 <span class="comment">// Title : Interrupt-driven RC Servo function library</span> |
||
| 13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span> |
||
| 14 | 00007 <span class="comment">// Created : 7/31/2002</span> |
||
| 15 | 00008 <span class="comment">// Revised : 8/02/2002</span> |
||
| 16 | 00009 <span class="comment">// Version : 1.0</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_sw</span> |
||
| 21 | 00014 <span class="comment">/// \defgroup servo Interrupt-driven RC Servo Function Library (servo.c)</span> |
||
| 22 | 00015 <span class="comment">/// \code #include "servo.h" \endcode</span> |
||
| 23 | 00016 <span class="comment">/// \par Overview</span> |
||
| 24 | 00017 <span class="comment">/// This code allows you to drive up to 8 RC servos from any</span> |
||
| 25 | 00018 <span class="comment">/// combination of ports and pins on the AVR processor. Using interrupts,</span> |
||
| 26 | 00019 <span class="comment">/// this code continuously sends control signals to the servo to maintain</span> |
||
| 27 | 00020 <span class="comment">/// position even while your code is doing other work.</span> |
||
| 28 | 00021 <span class="comment">///</span> |
||
| 29 | 00022 <span class="comment">/// The servoInit and servoOff effectively turn on and turn off servo</span> |
||
| 30 | 00023 <span class="comment">/// control. When you run ServoInit, it automatically assigns each</span> |
||
| 31 | 00024 <span class="comment">/// "channel" of servo control to be output on the SERVO_DEFAULT_PORT.</span> |
||
| 32 | 00025 <span class="comment">/// One "channel" of servo control can control one servo and must be</span> |
||
| 33 | 00026 <span class="comment">/// assigned single I/O pin for output.</span> |
||
| 34 | 00027 <span class="comment">///</span> |
||
| 35 | 00028 <span class="comment">/// If you're using all eight channels (SERVO_NUM_CHANNELS = 8), then</span> |
||
| 36 | 00029 <span class="comment">/// then by default the code will use SERVO_DEFAULT_PORT pins 0-7.</span> |
||
| 37 | 00030 <span class="comment">/// If you're only using four channels, then pins 0-3 will be used by</span> |
||
| 38 | 00031 <span class="comment">/// default.</span> |
||
| 39 | 00032 <span class="comment">///</span> |
||
| 40 | 00033 <span class="comment">/// The command servoSetChannelIO(channel, port, pin) allows you to</span> |
||
| 41 | 00034 <span class="comment">/// reassign the output of any channel to any port and I/O pin you</span> |
||
| 42 | 00035 <span class="comment">/// choose. For exampe, if you have an RC servo connected to PORTC, pin 6,</span> |
||
| 43 | 00036 <span class="comment">/// and you wish to use channel 2 to control it, use:</span> |
||
| 44 | 00037 <span class="comment">///</span> |
||
| 45 | 00038 <span class="comment">/// servoSerChannelIO( 2, _SFR_IO_ADDR(PORTC), 6)</span> |
||
| 46 | 00039 <span class="comment">///</span> |
||
| 47 | 00040 <span class="comment">/// (NOTE: you must include the "_SRF_IO_ADDR()" part around your port)</span> |
||
| 48 | 00041 <span class="comment">///</span> |
||
| 49 | 00042 <span class="comment">/// The servoSetPostion and servoGetPosition commands allow you to command</span> |
||
| 50 | 00043 <span class="comment">/// a given servo to your desired position. The position you request must</span> |
||
| 51 | 00044 <span class="comment">/// lie between the SERVO_MIN and SERVO_MAX limit you defined.</span> |
||
| 52 | 00045 <span class="comment">///</span> |
||
| 53 | 00046 <span class="comment">/// \WARNING: This servo library has been tested to work without issue on</span> |
||
| 54 | 00047 <span class="comment">/// several different AVR processors and with several different brands/kinds</span> |
||
| 55 | 00048 <span class="comment">/// of servos. However:</span> |
||
| 56 | 00049 <span class="comment">/// - Proper output duty cylces are dependent upon a user calibation and</span> |
||
| 57 | 00050 <span class="comment">/// configuration.</span> |
||
| 58 | 00051 <span class="comment">/// - IF YOUR SERVOS ARE EXCEPTIONALLY POWERFUL, AN ERRONEOUS OUTPUT DUTY</span> |
||
| 59 | 00052 <span class="comment">/// CYCLE GENERATED FROM THIS CODE OR ANY OTHER SOURCE CAN DAMAGE YOUR</span> |
||
| 60 | 00053 <span class="comment">/// SERVO'S INTERNAL DRIVER CHIP OR ITS GEARS!</span> |
||
| 61 | 00054 <span class="comment">/// - I have never experienced any servo damage from erroneous control signal</span> |
||
| 62 | 00055 <span class="comment">/// input, but it is possible.</span> |
||
| 63 | 00056 <span class="comment"></span><span class="comment">//</span> |
||
| 64 | 00057 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 65 | 00058 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 66 | 00059 <span class="comment">//</span> |
||
| 67 | 00060 <span class="comment">//*****************************************************************************</span> |
||
| 68 | 00061 |
||
| 69 | 00062 <span class="preprocessor">#ifndef SERVO_H</span> |
||
| 70 | 00063 <span class="preprocessor"></span><span class="preprocessor">#define SERVO_H</span> |
||
| 71 | 00064 <span class="preprocessor"></span> |
||
| 72 | 00065 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
| 73 | 00066 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span> |
||
| 74 | 00067 |
||
| 75 | 00068 <span class="comment">// include configuration</span> |
||
| 76 | 00069 <span class="preprocessor">#include "<a class="code" href="servoconf_8h.html">servoconf.h</a>"</span> |
||
| 77 | 00070 |
||
| 78 | 00071 <span class="keyword">typedef</span> <span class="keyword">struct </span>struct_ServoChannel |
||
| 79 | 00072 { |
||
| 80 | 00073 <span class="comment">// hardware I/O port and pin for this channel</span> |
||
| 81 | 00074 u08 port; |
||
| 82 | 00075 u08 pin; |
||
| 83 | 00076 <span class="comment">// PWM duty setting which corresponds to servo position</span> |
||
| 84 | 00077 u16 duty; |
||
| 85 | 00078 } ServoChannelType; |
||
| 86 | 00079 |
||
| 87 | 00080 <span class="comment">// functions</span> |
||
| 88 | 00081 |
||
| 89 | 00082 <span class="comment">// initializes servo system</span> |
||
| 90 | 00083 <span class="comment">// You must run this to begin servo control</span> |
||
| 91 | 00084 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a4">servoInit</a>(<span class="keywordtype">void</span>); |
||
| 92 | 00085 |
||
| 93 | 00086 <span class="comment">// turns off servo system</span> |
||
| 94 | 00087 <span class="comment">// This stops controlling the servos and</span> |
||
| 95 | 00088 <span class="comment">// returns control of the SERVOPORT to your code</span> |
||
| 96 | 00089 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a5">servoOff</a>(<span class="keywordtype">void</span>); |
||
| 97 | 00090 |
||
| 98 | 00091 <span class="comment">// set the port and I/O pin you wish to use for a given channel</span> |
||
| 99 | 00092 <span class="comment">// If you do not assign a port and I/O pin for a channel (ie. you don't</span> |
||
| 100 | 00093 <span class="comment">// use this command) then all output will be done through the</span> |
||
| 101 | 00094 <span class="comment">// SERVO_DEFAULT_PORT. See above definition of SERVO_DEFAULT_PORT.</span> |
||
| 102 | 00095 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a6">servoSetChannelIO</a>(u08 channel, u08 port, u08 pin); |
||
| 103 | 00096 |
||
| 104 | 00097 <span class="comment">// set and get servo position on a given channel </span> |
||
| 105 | 00098 <span class="comment">// servoSetPosition() commands the servo on <channel> to the position you</span> |
||
| 106 | 00099 <span class="comment">// desire. The position input must lie between 0 and POSITION_MAX and</span> |
||
| 107 | 00100 <span class="comment">// will be automatically scaled to raw positions between SERVO_MIN and</span> |
||
| 108 | 00101 <span class="comment">// SERVO_MAX</span> |
||
| 109 | 00102 <span class="comment">// servoGetPosition() returns the most recently set postition of the</span> |
||
| 110 | 00103 <span class="comment">// servo on <channel>. The return value will be scaled 0->POSITION_MAX</span> |
||
| 111 | 00104 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a7">servoSetPosition</a>(u08 channel, u08 position); |
||
| 112 | 00105 u08 <a class="code" href="servo_8c.html#a8">servoGetPosition</a>(u08 channel); |
||
| 113 | 00106 |
||
| 114 | 00107 <span class="comment">// set and get raw servo position on a given channel</span> |
||
| 115 | 00108 <span class="comment">// Works like non-raw commands but position is not scaled. Position must</span> |
||
| 116 | 00109 <span class="comment">// be between SERVO_MIN and SERVO_MAX</span> |
||
| 117 | 00110 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a9">servoSetPositionRaw</a>(u08 channel, u16 position); |
||
| 118 | 00111 u16 <a class="code" href="servo_8c.html#a10">servoGetPositionRaw</a>(u08 channel); |
||
| 119 | 00112 |
||
| 120 | 00113 <span class="comment">// servo interrupt service routine</span> |
||
| 121 | 00114 <span class="keywordtype">void</span> servoService(<span class="keywordtype">void</span>); |
||
| 122 | 00115 |
||
| 123 | 00116 <span class="preprocessor">#endif</span> |
||
| 124 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by |
||
| 125 | <a href="http://www.doxygen.org/index.html"> |
||
| 126 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 127 | </body> |
||
| 128 | </html> |
Powered by WebSVN v2.8.3