📄 servo_8h-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: servo.h Source File</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>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>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'servo.h'</span>00005 <span class="comment">// Title : Interrupt-driven RC Servo function library</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002</span>00007 <span class="comment">// Created : 7/31/2002</span>00008 <span class="comment">// Revised : 8/02/2002</span>00009 <span class="comment">// Version : 1.0</span>00010 <span class="comment">// Target MCU : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span><span class="comment"></span>00013 <span class="comment">/// \ingroup driver_sw</span>00014 <span class="comment">/// \defgroup servo Interrupt-driven RC Servo Function Library (servo.c)</span>00015 <span class="comment">/// \code #include "servo.h" \endcode</span>00016 <span class="comment">/// \par Overview</span>00017 <span class="comment">/// This code allows you to drive up to 8 RC servos from any</span>00018 <span class="comment">/// combination of ports and pins on the AVR processor. Using interrupts,</span>00019 <span class="comment">/// this code continuously sends control signals to the servo to maintain</span>00020 <span class="comment">/// position even while your code is doing other work.</span>00021 <span class="comment">///</span>00022 <span class="comment">/// The servoInit and servoOff effectively turn on and turn off servo</span>00023 <span class="comment">/// control. When you run ServoInit, it automatically assigns each</span>00024 <span class="comment">/// "channel" of servo control to be output on the SERVO_DEFAULT_PORT.</span>00025 <span class="comment">/// One "channel" of servo control can control one servo and must be</span>00026 <span class="comment">/// assigned single I/O pin for output.</span>00027 <span class="comment">///</span>00028 <span class="comment">/// If you're using all eight channels (SERVO_NUM_CHANNELS = 8), then</span>00029 <span class="comment">/// then by default the code will use SERVO_DEFAULT_PORT pins 0-7.</span>00030 <span class="comment">/// If you're only using four channels, then pins 0-3 will be used by</span>00031 <span class="comment">/// default.</span>00032 <span class="comment">///</span>00033 <span class="comment">/// The command servoSetChannelIO(channel, port, pin) allows you to</span>00034 <span class="comment">/// reassign the output of any channel to any port and I/O pin you</span>00035 <span class="comment">/// choose. For exampe, if you have an RC servo connected to PORTC, pin 6,</span>00036 <span class="comment">/// and you wish to use channel 2 to control it, use:</span>00037 <span class="comment">///</span>00038 <span class="comment">/// servoSerChannelIO( 2, _SFR_IO_ADDR(PORTC), 6)</span>00039 <span class="comment">///</span>00040 <span class="comment">/// (NOTE: you must include the "_SRF_IO_ADDR()" part around your port)</span>00041 <span class="comment">///</span>00042 <span class="comment">/// The servoSetPostion and servoGetPosition commands allow you to command</span>00043 <span class="comment">/// a given servo to your desired position. The position you request must</span>00044 <span class="comment">/// lie between the SERVO_MIN and SERVO_MAX limit you defined.</span>00045 <span class="comment">///</span>00046 <span class="comment">/// \WARNING: This servo library has been tested to work without issue on</span>00047 <span class="comment">/// several different AVR processors and with several different brands/kinds</span>00048 <span class="comment">/// of servos. However:</span>00049 <span class="comment">/// - Proper output duty cylces are dependent upon a user calibation and</span>00050 <span class="comment">/// configuration.</span>00051 <span class="comment">/// - IF YOUR SERVOS ARE EXCEPTIONALLY POWERFUL, AN ERRONEOUS OUTPUT DUTY</span>00052 <span class="comment">/// CYCLE GENERATED FROM THIS CODE OR ANY OTHER SOURCE CAN DAMAGE YOUR</span>00053 <span class="comment">/// SERVO'S INTERNAL DRIVER CHIP OR ITS GEARS!</span>00054 <span class="comment">/// - I have never experienced any servo damage from erroneous control signal</span>00055 <span class="comment">/// input, but it is possible.</span>00056 <span class="comment"></span><span class="comment">//</span>00057 <span class="comment">// This code is distributed under the GNU Public License</span>00058 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00059 <span class="comment">//</span>00060 <span class="comment">//*****************************************************************************</span>00061 00062 <span class="preprocessor">#ifndef SERVO_H</span>00063 <span class="preprocessor"></span><span class="preprocessor">#define SERVO_H</span>00064 <span class="preprocessor"></span>00065 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00066 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>00067 00068 <span class="comment">// include configuration</span>00069 <span class="preprocessor">#include "<a class="code" href="servoconf_8h.html">servoconf.h</a>"</span>00070 00071 <span class="keyword">typedef</span> <span class="keyword">struct </span>struct_ServoChannel00072 { 00073 <span class="comment">// hardware I/O port and pin for this channel</span>00074 u08 port;00075 u08 pin;00076 <span class="comment">// PWM duty setting which corresponds to servo position</span>00077 u16 duty;00078 } ServoChannelType;00079 00080 <span class="comment">// functions</span>00081 00082 <span class="comment">// initializes servo system</span>00083 <span class="comment">// You must run this to begin servo control</span>00084 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a4">servoInit</a>(<span class="keywordtype">void</span>);00085 00086 <span class="comment">// turns off servo system</span>00087 <span class="comment">// This stops controlling the servos and</span>00088 <span class="comment">// returns control of the SERVOPORT to your code</span>00089 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a5">servoOff</a>(<span class="keywordtype">void</span>);00090 00091 <span class="comment">// set the port and I/O pin you wish to use for a given channel</span>00092 <span class="comment">// If you do not assign a port and I/O pin for a channel (ie. you don't</span>00093 <span class="comment">// use this command) then all output will be done through the</span>00094 <span class="comment">// SERVO_DEFAULT_PORT. See above definition of SERVO_DEFAULT_PORT.</span>00095 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a6">servoSetChannelIO</a>(u08 channel, u08 port, u08 pin);00096 00097 <span class="comment">// set and get servo position on a given channel </span>00098 <span class="comment">// servoSetPosition() commands the servo on <channel> to the position you</span>00099 <span class="comment">// desire. The position input must lie between 0 and POSITION_MAX and</span>00100 <span class="comment">// will be automatically scaled to raw positions between SERVO_MIN and</span>00101 <span class="comment">// SERVO_MAX</span>00102 <span class="comment">// servoGetPosition() returns the most recently set postition of the</span>00103 <span class="comment">// servo on <channel>. The return value will be scaled 0->POSITION_MAX</span>00104 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a7">servoSetPosition</a>(u08 channel, u08 position);00105 u08 <a class="code" href="servo_8c.html#a8">servoGetPosition</a>(u08 channel);00106 00107 <span class="comment">// set and get raw servo position on a given channel</span>00108 <span class="comment">// Works like non-raw commands but position is not scaled. Position must</span>00109 <span class="comment">// be between SERVO_MIN and SERVO_MAX</span>00110 <span class="keywordtype">void</span> <a class="code" href="servo_8c.html#a9">servoSetPositionRaw</a>(u08 channel, u16 position);00111 u16 <a class="code" href="servo_8c.html#a10">servoGetPositionRaw</a>(u08 channel);00112 00113 <span class="comment">// servo interrupt service routine</span>00114 <span class="keywordtype">void</span> servoService(<span class="keywordtype">void</span>);00115 00116 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:55 2005 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -