Implement CPPM reception. Keep it as an option for now.
Recalibrate the radio, as the timings have changed. And, it seems a couple of channels are now swapped with the new radio. Or rather, unswapped. So fix the channel map to match.
This commit is contained in:
1
Makefile
1
Makefile
@@ -8,6 +8,7 @@ CSRCS+=fisqrt.c stick.c trig.c motor.c led.c watchdog.c panic.c status.c
|
|||||||
CSRCS+=thrust.c
|
CSRCS+=thrust.c
|
||||||
|
|
||||||
#PROJOPTS=-DUSE_UART -DSEND_DCM -DSTICK_DEBUG_CALIBRATE
|
#PROJOPTS=-DUSE_UART -DSEND_DCM -DSTICK_DEBUG_CALIBRATE
|
||||||
|
PROJOPTS=-DTIMER_CPPM
|
||||||
|
|
||||||
COPTIM?=-O1
|
COPTIM?=-O1
|
||||||
CFLAGS=-march=armv4t -msoft-float $(COPTIM) -Wall -Werror -Wextra $(PROJOPTS)
|
CFLAGS=-march=armv4t -msoft-float $(COPTIM) -Wall -Werror -Wextra $(PROJOPTS)
|
||||||
|
|||||||
34
stick.c
34
stick.c
@@ -19,30 +19,30 @@
|
|||||||
#define TWO_PI 6.28318531f
|
#define TWO_PI 6.28318531f
|
||||||
#define PI 3.14159265f
|
#define PI 3.14159265f
|
||||||
|
|
||||||
#define MIN_X 14700
|
#define MIN_X 8720
|
||||||
#define MAX_X 29700
|
#define MAX_X 23800
|
||||||
#define CENTRE_X 22200
|
#define CENTRE_X 16260
|
||||||
|
|
||||||
#define MIN_Y 14700
|
#define MIN_Y 8720
|
||||||
#define MAX_Y 29700
|
#define MAX_Y 23800
|
||||||
#define CENTRE_Y 22200
|
#define CENTRE_Y 16260
|
||||||
|
|
||||||
#define MIN_Z 14700
|
#define MIN_Z 8720
|
||||||
#define MAX_Z 29700
|
#define MAX_Z 23800
|
||||||
#define CENTRE_Z 22200
|
#define CENTRE_Z 16300
|
||||||
|
|
||||||
#define MIN_THR 15700
|
#define MIN_THR 9720
|
||||||
#define MAX_THR 29700
|
#define MAX_THR 23750
|
||||||
|
|
||||||
#define MIN_REAL_THR 14700
|
#define MIN_REAL_THR 8720
|
||||||
|
|
||||||
#define CENTRE_ZONE 100
|
#define CENTRE_ZONE 100
|
||||||
|
|
||||||
/* With new TX firmware:
|
/* With new TX firmware, CPPM:
|
||||||
* x y thr z
|
* x y thr z
|
||||||
* centre: 22192, 22222, 14687, 22196
|
* centre: 16260, 16258, 16000, 16300
|
||||||
* min: 14686, 14701, 14686, 14687
|
* min: 8720, 8718, 8720, 8722
|
||||||
* max: 29740, 29740, 29725, 29725
|
* max: 23790, 23817, 23750, 23803
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Full scale is a roll/pitch angle of 30 degrees from the vertical */
|
/* Full scale is a roll/pitch angle of 30 degrees from the vertical */
|
||||||
@@ -112,7 +112,7 @@ void stick_input(void) {
|
|||||||
z = timer_input(3);
|
z = timer_input(3);
|
||||||
|
|
||||||
#ifdef STICK_DEBUG_CALIBRATE
|
#ifdef STICK_DEBUG_CALIBRATE
|
||||||
if ((stick_counter % 20) == 0)
|
if ((stick_counter % 100) == 0)
|
||||||
stick_debug_calibrate();
|
stick_debug_calibrate();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
29
timer.c
29
timer.c
@@ -61,7 +61,13 @@
|
|||||||
volatile unsigned int timer1_rising[4];
|
volatile unsigned int timer1_rising[4];
|
||||||
volatile unsigned int timer1_width[4];
|
volatile unsigned int timer1_width[4];
|
||||||
|
|
||||||
unsigned int timer_map[] = {0, 3, 2, 1};
|
#ifdef TIMER_CPPM
|
||||||
|
volatile unsigned int timer1_cppm[8];
|
||||||
|
volatile unsigned int timer1_cppm_chan = 0;
|
||||||
|
volatile unsigned int timer1_sync_timestamp;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned int timer_map[] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||||
|
|
||||||
void __attribute__((interrupt("IRQ"))) timer_interrupt_handler(void);
|
void __attribute__((interrupt("IRQ"))) timer_interrupt_handler(void);
|
||||||
void __attribute__((interrupt("IRQ"))) timer1_interrupt_handler(void);
|
void __attribute__((interrupt("IRQ"))) timer1_interrupt_handler(void);
|
||||||
@@ -174,6 +180,18 @@ void __attribute__((interrupt("IRQ"))) timer1_interrupt_handler(void)
|
|||||||
timer1_rising[0] = T1WREG(CR0);
|
timer1_rising[0] = T1WREG(CR0);
|
||||||
} else {
|
} else {
|
||||||
timer1_width[0] = T1WREG(CR0) - timer1_rising[0];
|
timer1_width[0] = T1WREG(CR0) - timer1_rising[0];
|
||||||
|
#ifdef TIMER_CPPM
|
||||||
|
if (timer1_width[0] > TIMER_CPPM_SYNC) {
|
||||||
|
timer1_cppm_chan = 0;
|
||||||
|
timer1_sync_timestamp = timer1_rising[0];
|
||||||
|
} else {
|
||||||
|
if (timer1_cppm_chan < 8) {
|
||||||
|
timer1_cppm[timer1_cppm_chan] =
|
||||||
|
timer1_width[0];
|
||||||
|
timer1_cppm_chan++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ir & (1<<5)) {
|
if (ir & (1<<5)) {
|
||||||
@@ -212,6 +230,14 @@ bool timer_valid(int channel) {
|
|||||||
return (time - chtime) < TIMER_INPUT_TIMEOUT;
|
return (time - chtime) < TIMER_INPUT_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TIMER_CPPM
|
||||||
|
bool timer_allvalid(void) {
|
||||||
|
/* Be careful here to ensure that this can't be in the past */
|
||||||
|
unsigned int chtime = timer1_sync_timestamp; /* Atomic */
|
||||||
|
unsigned int time = T1WREG(TC); /* Atomic */
|
||||||
|
return (time - chtime) < TIMER_INPUT_TIMEOUT;
|
||||||
|
}
|
||||||
|
#else
|
||||||
bool timer_allvalid(void) {
|
bool timer_allvalid(void) {
|
||||||
unsigned int time;
|
unsigned int time;
|
||||||
unsigned int chtime[4];
|
unsigned int chtime[4];
|
||||||
@@ -225,6 +251,7 @@ bool timer_allvalid(void) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void timer_set_pwm_value(int channel, int value)
|
void timer_set_pwm_value(int channel, int value)
|
||||||
{
|
{
|
||||||
|
|||||||
6
timer.h
6
timer.h
@@ -17,10 +17,12 @@
|
|||||||
#define PWM_PERIOD ((4*PWM_MAX)+1)
|
#define PWM_PERIOD ((4*PWM_MAX)+1)
|
||||||
|
|
||||||
#define TIMER_INPUT_TIMEOUT (TIMER_PCLK/10)
|
#define TIMER_INPUT_TIMEOUT (TIMER_PCLK/10)
|
||||||
|
#define TIMER_CPPM_SYNC 40000
|
||||||
|
|
||||||
#define TIMER_CH(x) (timer_map[x])
|
#define TIMER_CH(x) (timer_map[x])
|
||||||
|
|
||||||
extern volatile unsigned int timer1_width[];
|
extern volatile unsigned int timer1_width[];
|
||||||
|
extern volatile unsigned int timer1_cppm[];
|
||||||
extern unsigned int timer_map[];
|
extern unsigned int timer_map[];
|
||||||
|
|
||||||
void init_timer(void);
|
void init_timer(void);
|
||||||
@@ -35,5 +37,9 @@ bool timer_allvalid(void);
|
|||||||
#define timer_delay_us(x) timer_delay_clocks((x)*TIMER_US)
|
#define timer_delay_us(x) timer_delay_clocks((x)*TIMER_US)
|
||||||
#define timer_delay_ms(x) timer_delay_clocks((x)*TIMER_MS)
|
#define timer_delay_ms(x) timer_delay_clocks((x)*TIMER_MS)
|
||||||
|
|
||||||
|
#ifdef TIMER_CPPM
|
||||||
|
#define timer_input(ch) (timer1_cppm[TIMER_CH(ch)])
|
||||||
|
#else
|
||||||
#define timer_input(ch) (timer1_width[TIMER_CH(ch)])
|
#define timer_input(ch) (timer1_width[TIMER_CH(ch)])
|
||||||
|
#endif
|
||||||
#endif /* __TIMER_H */
|
#endif /* __TIMER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user