Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
servos_4015_hw.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2006 Antoine Drouin
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
#include "
subsystems/actuators.h
"
23
#include "
armVIC.h
"
24
25
#include "generated/airframe.h"
26
#include "
mcu_periph/sys_time.h
"
27
28
29
uint16_t
servos_values
[
_4015_NB_CHANNELS
];
30
31
#define PWMMR_SERV0 PWMMR5
32
#define PWMMR_SERV1 PWMMR2
33
#define PWMLER_LATCH_SERV0 PWMLER_LATCH5
34
#define PWMLER_LATCH_SERV1 PWMLER_LATCH2
35
#define PWMMCR_MRI_SERV0 PWMMCR_MR5I
36
#define PWMMCR_MRI_SERV1 PWMMCR_MR2I
37
#define PWMPCR_ENA_SERV0 PWMPCR_ENA5
38
#define PWMPCR_ENA_SERV1 PWMPCR_ENA2
39
#define PWMIR_MRI_SERV0 PWMIR_MR5I
40
#define PWMIR_MRI_SERV1 PWMIR_MR2I
41
42
#ifndef PWM_VIC_SLOT
43
#define PWM_VIC_SLOT 3
44
#endif
45
46
void
actuators_4015_init
(
void
)
47
{
48
/* PWM selected as IRQ */
49
VICIntSelect
&= ~
VIC_BIT
(
VIC_PWM
);
50
/* PWM interrupt enabled */
51
VICIntEnable
=
VIC_BIT
(
VIC_PWM
);
52
_VIC_CNTL
(
PWM_VIC_SLOT
) =
VIC_ENABLE
|
VIC_PWM
;
53
/* address of the ISR */
54
_VIC_ADDR
(
PWM_VIC_SLOT
) = (
uint32_t
)
PWM_ISR
;
55
/* PW5 pin (P0.21) used for PWM */
56
IO0DIR
|= _BV(SERV1_CLOCK_PIN);
57
IO1DIR
|= _BV(SERV1_DATA_PIN) | _BV(SERV1_RESET_PIN);
58
SERV1_CLOCK_PINSEL |= SERV1_CLOCK_PINSEL_VAL << SERV1_CLOCK_PINSEL_BIT;
59
60
/* set match5 to go of a long time from now */
61
PWMMR0
= 0XFFFFFF;
62
PWMMR_SERV1
= 0XFFF;
63
/* commit above change */
64
PWMLER
=
PWMLER_LATCH0
|
PWMLER_LATCH_SERV1
;
65
/* interrupt on PWMMR5 match */
66
PWMMCR
=
PWMMCR_MR0R
|
PWMMCR_MRI_SERV1
;
67
/* enable PWM5 ouptput */
68
PWMPCR
=
PWMPCR_ENA_SERV1
;
69
70
/* Prescaler */
71
PWMPR
= PWM_PRESCALER - 1;
72
73
/* enable PWM timer counter and PWM mode */
74
PWMTCR
=
PWMTCR_COUNTER_ENABLE
|
PWMTCR_PWM_ENABLE
;
75
/* Load failsafe values */
76
/* Set all servos at their midpoints */
77
/* compulsory for unaffected servos */
78
uint8_t
i;
79
for
(i = 0 ; i <
_4015_NB_CHANNELS
; i++) {
80
servos_values
[i] =
SERVOS_TICS_OF_USEC
(1500);
81
}
82
#ifdef SERVO_MOTOR
83
servos_values
[SERVO_MOTOR] =
SERVOS_TICS_OF_USEC
(SERVO_MOTOR_NEUTRAL);
84
#endif
85
#ifdef SERVO_MOTOR_LEFT
86
servos_values
[SERVO_MOTOR_LEFT] =
SERVOS_TICS_OF_USEC
(SERVO_MOTOR_LEFT_NEUTRAL);
87
#endif
88
#ifdef SERVO_MOTOR_RIGHT
89
servos_values
[SERVO_RIGHT_MOTOR] =
SERVOS_TICS_OF_USEC
(SERVO_MOTOR_RIGHT_NEUTRAL);
90
#endif
91
#ifdef SERVO_HATCH
92
servos_values
[SERVO_HATCH] =
SERVOS_TICS_OF_USEC
(SERVO_HATCH_NEUTRAL);
93
#endif
94
}
95
96
97
98
#define SERVO_REFRESH_TICS SERVOS_TICS_OF_USEC(25000)
99
100
101
static
uint8_t
servos_idx
= 0;
102
static
uint32_t
servos_delay
;
103
104
void
PWM_ISR
(
void
)
105
{
106
ISR_ENTRY
();
107
// LED_TOGGLE(2);
108
if
(
servos_idx
== 0) {
109
IO1CLR
= _BV(SERV1_RESET_PIN);
110
IO1SET
= _BV(SERV1_DATA_PIN);
111
PWMMR0
=
servos_values
[
servos_idx
];
112
servos_delay
=
SERVO_REFRESH_TICS
-
servos_values
[
servos_idx
];
113
PWMLER
=
PWMLER_LATCH0
;
114
servos_idx
++;
115
}
else
if
(
servos_idx
<
_4015_NB_CHANNELS
) {
116
IO1CLR
= _BV(SERV1_DATA_PIN);
117
PWMMR0
=
servos_values
[
servos_idx
];
118
servos_delay
-=
servos_values
[
servos_idx
];
119
PWMLER
=
PWMLER_LATCH0
;
120
servos_idx
++;
121
}
else
{
122
IO1SET
= _BV(SERV1_RESET_PIN);
123
PWMMR0
=
servos_delay
;
124
PWMLER
=
PWMLER_LATCH0
;
125
servos_idx
= 0;
126
}
127
/* clear the interrupt */
128
PWMIR
=
PWMIR_MRI_SERV1
;
129
VICVectAddr
= 0x00000000;
130
ISR_EXIT
();
131
}
uint16_t
unsigned short uint16_t
Definition:
types.h:16
VIC_PWM
#define VIC_PWM
Definition:
lpcVIC.h:76
PWMMCR_MRI_SERV1
#define PWMMCR_MRI_SERV1
Definition:
servos_4015_hw.c:36
servos_delay
static uint32_t servos_delay
Definition:
servos_4015_hw.c:102
PWMTCR
#define PWMTCR
Definition:
LPC21xx.h:95
PWMPCR
#define PWMPCR
Definition:
LPC21xx.h:107
armVIC.h
PWMIR_MRI_SERV1
#define PWMIR_MRI_SERV1
Definition:
servos_4015_hw.c:40
VICIntSelect
#define VICIntSelect
Definition:
LPC21xx.h:430
actuators_4015_init
void actuators_4015_init(void)
Definition:
servos_4015_hw.c:46
PWMLER_LATCH0
#define PWMLER_LATCH0
Definition:
lpcTMR.h:124
PWMMR0
#define PWMMR0
Definition:
LPC21xx.h:100
uint32_t
unsigned long uint32_t
Definition:
types.h:18
PWMIR
#define PWMIR
Definition:
LPC21xx.h:94
_4015_NB_CHANNELS
#define _4015_NB_CHANNELS
Definition:
servos_4015_hw.h:36
servos_idx
static uint8_t servos_idx
Definition:
servos_4015_hw.c:101
_VIC_ADDR
#define _VIC_ADDR(idx)
Definition:
armVIC.h:20
VIC_BIT
#define VIC_BIT(chan)
Definition:
lpcVIC.h:105
PWMMCR_MR0R
#define PWMMCR_MR0R
Definition:
lpcTMR.h:89
PWMMR_SERV1
#define PWMMR_SERV1
Definition:
servos_4015_hw.c:32
PWMLER
#define PWMLER
Definition:
LPC21xx.h:108
PWMMCR
#define PWMMCR
Definition:
LPC21xx.h:99
sys_time.h
Architecture independent timing functions.
SERVOS_TICS_OF_USEC
#define SERVOS_TICS_OF_USEC(s)
Definition:
actuators_pwm_arch.h:41
uint8_t
unsigned char uint8_t
Definition:
types.h:14
VICVectAddr
#define VICVectAddr
Definition:
LPC21xx.h:436
IO0DIR
#define IO0DIR
Definition:
LPC21xx.h:335
PWM_ISR
void PWM_ISR(void)
Definition:
servos_4015_hw.c:104
PWMPCR_ENA_SERV1
#define PWMPCR_ENA_SERV1
Definition:
servos_4015_hw.c:38
PWMLER_LATCH_SERV1
#define PWMLER_LATCH_SERV1
Definition:
servos_4015_hw.c:34
servos_values
uint16_t servos_values[_4015_NB_CHANNELS]
Definition:
servos_4015_hw.c:29
ISR_ENTRY
#define ISR_ENTRY()
Definition:
armVIC.h:40
ISR_EXIT
#define ISR_EXIT()
Definition:
armVIC.h:61
PWMTCR_COUNTER_ENABLE
#define PWMTCR_COUNTER_ENABLE
Definition:
lpcTMR.h:83
IO1CLR
#define IO1CLR
Definition:
LPC21xx.h:340
PWMPR
#define PWMPR
Definition:
LPC21xx.h:97
VIC_ENABLE
#define VIC_ENABLE
Definition:
lpcVIC.h:102
VICIntEnable
#define VICIntEnable
Definition:
LPC21xx.h:431
PWM_VIC_SLOT
#define PWM_VIC_SLOT
Definition:
servos_4015_hw.c:43
IO1SET
#define IO1SET
Definition:
LPC21xx.h:338
SERVO_REFRESH_TICS
#define SERVO_REFRESH_TICS
Definition:
servos_4015_hw.c:98
_VIC_CNTL
#define _VIC_CNTL(idx)
Definition:
armVIC.h:19
IO1DIR
#define IO1DIR
Definition:
LPC21xx.h:339
PWMTCR_PWM_ENABLE
#define PWMTCR_PWM_ENABLE
Definition:
lpcTMR.h:85
actuators.h
sw
airborne
arch
lpc21
subsystems
actuators
servos_4015_hw.c
Generated on Tue Feb 1 2022 13:51:13 for Paparazzi UAS by
1.8.17