Rev 53 | Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 53 | Rev 54 | ||
---|---|---|---|
Line 57... | Line 57... | ||
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
57 | ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536); |
58 | if ((ppm > 600) && (ppm < 2400)) |
58 | if ((ppm > 600) && (ppm < 2400)) |
59 | { |
59 | { |
60 | if (ppm > 2100) ppm = 2100; |
60 | if (ppm > 2100) ppm = 2100; |
61 | if (ppm < 900) ppm = 900; |
61 | if (ppm < 900) ppm = 900; |
62 | ppm = (ppm_signal * 7 + ppm) / 8; |
62 | ppm = (ppm_signal * 3 + ppm) / 4; |
63 | ppm_signal = ppm; |
63 | ppm_signal = ppm; |
64 | ppm_new = 1; |
64 | if (ppm_new < 50) ppm_new++; |
65 | } |
65 | } |
Line 66... | Line 66... | ||
66 | 66 | ||
Line 67... | Line 67... | ||
67 | } |
67 | } |
Line 107... | Line 107... | ||
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
107 | if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; |
Line 108... | Line 108... | ||
108 | 108 | ||
109 | PORTB = PORTB_BAK; |
109 | PORTB = PORTB_BAK; |
Line -... | Line 110... | ||
- | 110 | PORTD = PORTD_BAK; |
|
110 | PORTD = PORTD_BAK; |
111 | |
111 | 112 | ||
112 | if (ms1++ == 32) |
113 | if (ms1++ == 32) |
113 | { |
114 | { |
114 | ms1=0; |
115 | ms1=0; |
Line 134... | Line 135... | ||
134 | return(((temp_hi << 8) | temp_lo) + t + 1); |
135 | return(((temp_hi << 8) | temp_lo) + t + 1); |
Line 135... | Line 136... | ||
135 | 136 | ||
Line -... | Line 137... | ||
- | 137 | } |
|
136 | } |
138 | |
137 | 139 | ||
138 | 140 | ||
139 | char CheckDelay(unsigned int t) |
141 | char CheckDelay(unsigned int t) |
Line 179... | Line 181... | ||
179 | } |
181 | } |
Line 180... | Line 182... | ||
180 | 182 | ||
181 | 183 | ||
182 | 184 | ||
183 | /*##############################################################################*/ |
185 | /*##############################################################################*/ |
184 | int GetPPM(void) |
186 | unsigned int GetPPM(void) |
185 | { |
187 | { |
Line 186... | Line 188... | ||
186 | //this routines seems to be nesseccary, as reading a 16 bit value |
188 | //this routines seems to be nesseccary, as reading a 16 bit value |
187 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
189 | //on a 8 bit machine is not atomic, so if an interrupt apears between reading |
Line 188... | Line -... | ||
188 | //low and high byte of the 16 bit value a wrong result is possible |
- | |
189 | 190 | //low and high byte of the 16 bit value a wrong result is possible |
|
190 | unsigned char intmask; |
191 | |
191 | unsigned int ppm_temp; |
192 | unsigned char temp_hi; |
192 | 193 | unsigned char temp_lo; |
|
Line 193... | Line 194... | ||
193 | intmask = TIMSK; //backup interupt enable bits |
194 | |
Line 194... | Line 195... | ||
194 | TIMSK &= ~(1<<TICIE1); //disable ppm interrupt |
195 | temp_hi = (ppm_signal >> 8); |
195 | ppm_temp = ppm_signal; |
196 | temp_lo = (ppm_signal & 0xff); |
196 | TIMSK = intmask; //restore interupt enable bits |
197 | if (temp_hi != (ppm_signal >> 8)) temp_hi = (ppm_signal >> 8); |
197 | return(ppm_temp); //return ppm_signal |
198 | return( (temp_hi << 8) | temp_lo); |
198 | 199 | ||
- | 200 | } |
|
- | 201 | ||
199 | } |
202 | |
- | 203 | /*##############################################################################*/ |
|
- | 204 | // MAIN |
|
- | 205 | /*##############################################################################*/ |
|
- | 206 | int main (void) |
|
- | 207 | { |
|
- | 208 | ||
- | 209 | #define step 128 |
|
- | 210 | #define mul 2 |
|
200 | 211 | ||
- | 212 | #define sigeepadr 0x00 |
|
201 | 213 | #define mineepadr 0x20 |
|
- | 214 | #define maxeepadr 0x22 |
|
- | 215 | #define eepsig 0x55aa |
|
- | 216 | ||
- | 217 | ||
- | 218 | ||
202 | /*##############################################################################*/ |
219 | unsigned int ppm; |
- | 220 | unsigned int setupdly; |
|
Line 203... | Line 221... | ||
203 | // MAIN |
221 | unsigned int ppmtodly; |
204 | /*##############################################################################*/ |
222 | unsigned int lmax; |
Line 205... | Line 223... | ||
205 | int main (void) |
223 | unsigned int lmin; |
Line 223... | Line 241... | ||
223 | ch2 = 0; |
241 | ch2 = 0; |
224 | ch3 = 0; |
242 | ch3 = 0; |
225 | ch4 = 0; |
243 | ch4 = 0; |
226 | ch5 = 0; |
244 | ch5 = 0; |
Line -... | Line 245... | ||
- | 245 | ||
- | 246 | lmax = 0x0000; |
|
- | 247 | lmin = 0xffff; |
|
227 | 248 | ||
228 | //StartUART(); |
249 | StartUART(); |
229 | StartPPM(); |
250 | StartPPM(); |
230 | //StartI2C(); |
251 | //StartI2C(); |
231 | StartPWM(); |
252 | StartPWM(); |
Line 232... | Line 253... | ||
232 | sei(); |
253 | sei(); |
- | 254 | ||
Line -... | Line 255... | ||
- | 255 | ||
- | 256 | min = 1100; |
|
- | 257 | max = 1900; |
|
- | 258 | ||
- | 259 | if (eeprom_read_word(sigeepadr) != eepsig) |
|
- | 260 | { |
|
- | 261 | eeprom_write_word(mineepadr, min); |
|
- | 262 | eeprom_write_word(maxeepadr, max); |
|
- | 263 | eeprom_write_word(sigeepadr, eepsig); |
|
- | 264 | } |
|
- | 265 | else |
|
- | 266 | { |
|
- | 267 | min = eeprom_read_word(mineepadr); |
|
Line -... | Line 268... | ||
- | 268 | max = eeprom_read_word(maxeepadr); |
|
233 | 269 | } |
|
- | 270 | ||
- | 271 | printf("ppm: %d / min: %d / max: %d\n",ppm,min,max); |
|
Line 234... | Line 272... | ||
234 | 272 | ||
235 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
273 | |
Line 236... | Line -... | ||
236 | - | ||
237 | - | ||
238 | colorState = 0; |
- | |
239 | - | ||
240 | while (1) |
- | |
241 | { |
- | |
242 | - | ||
243 | /* |
- | |
244 | #define step 128 |
- | |
245 | #define mul 2 |
- | |
246 | - | ||
247 | if ((ppm >= (step * 0) && (ppm < (step * 1))) ch0 = mul * ((ppm - (step * 0))); |
- | |
248 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) ch1 = mul * ((ppm - (step * 1))); |
- | |
249 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) ch0 = mul * ((step - 1) - (ppm - (step * 2))); |
- | |
250 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) ch2 = mul * ((ppm - (step * 3))); |
- | |
251 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) ch1 = mul * ((step - 1) - (ppm - (step * 4))); |
274 | setup = 0; |
252 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) ch0 = mul * ((ppm - (step * 5))); |
275 | setupdly = SetDelay(3000); |
253 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) ch2 = mul * ((step - 1) - (ppm - (step * 6))); |
276 | ppmtodly = SetDelay(5000); |
254 | - | ||
255 | //printf("%d ",ppm); |
277 | |
256 | */ |
278 | while (1) |
257 | 279 | { |
|
258 | for (i=0; i<=255; i++) |
- | |
259 | { |
- | |
260 | switch(colorState) |
- | |
261 | { |
- | |
262 | case 0: |
280 | |
263 | ch0 = i; //fade in (ch0) red |
- | |
264 | nextcolorState = 2; |
281 | if (ppm_new > 20) |
265 | break; |
282 | { |
266 | - | ||
267 | case 2: |
- | |
268 | ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
- | |
269 | nextcolorState = 4; |
283 | PORTC clrbit ledred; |
270 | break; |
- | |
271 | - | ||
272 | case 4: |
284 | ppm = GetPPM(); |
273 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
285 | ppmtodly = SetDelay(500); |
274 | nextcolorState = 6; |
286 | if (lmax < ppm) lmax=ppm; |
275 | break; |
- | |
276 | - | ||
277 | case 6: |
- | |
278 | ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
- | |
279 | nextcolorState = 8; |
287 | if (lmin > ppm) lmin=ppm; |
280 | break; |
- | |
281 | - | ||
282 | case 8: |
288 | } |
283 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
- | |
284 | nextcolorState = 10; |
289 | else |
285 | break; |
- | |
286 | - | ||
287 | case 10: |
290 | { |
288 | ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
291 | PORTC setbit ledred; |
289 | nextcolorState = 12; |
292 | ppm = min; |
Line -... | Line 293... | ||
- | 293 | } |
|
- | 294 | ||
- | 295 | if (CheckDelay(ppmtodly)) |
|
- | 296 | { |
|
- | 297 | ppmtodly = SetDelay(5000); |
|
- | 298 | ppm_new = 0; |
|
- | 299 | } |
|
- | 300 | ||
- | 301 | if ((ppm > 1600) && ((setup&1)==0)) setup++; |
|
- | 302 | if ((ppm < 1400) && ((setup&1)==1)) setup++; |
|
- | 303 | if (setup == 6) |
|
- | 304 | { |
|
- | 305 | PORTD setbit ledgreen; |
|
- | 306 | eeprom_write_word(mineepadr, lmin); |
|
- | 307 | eeprom_write_word(maxeepadr, lmax); |
|
- | 308 | min = lmin; |
|
Line -... | Line 309... | ||
- | 309 | max = lmax; |
|
- | 310 | setupdly = SetDelay(2000); |
|
- | 311 | } |
|
- | 312 | if (CheckDelay(setupdly)) |
|
- | 313 | { |
|
- | 314 | setup = 0; |
|
- | 315 | PORTD clrbit ledgreen; |
|
- | 316 | } |
|
- | 317 | ||
- | 318 | //printf("ppm: %d / min: %d / max: %d\n",ppm,lmin,lmax); |
|
- | 319 | ||
- | 320 | ||
- | 321 | /* |
|
290 | break; |
322 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
- | 323 | if ((ppm >= (step * 0)) && (ppm < (step * 1))) |
|
- | 324 | { |
|
- | 325 | ch0 = mul * ((ppm - (step * 0))); //fade in red > red (red only) |
|
- | 326 | ch1 = 0; |
|
- | 327 | ch2 = 0; |
|
- | 328 | } |
|
291 | 329 | if ((ppm >= (step * 1)) && (ppm < (step * 2))) |
|
- | 330 | { |
|
292 | case 12: |
331 | ch0 = ((step-1) * mul); |
- | 332 | ch2 = mul * ((ppm - (step * 1))); //fade in blue > purple (red + blue) |
|
- | 333 | ch1 = 0; |
|
- | 334 | } |
|
- | 335 | if ((ppm >= (step * 2)) && (ppm < (step * 3))) |
|
- | 336 | { |
|
- | 337 | ch0 = mul * ((step - 1) - (ppm - (step * 2))); //fade out red > blue (blue only) |
|
- | 338 | ch2 = ((step-1) * mul); |
|
- | 339 | ch1 = 0; |
|
- | 340 | } |
|
- | 341 | if ((ppm >= (step * 3)) && (ppm < (step * 4))) |
|
- | 342 | { |
|
- | 343 | ch0 = 0; |
|
- | 344 | ch2 = ((step-1) * mul); |
|
- | 345 | ch1 = mul * ((ppm - (step * 3))); //fade in green > tuerkis (blue + green) |
|
- | 346 | } |
|
- | 347 | if ((ppm >= (step * 4)) && (ppm < (step * 5))) |
|
- | 348 | { |
|
- | 349 | ch0 = 0; |
|
- | 350 | ch2 = mul * ((step - 1) - (ppm - (step * 4))); //fade out blue > green (green only) |
|
- | 351 | ch1 = ((step-1) * mul); |
|
- | 352 | } |
|
- | 353 | if ((ppm >= (step * 5)) && (ppm < (step * 6))) |
|
- | 354 | { |
|
- | 355 | ch0 = mul * ((ppm - (step * 5))); //fade in red > yellow (green + red) |
|
- | 356 | ch2 = 0; |
|
- | 357 | ch1 = ((step-1) * mul); |
|
- | 358 | } |
|
- | 359 | if ((ppm >= (step * 6)) && (ppm < (step * 7))) |
|
- | 360 | { |
|
- | 361 | ch0 = ((step-1) * mul); |
|
- | 362 | ch2 = 0; |
|
- | 363 | ch1 = mul * ((step - 1) - (ppm - (step * 6))); //fade out green > red (red only) |
|
- | 364 | } |
|
293 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
365 | if ((ppm >= (step * 7)) ) |
294 | nextcolorState = 0; |
- | |
Line 295... | Line -... | ||
295 | break; |
- | |
296 | } |
- | |
Line 297... | Line 366... | ||
297 | 366 | { |