Rev 64 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 64 | Rev 65 | ||
---|---|---|---|
Line 110... | Line 110... | ||
110 | 110 | ||
111 | if (counter++ == 254) |
111 | if (counter++ == 254) |
112 | { |
112 | { |
113 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); //new cycle, output on |
113 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); //new cycle, output on |
- | 114 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); // |
|
114 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); // |
115 | |
115 | ch0_tmp = CH0; |
116 | ch0_tmp = CH0; |
116 | ch1_tmp = CH1; |
117 | ch1_tmp = CH1; |
117 | ch2_tmp = CH2; |
118 | ch2_tmp = CH2; |
118 | ch3_tmp = CH3; |
119 | ch3_tmp = CH3; |
119 | ch4_tmp = CH4; |
120 | ch4_tmp = CH4; |
- | 121 | ch5_tmp = CH5; |
|
120 | ch5_tmp = CH5; |
122 | |
121 | counter = 0; |
123 | counter = 0; |
Line 122... | Line 124... | ||
122 | } |
124 | } |
123 | 125 | ||
Line 231... | Line 233... | ||
231 | #define inimin 1200 |
233 | #define inimin 1200 |
232 | #define inimax 1800 |
234 | #define inimax 1800 |
Line 233... | Line 235... | ||
233 | 235 | ||
234 | unsigned int ppm; |
236 | unsigned int ppm; |
235 | signed int color; |
237 | signed int color; |
236 | unsigned int setupdly; |
238 | volatile unsigned int setupdly; |
237 | unsigned int ppmtodly; |
239 | volatile unsigned int ppmtodly; |
- | 240 | volatile unsigned int flashdly; |
|
- | 241 | ||
- | 242 | volatile unsigned int dly1; |
|
- | 243 | ||
- | 244 | unsigned char flags; |
|
238 | unsigned int flashdly; |
245 | |
239 | unsigned char setup; |
246 | unsigned char setup; |
240 | unsigned int lmax; |
247 | unsigned int lmax; |
241 | unsigned int lmin; |
248 | unsigned int lmin; |
242 | unsigned int max; |
249 | unsigned int max; |
- | 250 | unsigned int min; |
|
243 | unsigned int min; |
251 | unsigned char temp; |
244 | signed long temp1; |
252 | signed long temp1; |
Line -... | Line 253... | ||
- | 253 | signed long temp2; |
|
- | 254 | ||
245 | signed long temp2; |
255 | flags = 0; |
246 | 256 | ||
Line 247... | Line 257... | ||
247 | DDRB = (CH0_B|CH1_B|CH2_B); |
257 | DDRB = (CH0_B|CH1_B|CH2_B); |
248 | PORTB = 0x00; |
258 | PORTB = 0x00; |
Line 249... | Line 259... | ||
249 | 259 | ||
250 | DDRC = (ledred); |
260 | DDRC = (ledred); |
Line 251... | Line 261... | ||
251 | PORTC = 0x00; |
261 | PORTC = 0x00; |
252 | 262 | ||
253 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
263 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
254 | PORTD = 0x00; |
264 | PORTD = 0x00; |
255 | 265 | ||
256 | CH0 = 0; |
266 | CH0 = 0xFF; //PORTB RGBLED red |
Line 257... | Line 267... | ||
257 | CH1 = 0; |
267 | CH1 = 0xFF; //PORTB RGBLED green |
258 | CH2 = 0; |
268 | CH2 = 0xFF; //PORTB RGBLED blue |
Line 259... | Line 269... | ||
259 | CH3 = 0; |
269 | CH3 = 0; |
260 | CH4 = 0; |
270 | CH4 = 0; |
261 | CH5 = 0; |
271 | CH5 = 0; |
262 | 272 | ||
263 | lmax = 0x0000; |
273 | lmax = 0x0000; |
Line 285... | Line 295... | ||
285 | max = eeprom_read_word(&EEPMAX); //read min and max |
295 | max = eeprom_read_word(&EEPMAX); //read min and max |
286 | } |
296 | } |
Line 287... | Line 297... | ||
287 | 297 | ||
- | 298 | ||
288 | 299 | setup = 0; //reset setup toggle counter |
|
289 | setup = 0; //reset setup toggle counter |
300 | temp = (1<<0); |
290 | setupdly = SetDelay(5000); |
301 | setupdly = SetDelay(5000); |
Line 291... | Line 302... | ||
291 | ppmtodly = SetDelay(5000); |
302 | ppmtodly = SetDelay(2000); |
292 | flashdly = SetDelay(1000); |
303 | flashdly = SetDelay(200); |
Line 293... | Line 304... | ||
293 | 304 | ||
Line 321... | Line 332... | ||
321 | if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
332 | if ((ppm > 1600) && ((setup&1)==0)) setup++; // |
322 | if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
333 | if ((ppm < 1400) && ((setup&1)==1)) setup++; // |
Line 323... | Line 334... | ||
323 | 334 | ||
324 | if (CheckDelay(flashdly)) |
335 | if (CheckDelay(flashdly)) |
325 | { |
336 | { |
- | 337 | CH0 = (temp & (1<<0)) * 255; |
|
- | 338 | CH1 = (temp & (1<<1)) * 255; |
|
- | 339 | CH2 = (temp & (1<<2)) * 255; |
|
- | 340 | CH3 = (temp & (1<<3)) * 255; |
|
- | 341 | CH4 = (temp & (1<<4)) * 255; |
|
- | 342 | CH5 = (temp & (1<<5)) * 255; |
|
- | 343 | temp <<= 1; |
|
- | 344 | if (temp == (1<<6)) temp = (1<<0); |
|
- | 345 | ||
- | 346 | /* |
|
326 | CH0 = CH0 ^ 0xff; |
347 | CH0 = CH0 ^ 0xff; //invert brightness |
327 | CH1 = CH1 ^ 0xff; |
348 | CH1 = CH1 ^ 0xff; |
- | 349 | CH2 = CH2 ^ 0xff; |
|
- | 350 | CH3 = CH3 ^ 0xff; |
|
- | 351 | CH4 = CH4 ^ 0xff; |
|
- | 352 | CH5 = CH5 ^ 0xff; |
|
- | 353 | */ |
|
328 | CH2 = CH2 ^ 0xff; |
354 | |
329 | flashdly = SetDelay(250); |
355 | flashdly = SetDelay(100); |
330 | } |
356 | } |
Line 331... | Line 357... | ||
331 | } |
357 | } |
332 | 358 | ||
Line 345... | Line 371... | ||
345 | 371 | ||
346 | if (setup == 7) |
372 | if (setup == 7) |
347 | { |
373 | { |
348 | if (CheckDelay(flashdly)) //each 25ms toggle PWM's |
374 | if (CheckDelay(flashdly)) //each 25ms toggle PWM's |
349 | { |
375 | { |
350 | CH0 = CH0 ^ 0xff; |
376 | CH0 = CH0 ^ 0xff; //invert brightness |
351 | CH1 = CH1 ^ 0xff; |
377 | CH1 = CH1 ^ 0xff; |
- | 378 | CH2 = CH2 ^ 0xff; |
|
- | 379 | CH3 = CH3 ^ 0xff; |
|
- | 380 | CH4 = CH4 ^ 0xff; |
|
- | 381 | CH5 = CH5 ^ 0xff; |
|
352 | CH2 = CH2 ^ 0xff; |
382 | |
353 | flashdly = SetDelay(25); |
383 | flashdly = SetDelay(25); |
Line 354... | Line 384... | ||
354 | } |
384 | } |
Line 355... | Line 385... | ||
355 | 385 | ||
356 | } |
386 | } |
357 | 387 | ||
358 | if (CheckDelay(setupdly)) //setup timeout reached |
388 | if ((CheckDelay(setupdly)) && setup < 8) //setup timeout reached |
- | 389 | { |
|
- | 390 | setup = 8; //lockdown setup |
|
- | 391 | PORTD clrbit ledgreen; |
|
- | 392 | CH0 = 0; //start CH3 |
|
- | 393 | CH1 = 85; //CH4 |
|
- | 394 | CH2 = 170; //and CH4 with about 120° phase shift |
|
359 | { |
395 | |
Line 360... | Line 396... | ||
360 | setup = 8; //lockdown setup |
396 | flags = 0; |
361 | PORTD clrbit ledgreen; |
397 | dly1 = SetDelay(100); |
362 | } |
- | |
363 | - | ||
Line -... | Line 398... | ||
- | 398 | } |
|
- | 399 | ||
- | 400 | ||
- | 401 | if (setup == 8) |
|
- | 402 | { |
|
364 | 403 | ||
365 | if (setup == 8) |
404 | |
366 | { |
405 | /************************************************************************************/ |
Line 367... | Line 406... | ||
367 | 406 | /* control CH3, CH4 and CH5 (RGB LED) */ |
|
368 | 407 | /************************************************************************************/ |
|
Line 369... | Line 408... | ||
369 | 408 | ||
370 | temp1 = ((long)STEP * 6 * 20000) / ((max-REDUCE) - (min+REDUCE)); |
409 | temp1 = ((long)STEP * 7 * 40000) / ((max-REDUCE) - (min+REDUCE)); |
371 | temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1); |
410 | temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1); |
372 | color = temp2 / 20000; |
411 | color = temp2 / 40000; |
373 | 412 | ||
Line 374... | Line 413... | ||
374 | if (color < 0) color = 0; |
413 | if (color < 0) color = 0; |
375 | if (color > ((STEP*6)+1)) color = ((STEP*6)+1); |
414 | if (color > ((STEP*7)+1)) color = ((STEP*7)+1); |
376 | 415 | ||
377 | 416 | ||
378 | //printf("p %u ",ppm); |
417 | //printf("p %u ",ppm); |
379 | //printf("pm %u ",(min+REDUCE)); |
418 | //printf("pm %u ",(min+REDUCE)); |
380 | //printf("t1 %li ",temp1); |
419 | //printf("t1 %li ",temp1); |
381 | //printf("t2 %li ",temp2); |
420 | //printf("t2 %li ",temp2); |
382 | //printf("c %i\n ",color); |
421 | //printf("c %i\n ",color); |
383 | 422 | ||
384 | 423 | ||
385 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
424 | // Farbablauf: off > red > purple > blue > cyan > green > yellow > white |
386 | if ((color >= (STEP * 0)) && (color < (STEP * 1))) |
425 | if ((color >= (STEP * 0)) && (color < (STEP * 1))) |
387 | { |
426 | { |
388 | CH0 = MUL * ((color - (STEP * 0))); //fade in red > red (red only) |
427 | CH3 = MUL * ((color - (STEP * 0))); //fade in red > red (red only) |
389 | CH1 = 0; |
428 | CH4 = 0; |
390 | CH2 = 0; |
429 | CH5 = 0; |
391 | } |
430 | } |
392 | if ((color >= (STEP * 1)) && (color < (STEP * 2))) |
431 | if ((color >= (STEP * 1)) && (color < (STEP * 2))) |
393 | { |
432 | { |
394 | CH0 = ((STEP-1) * MUL); |
433 | CH3 = ((STEP-1) * MUL); |
395 | CH1 = 0; |
434 | CH4 = 0; |
396 | CH2 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue) |
435 | CH5 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue) |
397 | } |
436 | } |
398 | if ((color >= (STEP * 2)) && (color < (STEP * 3))) |
437 | if ((color >= (STEP * 2)) && (color < (STEP * 3))) |
399 | { |
438 | { |
400 | CH0 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only) |
439 | CH3 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only) |
401 | CH1 = 0; |
440 | CH4 = 0; |
402 | CH2 = ((STEP-1) * MUL); |
441 | CH5 = ((STEP-1) * MUL); |
403 | } |
442 | } |
404 | if ((color >= (STEP * 3)) && (color < (STEP * 4))) |
443 | if ((color >= (STEP * 3)) && (color < (STEP * 4))) |
405 | { |
444 | { |
406 | CH0 = 0; |
445 | CH3 = 0; |
407 | CH1 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green) |
446 | CH4 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green) |
408 | CH2 = ((STEP-1) * MUL); |
447 | CH5 = ((STEP-1) * MUL); |
409 | } |
448 | } |
410 | if ((color >= (STEP * 4)) && (color < (STEP * 5))) |
449 | if ((color >= (STEP * 4)) && (color < (STEP * 5))) |
411 | { |
450 | { |
412 | CH0 = 0; |
451 | CH3 = 0; |
413 | CH1 = ((STEP-1) * MUL); |
452 | CH4 = ((STEP-1) * MUL); |
414 | CH2 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only) |
453 | CH5 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only) |
415 | } |
454 | } |
416 | if ((color >= (STEP * 5)) && (color < (STEP * 6))) |
455 | if ((color >= (STEP * 5)) && (color < (STEP * 6))) |
417 | { |
- | |
Line -... | Line 456... | ||
- | 456 | { |
|
- | 457 | CH3 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red) |
|
- | 458 | CH4 = ((STEP-1) * MUL); |
|
- | 459 | CH5 = 0; |
|
- | 460 | } |
|
- | 461 | if ((color >= (STEP * 6)) && (color < (STEP * 7))) |
|
- | 462 | { |
|
- | 463 | CH3 = ((STEP-1) * MUL); |
|
- | 464 | CH4 = ((STEP-1) * MUL); |
|
- | 465 | CH5 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue) |
|
- | 466 | } |
|
- | 467 | ||
- | 468 | if (color >= (STEP * 7)) |
|
- | 469 | { |
|
- | 470 | CH3 = ((STEP-1) * MUL); |
|
- | 471 | CH4 = ((STEP-1) * MUL); |
|
- | 472 | CH5 = ((STEP-1) * MUL); |
|
- | 473 | } |
|
- | 474 | ||
- | 475 | /************************************************************************************/ |
|
- | 476 | /* control CH0, CH1 and CH2 */ |
|
- | 477 | /************************************************************************************/ |
|
- | 478 | ||
- | 479 | if (CheckDelay(dly1)) //timeout reached ? |
|
- | 480 | { |
|
- | 481 | ||
- | 482 | if ((flags & (1<<0))==0) //check if up or down |
|
- | 483 | { |
|
- | 484 | if (CH0++ == 254) //run CH0 up to 255 |
|
- | 485 | { |
|
- | 486 | flags setbit (1<<0); //255 reached next time go down |
|
- | 487 | ||
- | 488 | } |
|
- | 489 | } |
|
- | 490 | else //run down |
|
- | 491 | { |
|
- | 492 | if (CH0-- == 1) //run CH0 down to 0 |
|
- | 493 | { |
|
- | 494 | flags clrbit (1<<0); //0 reached next time go up |
|
- | 495 | } |
|
- | 496 | ||
- | 497 | } |
|
- | 498 | ||
- | 499 | ||
- | 500 | if ((flags & (1<<1))==0) //same for CH1 |
|
- | 501 | { |
|
- | 502 | if (CH1++ == 254) |
|
- | 503 | { |
|
- | 504 | flags setbit (1<<1); |
|
- | 505 | } |
|
- | 506 | } |
|
- | 507 | else |
|
- | 508 | { |
|
- | 509 | if (CH1-- == 1) |
|
- | 510 | { |
|
- | 511 | flags clrbit (1<<1); |
|
- | 512 | } |
|
- | 513 | ||
- | 514 | } |
|
- | 515 | ||
- | 516 | ||
- | 517 | if ((flags & (1<<2))==0) //and same for CH2 |
|
- | 518 | { |
|
- | 519 | if (CH2++ == 254) |
|
- | 520 | { |
|
- | 521 | flags setbit (1<<2); |
|
- | 522 | } |
|
- | 523 | } |
|
- | 524 | else |
|
- | 525 | { |
|
- | 526 | if (CH2-- == 1) |
|
- | 527 | { |
|
Line 418... | Line 528... | ||
418 | CH0 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red) |
528 | flags clrbit (1<<2); |
Line 419... | Line 529... | ||
419 | CH1 = ((STEP-1) * MUL); |
529 | } |