Main Page   Modules   Data Structures   File List   Data Fields   Globals  

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 // NOTE: you need the latest version (3.2+) of the AVR-GCC compiler to use this
00014 //  function library.  Download it from http://www.avrfreaks.net/AVRGCC
00015 //
00016 // Description : This code allows you to drive up to 8 RC servos from any
00017 //      combination of ports and pins on the AVR processor. Using interrupts,
00018 //      this code continuously sends control signals to the servo to maintain
00019 //      position even while your code is doing other work.
00020 //
00021 //      The servoInit and servoOff effectively turn on and turn off servo
00022 //      control.  When you run ServoInit, it automatically assigns each
00023 //      "channel" of servo control to be output on the SERVO_DEFAULT_PORT.
00024 //      One "channel" of servo control can control one servo and must be
00025 //      assigned single I/O pin for output.
00026 //
00027 //      If you're using all eight channels (SERVO_NUM_CHANNELS = 8), then
00028 //      then by default the code will use SERVO_DEFAULT_PORT pins 0-7.
00029 //      If you're only using four channels, then pins 0-3 will be used by
00030 //      default.
00031 //
00032 //      The command servoSetChannelIO(channel, port, pin) allows you to
00033 //      reassign the output of any channel to any port and I/O pin you
00034 //      choose.  For exampe, if you have an RC servo connected to PORTC, pin 6,
00035 //      and you wish to use channel 2 to control it, use:
00036 //
00037 //      servoSerChannelIO( 2, _SFR_IO_ADDR(PORTC), 6)
00038 //
00039 //      (NOTE: you must include the "_SRF_IO_ADDR()" part around your port)
00040 //
00041 //      The servoSetPostion and servoGetPosition commands allow you to command
00042 //      a given servo to your desired position.  The position you request must
00043 //      lie between the SERVO_MIN and SERVO_MAX limit you defined.
00044 //
00045 // This code is distributed under the GNU Public License
00046 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00047 //
00048 //*****************************************************************************
00049 
00050 #ifndef SERVO_H
00051 #define SERVO_H
00052 
00053 #include "global.h"
00054 #include "timer.h"
00055 
00056 // include configuration
00057 #include "servoconf.h"
00058 
00059 typedef struct struct_ServoChannel
00060 {   
00061     // hardware I/O port and pin for this channel
00062     u08 port;
00063     u08 pin;
00064     // PWM duty setting which corresponds to servo position
00065     u16 duty;
00066 } ServoChannelType;
00067 
00068 // functions
00069 
00070 // initializes servo system
00071 //      You must run this to begin servo control
00072 void servoInit(void);
00073 
00074 // turns off servo system
00075 //      This stops controlling the servos and
00076 //      returns control of the SERVOPORT to your code
00077 void servoOff(void);
00078 
00079 // set the port and I/O pin you wish to use for a given channel
00080 //      If you do not assign a port and I/O pin for a channel (ie. you don't
00081 //      use this command) then all output will be done through the
00082 //      SERVO_DEFAULT_PORT.  See above definition of SERVO_DEFAULT_PORT.
00083 void servoSetChannelIO(u08 channel, u08 port, u08 pin);
00084 
00085 // set and get servo position on a given channel 
00086 //      servoSetPosition() commands the servo on <channel> to the position you
00087 //          desire.  The position input must lie between 0 and POSITION_MAX and
00088 //          will be automatically scaled to raw positions between SERVO_MIN and
00089 //          SERVO_MAX
00090 //      servoGetPosition() returns the most recently set postition of the
00091 //          servo on <channel>.  The return value will be scaled 0->POSITION_MAX
00092 void servoSetPosition(u08 channel, u08 position);
00093 u08 servoGetPosition(u08 channel);
00094 
00095 // set and get raw servo position on a given channel
00096 //      Works like non-raw commands but position is not scaled.  Position must
00097 //      be between SERVO_MIN and SERVO_MAX
00098 void servoSetPositionRaw(u08 channel, u16 position);
00099 u16 servoGetPositionRaw(u08 channel);
00100 
00101 // servo interrupt service routine
00102 void servoService(void);
00103 
00104 #endif

Generated on Sun Feb 22 19:12:31 2004 for Procyon AVRlib by doxygen1.3-rc2