/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: 2014-04-09 23:32:44 UTC
  • Revision ID: dan-20140409233244-s8n95ymvkg3pjxju
added mega-shield.net to the ignore file because it is generated

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