Rev 1172 | Rev 1232 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1172 | Rev 1213 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | 4 | ||
5 | #include "Spectrum.h" |
5 | #include "Spectrum.h" |
6 | #include "main.h" |
6 | #include "main.h" |
- | 7 | ||
- | 8 | //--------------------------------------------------------------// |
|
- | 9 | ||
- | 10 | //--------------------------------------------------------------// |
|
- | 11 | void SpektrumBinding(void) |
|
- | 12 | { |
|
- | 13 | unsigned int timerTimeout = SetDelay(10000); // Timeout 10 sec. |
|
- | 14 | unsigned char connected = 0; |
|
- | 15 | unsigned int delaycounter; |
|
- | 16 | ||
- | 17 | UCSR1B &= ~(1 << RXCIE1); // disable rx-interrupt |
|
- | 18 | UCSR1B &= ~(1<<RXEN1); // disable Uart-Rx |
|
- | 19 | PORTD &= ~(1 << PORTD2); // disable pull-up |
|
- | 20 | ||
- | 21 | printf("\n\rPlease connect Spektrum receiver for binding NOW..."); |
|
- | 22 | ||
- | 23 | while(!CheckDelay(timerTimeout)) |
|
- | 24 | { |
|
- | 25 | if (PIND & (1 << PORTD2)) { timerTimeout = SetDelay(90); connected = 1; break; } |
|
- | 26 | } |
|
- | 27 | ||
- | 28 | if (connected) |
|
- | 29 | { |
|
- | 30 | ||
- | 31 | printf("ok.\n\r"); |
|
- | 32 | DDRD |= (1 << DDD2); // Rx as output |
|
- | 33 | ||
- | 34 | while(!CheckDelay(timerTimeout)); // delay after startup of RX |
|
- | 35 | for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 36 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 37 | ||
- | 38 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 39 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 40 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 41 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 42 | ||
- | 43 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 44 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 45 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 46 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 47 | ||
- | 48 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 49 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
|
- | 50 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
|
- | 51 | ||
- | 52 | } |
|
- | 53 | else |
|
- | 54 | { printf("Timeout.\n\r"); |
|
- | 55 | ||
- | 56 | ||
- | 57 | } |
|
- | 58 | ||
- | 59 | DDRD &= ~(1 << DDD2); // RX as input |
|
- | 60 | PORTD &= ~(1 << PORTD2); |
|
- | 61 | ||
- | 62 | Uart1Init(); // init Uart again |
|
- | 63 | } |
|
7 | 64 | ||
8 | //############################################################################ |
65 | //############################################################################ |
9 | // zum Decodieren des Spektrum Satelliten wird USART1 benutzt. |
66 | // zum Decodieren des Spektrum Satelliten wird USART1 benutzt. |
10 | // USART1 initialisation from killagreg |
67 | // USART1 initialisation from killagreg |
11 | void Uart1Init(void) |
68 | void Uart1Init(void) |
12 | //############################################################################ |
69 | //############################################################################ |
13 | { |
70 | { |
14 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
71 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
15 | // USART1 Control and Status Register A, B, C and baud rate register |
72 | // USART1 Control and Status Register A, B, C and baud rate register |
16 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
73 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
17 | // disable RX-Interrupt |
74 | // disable RX-Interrupt |
18 | UCSR1B &= ~(1 << RXCIE1); |
75 | UCSR1B &= ~(1 << RXCIE1); |
19 | // disable TX-Interrupt |
76 | // disable TX-Interrupt |
20 | UCSR1B &= ~(1 << TXCIE1); |
77 | UCSR1B &= ~(1 << TXCIE1); |
21 | // disable DRE-Interrupt |
78 | // disable DRE-Interrupt |
22 | UCSR1B &= ~(1 << UDRIE1); |
79 | UCSR1B &= ~(1 << UDRIE1); |
23 | // set direction of RXD1 and TXD1 pins |
80 | // set direction of RXD1 and TXD1 pins |
24 | // set RXD1 (PD2) as an input pin |
81 | // set RXD1 (PD2) as an input pin |
25 | PORTD |= (1 << PORTD2); |
82 | PORTD |= (1 << PORTD2); |
26 | DDRD &= ~(1 << DDD2); |
83 | DDRD &= ~(1 << DDD2); |
27 | // USART0 Baud Rate Register |
84 | // USART0 Baud Rate Register |
28 | // set clock divider |
85 | // set clock divider |
- | 86 | ||
29 | UBRR1H = (uint8_t)(ubrr>>8); |
87 | UBRR1H = (uint8_t)(ubrr>>8); |
30 | UBRR1L = (uint8_t)ubrr; |
88 | UBRR1L = (uint8_t)ubrr; |
31 | // enable double speed operation |
89 | // enable double speed operation |
32 | UCSR1A |= (1 << U2X1); |
90 | UCSR1A |= (1 << U2X1); |
33 | // enable receiver and transmitter |
91 | // enable receiver and transmitter |
34 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
92 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
- | 93 | ||
- | 94 | ||
- | 95 | ||
- | 96 | ||
35 | UCSR1B = (1<<RXEN1); |
97 | UCSR1B = (1<<RXEN1); |
36 | // set asynchronous mode |
98 | // set asynchronous mode |
37 | UCSR1C &= ~(1 << UMSEL11); |
99 | UCSR1C &= ~(1 << UMSEL11); |
38 | UCSR1C &= ~(1 << UMSEL10); |
100 | UCSR1C &= ~(1 << UMSEL10); |
39 | // no parity |
101 | // no parity |
40 | UCSR1C &= ~(1 << UPM11); |
102 | UCSR1C &= ~(1 << UPM11); |
41 | UCSR1C &= ~(1 << UPM10); |
103 | UCSR1C &= ~(1 << UPM10); |
42 | // 1 stop bit |
104 | // 1 stop bit |
43 | UCSR1C &= ~(1 << USBS1); |
105 | UCSR1C &= ~(1 << USBS1); |
44 | // 8-bit |
106 | // 8-bit |
45 | UCSR1B &= ~(1 << UCSZ12); |
107 | UCSR1B &= ~(1 << UCSZ12); |
46 | UCSR1C |= (1 << UCSZ11); |
108 | UCSR1C |= (1 << UCSZ11); |
47 | UCSR1C |= (1 << UCSZ10); |
109 | UCSR1C |= (1 << UCSZ10); |
48 | // flush receive buffer explicit |
110 | // flush receive buffer explicit |
49 | while(UCSR1A & (1<<RXC1)) UDR1; |
111 | while(UCSR1A & (1<<RXC1)) UDR1; |
50 | // enable RX-interrupts at the end |
112 | // enable RX-interrupts at the end |
51 | UCSR1B |= (1 << RXCIE1); |
113 | UCSR1B |= (1 << RXCIE1); |
52 | // -- End of USART1 initialisation |
114 | // -- End of USART1 initialisation |
53 | return; |
115 | return; |
54 | } |
116 | } |
55 | 117 | ||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
118 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | // + Copyright (c) Rainer Walther |
119 | // + Copyright (c) Rainer Walther |
58 | // + RC-routines from original MK rc.c (c) H&I |
120 | // + RC-routines from original MK rc.c (c) H&I |
59 | // + Useful infos from Walter: http://www.rcgroups.com/forums/showthread.php?t=714299&page=2 |
121 | // + Useful infos from Walter: http://www.rcgroups.com/forums/showthread.php?t=714299&page=2 |
60 | // + only for non-profit use |
122 | // + only for non-profit use |
61 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
123 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
62 | // |
124 | // |
63 | // 20080808 rw Modified for Spektrum AR6100 (PPM) |
125 | // 20080808 rw Modified for Spektrum AR6100 (PPM) |
64 | // 20080823 rw Add Spektrum satellite receiver on USART1 (644P only) |
126 | // 20080823 rw Add Spektrum satellite receiver on USART1 (644P only) |
65 | // 20081213 rw Add support for Spektrum DS9 Air-Tx-Module (9 channels) |
127 | // 20081213 rw Add support for Spektrum DS9 Air-Tx-Module (9 channels) |
66 | // Replace AR6100-coding with original composit-signal routines |
128 | // Replace AR6100-coding with original composit-signal routines |
67 | // |
129 | // |
68 | // --- |
130 | // --- |
69 | // Entweder Summensignal ODER Spektrum-Receiver anschließen. Nicht beides gleichzeitig betreiben! |
131 | // Entweder Summensignal ODER Spektrum-Receiver anschließen. Nicht beides gleichzeitig betreiben! |
70 | // Binding is not implemented. Bind with external Receiver. |
132 | // Binding is not implemented. Bind with external Receiver. |
71 | // Servo output J3, J4, J5 not serviced |
133 | // Servo output J3, J4, J5 not serviced |
72 | // |
134 | // |
73 | // Anschuß Spektrum Receiver |
135 | // Anschuß Spektrum Receiver |
74 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
136 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
75 | // Schwarz: GND |
137 | // Schwarz: GND |
76 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
138 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
77 | // |
139 | // |
78 | // --- |
140 | // --- |
79 | // Satellite-Reciever connected on USART1: |
141 | // Satellite-Reciever connected on USART1: |
80 | // |
142 | // |
81 | // DX7/DX6i: One data-frame at 115200 baud every 22ms. |
143 | // DX7/DX6i: One data-frame at 115200 baud every 22ms. |
82 | // DX7se: One data-frame at 115200 baud every 11ms. |
144 | // DX7se: One data-frame at 115200 baud every 11ms. |
83 | // byte1: unknown |
145 | // byte1: unknown |
84 | // byte2: unknown |
146 | // byte2: unknown |
85 | // byte3: and byte4: channel data (FLT-Mode) |
147 | // byte3: and byte4: channel data (FLT-Mode) |
86 | // byte5: and byte6: channel data (Roll) |
148 | // byte5: and byte6: channel data (Roll) |
87 | // byte7: and byte8: channel data (Nick) |
149 | // byte7: and byte8: channel data (Nick) |
88 | // byte9: and byte10: channel data (Gier) |
150 | // byte9: and byte10: channel data (Gier) |
89 | // byte11: and byte12: channel data (Gear Switch) |
151 | // byte11: and byte12: channel data (Gear Switch) |
90 | // byte13: and byte14: channel data (Gas) |
152 | // byte13: and byte14: channel data (Gas) |
91 | // byte15: and byte16: channel data (AUX2) |
153 | // byte15: and byte16: channel data (AUX2) |
92 | // |
154 | // |
93 | // DS9 (9 Channel): One data-frame at 115200 baud every 11ms, alternating frame 1/2 for CH1-7 / CH8-9 |
155 | // DS9 (9 Channel): One data-frame at 115200 baud every 11ms, alternating frame 1/2 for CH1-7 / CH8-9 |
94 | // 1st Frame: |
156 | // 1st Frame: |
95 | // byte1: unknown |
157 | // byte1: unknown |
96 | // byte2: unknown |
158 | // byte2: unknown |
97 | // byte3: and byte4: channel data |
159 | // byte3: and byte4: channel data |
98 | // byte5: and byte6: channel data |
160 | // byte5: and byte6: channel data |
99 | // byte7: and byte8: channel data |
161 | // byte7: and byte8: channel data |
100 | // byte9: and byte10: channel data |
162 | // byte9: and byte10: channel data |
101 | // byte11: and byte12: channel data |
163 | // byte11: and byte12: channel data |
102 | // byte13: and byte14: channel data |
164 | // byte13: and byte14: channel data |
103 | // byte15: and byte16: channel data |
165 | // byte15: and byte16: channel data |
104 | // 2nd Frame: |
166 | // 2nd Frame: |
105 | // byte1: unknown |
167 | // byte1: unknown |
106 | // byte2: unknown |
168 | // byte2: unknown |
107 | // byte3: and byte4: channel data |
169 | // byte3: and byte4: channel data |
108 | // byte5: and byte6: channel data |
170 | // byte5: and byte6: channel data |
109 | // byte7: and byte8: 0xffff |
171 | // byte7: and byte8: 0xffff |
110 | // byte9: and byte10: 0xffff |
172 | // byte9: and byte10: 0xffff |
111 | // byte11: and byte12: 0xffff |
173 | // byte11: and byte12: 0xffff |
112 | // byte13: and byte14: 0xffff |
174 | // byte13: and byte14: 0xffff |
113 | // byte15: and byte16: 0xffff |
175 | // byte15: and byte16: 0xffff |
114 | // |
176 | // |
115 | // Each channel data (16 bit= 2byte, first msb, second lsb) is arranged as: |
177 | // Each channel data (16 bit= 2byte, first msb, second lsb) is arranged as: |
116 | // |
178 | // |
117 | // Bits: F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 |
179 | // Bits: F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 |
118 | // |
180 | // |
119 | // 0 means a '0' bit |
181 | // 0 means a '0' bit |
120 | // F: 1 = indicates beginning of 2nd frame for CH8-9 (DS9 only) |
182 | // F: 1 = indicates beginning of 2nd frame for CH8-9 (DS9 only) |
121 | // C3 to C0 is the channel number. 0 to 9 (4 bit, as assigned in the transmitter) |
183 | // C3 to C0 is the channel number. 0 to 9 (4 bit, as assigned in the transmitter) |
122 | // D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for 100% transmitter-travel |
184 | // D9 to D0 is the channel data (10 bit) 0xaa..0x200..0x356 for 100% transmitter-travel |
123 | // |
185 | // |
124 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
186 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
125 | 187 | ||
126 | //############################################################################ |
188 | //############################################################################ |
127 | //Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever |
189 | //Diese Routine startet und inizialisiert den USART1 für seriellen Spektrum satellite reciever |
128 | SIGNAL(USART1_RX_vect) |
190 | SIGNAL(USART1_RX_vect) |
129 | //############################################################################ |
191 | //############################################################################ |
130 | { |
192 | { |
131 | static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer; |
193 | static unsigned int Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0, FrameTimer; |
132 | unsigned int Channel, index; |
194 | unsigned int Channel, index; |
133 | signed int signal, tmp; |
195 | signed int signal, tmp; |
134 | int bCheckDelay; |
196 | int bCheckDelay; |
135 | uint8_t c; |
197 | uint8_t c; |
136 | 198 | ||
137 | c = UDR1; // get data byte |
199 | c = UDR1; // get data byte |
138 | 200 | ||
139 | if (ReSync == 1) |
201 | if (ReSync == 1) |
140 | { |
202 | { |
141 | // wait for beginning of new frame |
203 | // wait for beginning of new frame |
142 | ReSync = 0; |
204 | ReSync = 0; |
143 | 205 | ||
144 | FrameTimer = SetDelay(7); // minimum 7ms zwischen den frames |
206 | FrameTimer = SetDelay(7); // minimum 7ms zwischen den frames |
145 | FrameCnt = 0; |
207 | FrameCnt = 0; |
146 | Sync = 0; |
208 | Sync = 0; |
147 | ByteHigh = 0; |
209 | ByteHigh = 0; |
148 | } |
210 | } |
149 | else |
211 | else |
150 | { |
212 | { |
151 | bCheckDelay = CheckDelay(FrameTimer); |
213 | bCheckDelay = CheckDelay(FrameTimer); |
152 | if ( Sync == 0 ) |
214 | if ( Sync == 0 ) |
153 | { |
215 | { |
154 | if(bCheckDelay) |
216 | if(bCheckDelay) |
155 | { |
217 | { |
156 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
218 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
157 | // Zeichen ignorieren, da Bedeutung unbekannt |
219 | // Zeichen ignorieren, da Bedeutung unbekannt |
158 | Sync = 1; |
220 | Sync = 1; |
159 | FrameCnt ++; |
221 | FrameCnt ++; |
160 | } |
222 | } |
161 | else |
223 | else |
162 | { |
224 | { |
163 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
225 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
164 | // warten auf erstes Sync-Zeichen |
226 | // warten auf erstes Sync-Zeichen |
165 | } |
227 | } |
166 | } |
228 | } |
167 | else if((Sync == 1) && !bCheckDelay) |
229 | else if((Sync == 1) && !bCheckDelay) |
168 | { |
230 | { |
169 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
231 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
170 | Sync = 2; |
232 | Sync = 2; |
171 | FrameCnt ++; |
233 | FrameCnt ++; |
172 | } |
234 | } |
173 | else if((Sync == 2) && !bCheckDelay) |
235 | else if((Sync == 2) && !bCheckDelay) |
174 | { |
236 | { |
175 | // Datenbyte high |
237 | // Datenbyte high |
176 | ByteHigh = c; |
238 | ByteHigh = c; |
177 | 239 | ||
178 | if (FrameCnt == 2) |
240 | if (FrameCnt == 2) |
179 | { |
241 | { |
180 | // is 1st Byte of Channel-data |
242 | // is 1st Byte of Channel-data |
181 | // Frame 1 with Channel 1-7 comming next |
243 | // Frame 1 with Channel 1-7 comming next |
182 | Frame2 = 0; |
244 | Frame2 = 0; |
183 | if(ByteHigh & 0x80) |
245 | if(ByteHigh & 0x80) |
184 | { |
246 | { |
185 | // DS9: Frame 2 with Channel 8-9 comming next |
247 | // DS9: Frame 2 with Channel 8-9 comming next |
186 | Frame2 = 1; |
248 | Frame2 = 1; |
187 | } |
249 | } |
188 | } |
250 | } |
189 | Sync = 3; |
251 | Sync = 3; |
190 | FrameCnt ++; |
252 | FrameCnt ++; |
191 | } |
253 | } |
192 | else if((Sync == 3) && !bCheckDelay) |
254 | else if((Sync == 3) && !bCheckDelay) |
193 | { |
255 | { |
194 | // Datenbyte low |
256 | // Datenbyte low |
195 | 257 | ||
196 | // High-Byte for next channel comes next |
258 | // High-Byte for next channel comes next |
197 | Sync = 2; |
259 | Sync = 2; |
198 | FrameCnt ++; |
260 | FrameCnt ++; |
199 | 261 | ||
200 | index = (ByteHigh >> 2) & 0x0f; |
262 | index = (ByteHigh >> 2) & 0x0f; |
201 | index ++; |
263 | index ++; |
202 | Channel = (ByteHigh << 8) | c; |
264 | Channel = (ByteHigh << 8) | c; |
203 | signal = Channel & 0x3ff; |
265 | signal = Channel & 0x3ff; |
204 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
266 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
205 | signal = signal/3; // scaling to fit PPM resolution |
267 | signal = signal/3; // scaling to fit PPM resolution |
206 | 268 | ||
207 | if(index >= 0 && index <= 10) |
269 | if(index >= 0 && index <= 10) |
208 | { |
270 | { |
209 | // Stabiles Signal |
271 | // Stabiles Signal |
210 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
272 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
211 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
273 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
212 | if(tmp > signal+1) tmp--; else |
274 | if(tmp > signal+1) tmp--; else |
213 | if(tmp < signal-1) tmp++; |
275 | if(tmp < signal-1) tmp++; |
214 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
276 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
215 | else PPM_diff[index] = 0; |
277 | else PPM_diff[index] = 0; |
216 | PPM_in[index] = tmp; |
278 | PPM_in[index] = tmp; |
217 | } |
279 | } |
218 | } |
280 | } |
219 | else |
281 | else |
220 | { |
282 | { |
221 | // hier stimmt was nicht: neu synchronisieren |
283 | // hier stimmt was nicht: neu synchronisieren |
222 | ReSync = 1; |
284 | ReSync = 1; |
223 | FrameCnt = 0; |
285 | FrameCnt = 0; |
224 | Frame2 = 0; |
286 | Frame2 = 0; |
225 | } |
287 | } |
226 | 288 | ||
227 | // 16 Bytes per frame |
289 | // 16 Bytes per frame |
228 | if(FrameCnt >= 16) |
290 | if(FrameCnt >= 16) |
229 | { |
291 | { |
230 | // Frame complete |
292 | // Frame complete |
231 | if(Frame2 == 0) |
293 | if(Frame2 == 0) |
232 | { |
294 | { |
233 | // Null bedeutet: Neue Daten |
295 | // Null bedeutet: Neue Daten |
234 | // nur beim ersten Frame (CH 0-7) setzen |
296 | // nur beim ersten Frame (CH 0-7) setzen |
235 | NewPpmData = 0; |
297 | NewPpmData = 0; |
236 | } |
298 | } |
237 | 299 | ||
238 | // new frame next, nach fruehestens 7ms erwartet |
300 | // new frame next, nach fruehestens 7ms erwartet |
239 | FrameCnt = 0; |
301 | FrameCnt = 0; |
240 | Frame2 = 0; |
302 | Frame2 = 0; |
241 | Sync = 0; |
303 | Sync = 0; |
242 | } |
304 | } |
243 | // Zeit bis zum nächsten Zeichen messen |
305 | // Zeit bis zum nächsten Zeichen messen |
244 | FrameTimer = SetDelay(7); |
306 | FrameTimer = SetDelay(7); |
245 | } |
307 | } |
246 | } |
308 | } |
247 | 309 | ||
248 | 310 | ||
249 | 311 |