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