Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

servo.h

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

Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by  doxygen 1.4.2