Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
servos_4015_hw.c
Go to the documentation of this file.
1 #include "actuators.h"
2 #include "armVIC.h"
3 
4 #include "generated/airframe.h"
5 #include "mcu_periph/sys_time.h"
6 
7 
9 
10 #define PWMMR_SERV0 PWMMR5
11 #define PWMMR_SERV1 PWMMR2
12 #define PWMLER_LATCH_SERV0 PWMLER_LATCH5
13 #define PWMLER_LATCH_SERV1 PWMLER_LATCH2
14 #define PWMMCR_MRI_SERV0 PWMMCR_MR5I
15 #define PWMMCR_MRI_SERV1 PWMMCR_MR2I
16 #define PWMPCR_ENA_SERV0 PWMPCR_ENA5
17 #define PWMPCR_ENA_SERV1 PWMPCR_ENA2
18 #define PWMIR_MRI_SERV0 PWMIR_MR5I
19 #define PWMIR_MRI_SERV1 PWMIR_MR2I
20 
21 
22 void actuators_init ( void ) {
23  /* PWM selected as IRQ */
25  /* PWM interrupt enabled */
28  /* address of the ISR */
30  /* PW5 pin (P0.21) used for PWM */
31  IO0DIR |= _BV(SERV1_CLOCK_PIN);
32  IO1DIR |= _BV(SERV1_DATA_PIN) | _BV(SERV1_RESET_PIN);
34 
35  /* set match5 to go of a long time from now */
36  PWMMR0 = 0XFFFFFF;
37  PWMMR_SERV1 = 0XFFF;
38  /* commit above change */
40  /* interrupt on PWMMR5 match */
42  /* enable PWM5 ouptput */
44 
45  /* Prescaler */
46  PWMPR = PWM_PRESCALER-1;
47 
48  /* enable PWM timer counter and PWM mode */
50  /* Load failsafe values */
51  /* Set all servos at their midpoints */
52  /* compulsory for unaffected servos */
53  uint8_t i;
54  for( i=0 ; i < _4015_NB_CHANNELS ; i++ )
56 #ifdef SERVO_MOTOR
57  servos_values[SERVO_MOTOR] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_NEUTRAL);
58 #endif
59 #ifdef SERVO_MOTOR_LEFT
60  servos_values[SERVO_MOTOR_LEFT] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_LEFT_NEUTRAL);
61 #endif
62 #ifdef SERVO_MOTOR_RIGHT
63  servos_values[SERVO_RIGHT_MOTOR] = SERVOS_TICS_OF_USEC(SERVO_MOTOR_RIGHT_NEUTRAL);
64 #endif
65 #ifdef SERVO_HATCH
66  servos_values[SERVO_HATCH] = SERVOS_TICS_OF_USEC(SERVO_HATCH_NEUTRAL);
67 #endif
68 }
69 
70 
71 
72 #define SERVO_REFRESH_TICS SERVOS_TICS_OF_USEC(25000)
73 
74 
75 static uint8_t servos_idx = 0;
77 
78 void PWM_ISR ( void ) {
79  ISR_ENTRY();
80  // LED_TOGGLE(2);
81  if (servos_idx == 0) {
82  IO1CLR = _BV(SERV1_RESET_PIN);
83  IO1SET = _BV(SERV1_DATA_PIN);
87  servos_idx++;
88  }
89  else if (servos_idx < _4015_NB_CHANNELS) {
90  IO1CLR = _BV(SERV1_DATA_PIN);
94  servos_idx++;
95  }
96  else {
97  IO1SET = _BV(SERV1_RESET_PIN);
100  servos_idx = 0;
101  }
102  /* clear the interrupt */
104  VICVectAddr = 0x00000000;
105  ISR_EXIT();
106 }
#define VICIntSelect
Definition: LPC21xx.h:398
unsigned short uint16_t
Definition: types.h:16
#define IO1SET
Definition: LPC21xx.h:306
#define PWMPCR_ENA_SERV1
#define PWMIR
Definition: LPC21xx.h:94
#define PWMMCR_MRI_SERV1
#define PWMMR0
Definition: LPC21xx.h:100
#define VICVectAddr3
Definition: LPC21xx.h:409
#define SERV1_RESET_PIN
Definition: tiny_sim.h:50
#define PWMTCR
Definition: LPC21xx.h:95
#define PWMPCR
Definition: LPC21xx.h:107
#define SERVOS_TICS_OF_USEC(s)
#define VIC_PWM
Definition: lpcVIC.h:76
#define PWMMR_SERV1
#define PWMTCR_COUNTER_ENABLE
Definition: lpcTMR.h:83
#define _4015_NB_CHANNELS
#define PWMMCR
Definition: LPC21xx.h:99
Architecture independent timing functions.
#define SERV1_CLOCK_PINSEL_VAL
Definition: tiny_sim.h:45
#define PWMLER
Definition: LPC21xx.h:108
static uint8_t servos_idx
#define VICVectAddr
Definition: LPC21xx.h:404
unsigned long uint32_t
Definition: types.h:18
void actuators_init(void)
#define PWMMCR_MR0R
Definition: lpcTMR.h:89
#define SERV1_CLOCK_PINSEL_BIT
Definition: tiny_sim.h:46
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define IO0DIR
Definition: LPC21xx.h:303
#define PWMPR
Definition: LPC21xx.h:97
static uint32_t servos_delay
#define PWMIR_MRI_SERV1
#define PWMTCR_PWM_ENABLE
Definition: lpcTMR.h:85
#define SERVO_REFRESH_TICS
unsigned char uint8_t
Definition: types.h:14
#define PWMLER_LATCH0
Definition: lpcTMR.h:124
#define ISR_EXIT()
Definition: armVIC.h:61
void PWM_ISR(void)
#define VICIntEnable
Definition: LPC21xx.h:399
#define PWMLER_LATCH_SERV1
uint16_t servos_values[_4015_NB_CHANNELS]
Definition: servos_4015_hw.c:8
#define SERV1_CLOCK_PINSEL
Definition: tiny_sim.h:44
#define VICVectCntl3
Definition: LPC21xx.h:425
#define IO1CLR
Definition: LPC21xx.h:308
#define SERV1_CLOCK_PIN
Definition: tiny_sim.h:43
#define SERV1_DATA_PIN
Definition: tiny_sim.h:48
#define ISR_ENTRY()
Definition: armVIC.h:40
#define VIC_ENABLE
Definition: lpcVIC.h:102
#define IO1DIR
Definition: LPC21xx.h:307