The unified diff between revisions [be147b11..] and [9f05a1eb..] is displayed below. It can also be downloaded as a raw diff.

#
# old_revision [be147b11caac304fda1579ac71017eecc3bb79e0]
# new_revision [9f05a1eb606ea1c0421aa4a0b25b83b4fe4a20c8]
#
# patch "Makefile"
#  from [0d87a7bdf64f764dc4892656b9cd1e2613f05867]
#    to [33137b98e954e7abaca672f6ad561d1367b25d30]
# 
# patch "stick.c"
#  from [4870f5f016221d25b0d8a4d093fda5dbe0f0b30c]
#    to [57244f98d116ac872a524b6de2c760af161fd0a0]
# 
# patch "timer.c"
#  from [7f173b22d8e013f1c5ce08dfb04bb4cd59f5932c]
#    to [80f539706b746c7f6a4cbc52c6ebe93064f0b7f9]
# 
# patch "timer.h"
#  from [a1df137b32f7a24a94d0b016cb360bc10529bfa8]
#    to [22e6b547150be529a916f8f29060e07a0b1cd5a9]
#
============================================================
--- Makefile	0d87a7bdf64f764dc4892656b9cd1e2613f05867
+++ Makefile	33137b98e954e7abaca672f6ad561d1367b25d30
@@ -8,6 +8,7 @@ CSRCS+=thrust.c
 CSRCS+=thrust.c
 
 #PROJOPTS=-DUSE_UART -DSEND_DCM -DSTICK_DEBUG_CALIBRATE
+PROJOPTS=-DTIMER_CPPM
 
 COPTIM?=-O1
 CFLAGS=-march=armv4t -msoft-float $(COPTIM) -Wall -Werror -Wextra $(PROJOPTS)
============================================================
--- stick.c	4870f5f016221d25b0d8a4d093fda5dbe0f0b30c
+++ stick.c	57244f98d116ac872a524b6de2c760af161fd0a0
@@ -19,30 +19,30 @@
 #define TWO_PI 6.28318531f
 #define PI 3.14159265f
 
-#define MIN_X 14700
-#define MAX_X 29700
-#define CENTRE_X 22200
+#define MIN_X 8720
+#define MAX_X 23800
+#define CENTRE_X 16260
 
-#define MIN_Y 14700
-#define MAX_Y 29700
-#define CENTRE_Y 22200
+#define MIN_Y 8720
+#define MAX_Y 23800
+#define CENTRE_Y 16260
 
-#define MIN_Z 14700
-#define MAX_Z 29700
-#define CENTRE_Z 22200
+#define MIN_Z 8720
+#define MAX_Z 23800
+#define CENTRE_Z 16300
 
-#define MIN_THR 15700
-#define MAX_THR 29700
+#define MIN_THR 9720
+#define MAX_THR 23750
 
-#define MIN_REAL_THR 14700
+#define MIN_REAL_THR 8720
 
 #define CENTRE_ZONE 100
 
-/* With new TX firmware:
+/* With new TX firmware, CPPM:
  *             x      y    thr      z
- * centre: 22192, 22222, 14687, 22196
- * min:    14686, 14701, 14686, 14687
- * max:    29740, 29740, 29725, 29725
+ * centre: 16260, 16258, 16000, 16300
+ * min:     8720,  8718, 8720,  8722 
+ * max:    23790, 23817, 23750, 23803
  */
 
 /* 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);
 
 #ifdef STICK_DEBUG_CALIBRATE
-		if ((stick_counter % 20) == 0)
+		if ((stick_counter % 100) == 0)
 			stick_debug_calibrate();
 #endif
 
============================================================
--- timer.c	7f173b22d8e013f1c5ce08dfb04bb4cd59f5932c
+++ timer.c	80f539706b746c7f6a4cbc52c6ebe93064f0b7f9
@@ -61,8 +61,14 @@ volatile unsigned int timer1_width[4];
 volatile unsigned int timer1_rising[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"))) timer1_interrupt_handler(void);
 
@@ -174,6 +180,18 @@ void __attribute__((interrupt("IRQ"))) t
 			timer1_rising[0] = T1WREG(CR0);
 		} else {
 			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)) {
@@ -212,7 +230,15 @@ bool timer_valid(int channel) {
 	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) {
 	unsigned int time;
 	unsigned int chtime[4];
 	int i;
@@ -225,6 +251,7 @@ bool timer_allvalid(void) {
 			return FALSE;
 	return TRUE;
 }
+#endif
 
 void timer_set_pwm_value(int channel, int value)
 {
============================================================
--- timer.h	a1df137b32f7a24a94d0b016cb360bc10529bfa8
+++ timer.h	22e6b547150be529a916f8f29060e07a0b1cd5a9
@@ -17,10 +17,12 @@
 #define PWM_PERIOD ((4*PWM_MAX)+1)
 
 #define TIMER_INPUT_TIMEOUT (TIMER_PCLK/10)
+#define TIMER_CPPM_SYNC 40000
 
 #define TIMER_CH(x) (timer_map[x])
 
 extern volatile unsigned int timer1_width[];
+extern volatile unsigned int timer1_cppm[];
 extern unsigned int timer_map[];
 
 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_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)])
+#endif
 #endif /* __TIMER_H */