/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: Tim Marston
  • Date: 2013-10-30 22:41:50 UTC
  • Revision ID: tim@ed.am-20131030224150-t6xs1l783m2yg6rd
updated comments in receiver test programs

Show diffs side-by-side

added added

removed removed

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
 
 
 
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).
11
17
 
12
18
// number of signal pulses to average
13
19
#define AVERAGE_SAMPLES 1
16
22
#define AVERAGE_DAMP 1
17
23
 
18
24
// graphic display
19
 
#define GRAPH 0
 
25
#define GRAPH 1
20
26
#define GRAPH_MIN 1000
21
27
#define GRAPH_MAX 2000
22
28
#define GRAPH_SIZE 30
58
64
        for( int a = 0; a < AVERAGE_SAMPLES; a++ )
59
65
                intervals[ a ] = 0;
60
66
 
61
 
#if GRAPH
 
67
#ifdef GRAPH
62
68
        // init graph
63
69
        char graph[ GRAPH_SIZE + 3 ];
64
70
        for( int a = 1; a < GRAPH_SIZE + 1; a++ )
71
77
        while( true )
72
78
        {
73
79
                // detect pulse falling-edge
74
 
                noInterrupts();
75
80
                unsigned long pulse_on = _new_pulse_on;
76
81
                unsigned long pulse_off = _new_pulse_off;
77
 
                interrupts();
78
 
                
79
82
                bool got_pulse = false;
80
 
                if( pulse_off != last_pulse_off )
 
83
                if( pulse_off > last_pulse_off )
81
84
                {
82
85
                        // sanity check
83
86
                        unsigned long interval = pulse_off - pulse_on;
84
 
//                      if( interval > 800 && interval < 3000 )
 
87
                        if( interval > 800 && interval < 3000 )
85
88
                        {
86
89
                                // update interval buffer
87
90
                                intervals[ interval_idx ] = pulse_off - pulse_on;
104
107
                                ave += intervals[ a ];
105
108
                        ave /= AVERAGE_SAMPLES;
106
109
 
107
 
#if GRAPH
 
110
#ifdef GRAPH
108
111
 
109
112
                        // draw graph
110
113
                        int pos = ( GRAPH_SIZE ) *