Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1198 - 1
/*********************************************************************/
2
/*                                                                                                                                       */
3
/*                               NG-Video 5,8GHz                                                                 */
4
/*                                                                                                                                       */
5
/*                              Copyright (C) 2011 - gebad                                                       */
6
/*                                                                                                                                       */
7
/*  This code is distributed under the GNU Public License                        */
8
/*      which can be found at http://www.gnu.org/licenses/gpl.txt                */
9
/*                                                                                                                                       */
10
/*      using                                                                                                                    */
11
/*! \file servo.c \brief Interrupt-driven RC Servo function library. */
12
/*                                                                                                                                       */
13
/*File Name     : 'servo.c'                                                                                              */
14
/*Title         : Interrupt-driven RC Servo function library                     */
15
/*Author                : Pascal Stang - Copyright (C) 2002                                      */
16
/*Created               : 7/31/2002                                                                                      */
17
/*Revised               : 8/02/2002                                                                                      */
18
/*Version               : 1.0                                                                                            */
19
/*Target MCU    : Atmel AVR Series                                                                       */
20
/*Editor Tabs   : 4                                                                                                      */
21
/*                                                                                                                                       */
22
/*ingroup driver_sw                                                                                                      */
23
/*defgroup servo Interrupt-driven RC Servo Function Library (servo.c)*/
24
/*code #include "servo.h" \endcode                                                                       */
25
/*par Overview                                                                                                           */
26
/*                                                                                                                                       */
27
/*This code is distributed under the GNU Public License                          */
28
/*which can be found at http://www.gnu.org/licenses/gpl.txt                      */
29
/*                                                                                                                                       */
30
/*********************************************************************/
31
 
32
#ifndef SERVO_H
33
#define SERVO_H
34
 
35
// The numbers below good for parallax servos at an F_CPU of 20.000MHz.
36
// Da einige Servo's auch eien Winkel von 180 grd zulassen, Wertebereich
37
// entgegen den sonst üblichen. Einschränkung mit default Kalibrierung
38
// auf 0,9ms (45) bis 2,1ms(45) gesetzt. Je nach Servo, entspricht einen
39
// Winkel von etwa 180grd
40
// Periode default 20ms
41
 
42
#define SERVO_MAX               211 // 2,7 ms bei prescaler 256, bei prescaler 64 SERVO_MAX * 4
43
#define SERVO_MIN               26      // 0,33ms bei prescaler 256, bei prescaler 64 SERVO_MIN * 4
44
#define SERVO_STEPS             255     // Servo-Schritte von links nach rechts, Anschlagkalibrierung spielt keine Rolle
45
#define SERVO_PRESCALER 256 // bei prescaler 256, bei prescaler 64 SERVO_PRESCALER / 4
46
#define STEPS_255               0       // Servo-Schritte von links nach rechts, Anschlagkalibrierung spielt keine Rolle
47
#define STEPS_1023              1       // Servo-Schritte von links nach rechts, Anschlagkalibrierung spielt keine Rolle
48
 
49
typedef struct //Servo-Konstante je nach Prescaler
50
{
51
  uint16_t max;
52
  uint16_t min;
53
  uint16_t steps;
54
  uint16_t prescaler;
55
} ServoConst_t;
56
 
57
typedef struct //struct_ServoChannel
58
{
59
  uint8_t  pin;                 // hardware I/O port and pin for this channel
60
  uint16_t duty;                // PWM duty setting which corresponds to servo position
61
  uint8_t  rev;                 // Parameter, wie on/off; reverse; range
62
  uint16_t min;                 // SERVO_MIN + Parameter min
63
  uint16_t max;                 // SERVO_MAX - Parameter max
64
  uint16_t mid_scaled;  // skalierte Servomitte
65
  int16_t  mid;                 // Servomitte = SERVO_STEPS/2 +/- x Schritte; bei Pescaler 256 wird nur uint8_t benötigt aber bei 64
66
} ServoChannelType;
67
 
68
uint8_t  sIdxSteps;     // 0 für 255 und 1 für 1023 Schritte; Prescaler 256 oder 64
69
 
70
// functions
71
 
72
// initializes servo system
73
//              You must run this to begin servo control
74
void servoInit(uint8_t servo_period);
75
 
76
// turns off servo system
77
//              This stops controlling the servos and
78
//              returns control of the SERVOPORT to your code
79
void servoOff(void);
80
 
81
// set servo position on a given channel 
82
//              servoSetPosition() commands the servo on <channel> to the position you
83
//                      desire.  The position input must lie between 0 and POSITION_MAX and
84
//                      will be automatically scaled to raw positions between SERVO_MIN and
85
//                      SERVO_MAX
86
void servoSetPosition(uint8_t channel, uint16_t position);
87
 
88
// set raw servo position on a given channel
89
//              Works like non-raw commands but position is not scaled.  Position must
90
//              be between SERVO_MIN and SERVO_MAX
91
void servoSetPositionRaw(uint8_t channel, uint16_t position);
92
// vor servoInit(), oder vor sei() ServoWerte mit servoSet...() initialisieren, einschließlich servoSetPosition(...)!
93
void servoSet_rev(uint8_t channel, uint8_t val);
94
void servoSet_min(uint8_t channel, uint16_t min);
95
void servoSet_max(uint8_t channel, uint16_t max);
96
void servoSet_mid(uint8_t channel, uint16_t mid);
97
uint16_t pw_us(uint16_t Steps); // gibt Zeit in µs bei x Servoschritte
98
uint16_t ServoSteps(void);      // gibt "Konstante" derzeitiger Servoschritte zürück
99
 
100
#endif /* SERVO_H */