Rev 1206 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1206 | Rev 1214 | ||
---|---|---|---|
Line 58... | Line 58... | ||
58 | volatile int16_t PPM_in[15]; //PPM24 supports 12 channels per frame |
58 | volatile int16_t PPM_in[15]; //PPM24 supports 12 channels per frame |
59 | volatile int16_t PPM_diff[15]; |
59 | volatile int16_t PPM_diff[15]; |
60 | volatile uint8_t NewPpmData = 1; |
60 | volatile uint8_t NewPpmData = 1; |
61 | volatile int16_t RC_Quality = 0; |
61 | volatile int16_t RC_Quality = 0; |
Line 62... | Line -... | ||
62 | - | ||
Line 63... | Line 62... | ||
63 | volatile uint8_t NewRCFrames = 0; |
62 | |
64 | 63 | ||
65 | 64 | ||
Line 108... | Line 107... | ||
108 | // Timer/Counter1 Interrupt Mask Register |
107 | // Timer/Counter1 Interrupt Mask Register |
Line 109... | Line 108... | ||
109 | 108 | ||
110 | // Enable Input Capture Interrupt (bit: ICIE1=1) |
109 | // Enable Input Capture Interrupt (bit: ICIE1=1) |
111 | // Disable Output Compare A & B Match Interrupts (bit: OCIE1B=0, OICIE1A=0) |
110 | // Disable Output Compare A & B Match Interrupts (bit: OCIE1B=0, OICIE1A=0) |
112 | // Enable Overflow Interrupt (bit: TOIE1=0) |
111 | // Enable Overflow Interrupt (bit: TOIE1=0) |
113 | TIMSK1 &= ~((1<<OCIE1B)|(1<<OCIE1A)); |
112 | TIMSK1 &= ~((1<<OCIE1B)|(1<<OCIE1A)|(1<<TOIE1)); |
Line 114... | Line 113... | ||
114 | TIMSK1 |= (1<<ICIE1)|(1<<TOIE1); |
113 | TIMSK1 |= (1<<ICIE1); |
Line 115... | Line 114... | ||
115 | 114 | ||
116 | RC_Quality = 0; |
115 | RC_Quality = 0; |
Line 117... | Line -... | ||
117 | - | ||
118 | SREG = sreg; |
- | |
119 | } |
- | |
120 | - | ||
121 | - | ||
122 | // happens every 0.209712 s. |
- | |
123 | // check for at least one new frame per timer overflow (timeout) |
- | |
124 | ISR(TIMER1_OVF_vect) |
- | |
125 | { |
- | |
126 | if (NewRCFrames == 0) RC_Quality -= RC_Quality/8; |
116 | |
127 | NewRCFrames = 0; |
117 | SREG = sreg; |
128 | } |
118 | } |
129 | 119 | ||
130 | 120 | ||
Line 167... | Line 157... | ||
167 | //sync gap? (3.52 ms < signal < 25.6 ms) |
157 | //sync gap? (3.52 ms < signal < 25.6 ms) |
168 | if((signal > 1100) && (signal < 8000)) |
158 | if((signal > 1100) && (signal < 8000)) |
169 | { |
159 | { |
170 | // if a sync gap happens and there where at least 4 channels decoded before |
160 | // if a sync gap happens and there where at least 4 channels decoded before |
171 | // then the NewPpmData flag is reset indicating valid data in the PPM_in[] array. |
161 | // then the NewPpmData flag is reset indicating valid data in the PPM_in[] array. |
172 | if(index == 4) |
162 | if(index >= 4) |
173 | { |
163 | { |
174 | NewPpmData = 0; // Null means NewData for the first 4 channels |
164 | NewPpmData = 0; // Null means NewData for the first 4 channels |
175 | NewRCFrames++; |
- | |
176 | } |
165 | } |
177 | // synchronize channel index |
166 | // synchronize channel index |
178 | index = 1; |
167 | index = 1; |
179 | } |
168 | } |
180 | else // within the PPM frame |
169 | else // within the PPM frame |
Line 186... | Line 175... | ||
186 | if((signal > 250) && (signal < 687)) |
175 | if((signal > 250) && (signal < 687)) |
187 | { |
176 | { |
188 | // shift signal to zero symmetric range -154 to 159 |
177 | // shift signal to zero symmetric range -154 to 159 |
189 | signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms) |
178 | signal -= 466; // offset of 1.4912 ms ??? (469 * 3.2µs = 1.5008 ms) |
190 | // check for stable signal |
179 | // check for stable signal |
191 | if(abs(signal-PPM_in[index]) < 6) |
180 | if(abs(signal - PPM_in[index]) < 6) |
192 | { |
181 | { |
193 | if(RC_Quality < 200) RC_Quality +=10; |
182 | if(RC_Quality < 200) RC_Quality +=10; |
194 | else RC_Quality = 200; |
183 | else RC_Quality = 200; |
195 | } |
184 | } |
196 | // calculate exponential history for signal |
185 | // calculate exponential history for signal |
Line 210... | Line 199... | ||
210 | { |
199 | { |
211 | if(index == 7) J5HIGH; else J5LOW; |
200 | if(index == 7) J5HIGH; else J5LOW; |
212 | } |
201 | } |
213 | } |
202 | } |
214 | } |
203 | } |
215 | if(RC_Quality) RC_Quality--; |
- | |
216 | } |
204 | } |