/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-23 21:08:18 UTC
  • Revision ID: tim@ed.am-20131023210818-w3b4t7ddzxvu11mo
added "graphic" display to receiver test program

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