/elec/quadcopter

To get this branch, use:
bzr branch http://bzr.ed.am/elec/quadcopter

« back to all changes in this revision

Viewing changes to test/receiver/pulse-width/main.ino

  • Committer: dan
  • Date: 2016-04-10 13:34:18 UTC
  • Revision ID: dan-20160410133418-tqb658tj3t1l5nch
updated ignores

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
// This program tries to measure the width of the signal pulses in
8
8
// microseconds.  It takes several measurements and prints it the average over
9
9
// serial.
10
 
//
11
 
// NOTES: Due to the way our receiver works (by varying the position of the
12
 
// rising edge of the pulse and keeping the falling edge fixed), it is
13
 
// sufficient for us to measure the pule width to determine the channel value
14
 
// (e.g., throttle position).  But it should be noted that this relies on a
15
 
// quirk of our receiver/transmitter and it is not truly measuring PPM.  Our
16
 
// next experiment is measuring PPM (../ppm-read).
 
10
 
17
11
 
18
12
// number of signal pulses to average
19
13
#define AVERAGE_SAMPLES 1
22
16
#define AVERAGE_DAMP 1
23
17
 
24
18
// graphic display
25
 
#define GRAPH 1
 
19
#define GRAPH 0
26
20
#define GRAPH_MIN 1000
27
21
#define GRAPH_MAX 2000
28
22
#define GRAPH_SIZE 30
64
58
        for( int a = 0; a < AVERAGE_SAMPLES; a++ )
65
59
                intervals[ a ] = 0;
66
60
 
67
 
#ifdef GRAPH
 
61
#if GRAPH
68
62
        // init graph
69
63
        char graph[ GRAPH_SIZE + 3 ];
70
64
        for( int a = 1; a < GRAPH_SIZE + 1; a++ )
77
71
        while( true )
78
72
        {
79
73
                // detect pulse falling-edge
 
74
                noInterrupts();
80
75
                unsigned long pulse_on = _new_pulse_on;
81
76
                unsigned long pulse_off = _new_pulse_off;
 
77
                interrupts();
 
78
                
82
79
                bool got_pulse = false;
83
 
                if( pulse_off > last_pulse_off )
 
80
                if( pulse_off != last_pulse_off )
84
81
                {
85
82
                        // sanity check
86
83
                        unsigned long interval = pulse_off - pulse_on;
87
 
                        if( interval > 800 && interval < 3000 )
 
84
//                      if( interval > 800 && interval < 3000 )
88
85
                        {
89
86
                                // update interval buffer
90
87
                                intervals[ interval_idx ] = pulse_off - pulse_on;
107
104
                                ave += intervals[ a ];
108
105
                        ave /= AVERAGE_SAMPLES;
109
106
 
110
 
#ifdef GRAPH
 
107
#if GRAPH
111
108
 
112
109
                        // draw graph
113
110
                        int pos = ( GRAPH_SIZE ) *