Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
servos_ppm_hw.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2008 Mark Griffin
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
29 #ifndef SERVOS_PPM_HW_H
30 #define SERVOS_PPM_HW_H
31 
32 #include "std.h"
33 #include "LPC21xx.h"
34 #include "mcu_periph/sys_time.h"
35 
36 #include BOARD_CONFIG
37 
38 #define SERVOS_TICS_OF_USEC(s) CPU_TICKS_OF_USEC(s)
39 #define ChopServo(x,a,b) Chop(x, a, b)
40 
41 #define _PPM_NB_CHANNELS 8
43 #define Actuator(i) servos_values[i]
44 
45 #define ActuatorsCommit() {}
46 extern uint8_t servos_PPM_idx;
47 extern uint32_t servos_delay;
48 extern uint8_t ppm_pulse; /* 1=start of pulse, 0=end of pulse */
49 
50 /* define the ppm frame rate. 22msec is typical for JR/Graupner */
51 #define SERVO_REFRESH_TICS SERVOS_TICS_OF_USEC(22000)
52 /* define the ppm pulse width. 550usec is typical for JR/Graupner */
53 #define PPM_WIDTH SERVOS_TICS_OF_USEC(550)
54 
55 #define ACTUATORS_IT TIR_MR1I
56 #define ServosPPMMat_ISR() { \
57  if (servos_PPM_idx == 0) { \
58  servos_delay = SERVO_REFRESH_TICS; \
59  } \
60  if (servos_PPM_idx < _PPM_NB_CHANNELS ) { \
61  if (ppm_pulse) { \
62  T0MR1 += PPM_WIDTH; \
63  servos_delay -= PPM_WIDTH; \
64  } else { \
65  T0MR1 += servos_values[servos_PPM_idx] - PPM_WIDTH; \
66  servos_delay -= servos_values[servos_PPM_idx] - PPM_WIDTH; \
67  servos_PPM_idx++; \
68  } \
69  } else { /* servos_PPM_idx=_PPM_NB_CHANNELS */ \
70  if (ppm_pulse) { \
71  T0MR1 += PPM_WIDTH; \
72  servos_delay -= PPM_WIDTH; \
73  } else { \
74  servos_PPM_idx = 0; \
75  T0MR1 += servos_delay - PPM_WIDTH; \
76  } \
77  } \
78  if (!ppm_pulse) { \
79  /* lower clock pin */ \
80  T0EMR &= ~TEMR_EM1; \
81  } \
82  /* toggle ppm_pulse flag */ \
83  ppm_pulse ^= 1; \
84 }
85 #endif /* SERVOS_PPM_HW_H */
unsigned short uint16_t
Definition: types.h:16
uint8_t servos_PPM_idx
Definition: servos_ppm_hw.c:33
uint16_t servos_values[_PPM_NB_CHANNELS]
Definition: servos_4015_hw.c:8
#define _PPM_NB_CHANNELS
Definition: servos_ppm_hw.h:41
Architecture independent timing functions.
uint32_t servos_delay
unsigned long uint32_t
Definition: types.h:18
unsigned char uint8_t
Definition: types.h:14
uint8_t ppm_pulse
Definition: servos_ppm_hw.c:34