Subversion Repositories FlightCtrl

Rev

Rev 802 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 802 Rev 804
Line 126... Line 126...
126
        // calculatiing the difference of the two uint16_t and converting the result to an int16_t
126
        // calculatiing the difference of the two uint16_t and converting the result to an int16_t
127
        // implicit handles a timer overflow 65535 -> 0 the right way.
127
        // implicit handles a timer overflow 65535 -> 0 the right way.
128
        signal = (uint16_t) ICR1 - oldICR1;
128
        signal = (uint16_t) ICR1 - oldICR1;
129
        oldICR1 = ICR1;
129
        oldICR1 = ICR1;
Line 130... Line 130...
130
 
130
 
131
    // lost frame
131
    // lost frame?
132
    if(signal > 8000)
132
    if(signal > 8000)
133
    {
133
    {
134
                Sum_RC_Quality -= Sum_RC_Quality/2;
134
                Sum_RC_Quality -= Sum_RC_Quality/2;
135
        }
135
        }
Line 153... Line 153...
153
            {
153
            {
154
                                // shift signal to zero symmetric range  -154 to 159
154
                                // shift signal to zero symmetric range  -154 to 159
155
                signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms)
155
                signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms)
156
                // check for stable signal
156
                // check for stable signal
157
                Noise = abs(signal - PPM_in[index]);
157
                Noise = abs(signal - PPM_in[index]);
158
                if (Noise > 150) Sum_RC_Quality /= 2;
-
 
159
                else if((Noise/16) > (200-RC_Quality)) // spike detector
158
                if((Noise/16) > (200-RC_Quality)) // spike detector
160
                                {
159
                                {
161
                                        Sum_RC_Quality -= 3*RC_Quality;
160
                                        Sum_RC_Quality -= 3*RC_Quality;
162
                                        Sum_RC_Quality += 3*(200 - Noise);
161
                                        Sum_RC_Quality += 3*(200 - Noise);
163
                                }
162
                                }
164
                                else
163
                                else
Line 175... Line 174...
175
                else PPM_diff[index] = 0;
174
                else PPM_diff[index] = 0;
176
                PPM_in[index] = tmp; // update channel value
175
                PPM_in[index] = tmp; // update channel value
177
            }
176
            }
178
            else
177
            else
179
            {   // invalid PPM time
178
            {   // invalid PPM time
180
                                Sum_RC_Quality /= 2;
179
                                Sum_RC_Quality /= 8;
181
                        }
180
                        }
182
            index++; // next channel
181
            index++; // next channel
183
            // demux sum signal for channels 5 to 7 to J3, J4, J5
182
            // demux sum signal for channels 5 to 7 to J3, J4, J5
184
                if(index == 5) PORTD |= (1<<PORTD5); else PORTD &= ~(1<<PORTD5);
183
                if(index == 5) PORTD |= (1<<PORTD5); else PORTD &= ~(1<<PORTD5);
185
                if(index == 6) PORTD |= (1<<PORTD4); else PORTD &= ~(1<<PORTD4);
184
                if(index == 6) PORTD |= (1<<PORTD4); else PORTD &= ~(1<<PORTD4);