Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 64 → Rev 65

/IR-TX-BL/branches/PWM-CTRL_V0.02/main.c
112,6 → 112,7
{
PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); //new cycle, output on
PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); //
 
ch0_tmp = CH0;
ch1_tmp = CH1;
ch2_tmp = CH2;
118,6 → 119,7
ch3_tmp = CH3;
ch4_tmp = CH4;
ch5_tmp = CH5;
 
counter = 0;
}
 
233,17 → 235,25
 
unsigned int ppm;
signed int color;
unsigned int setupdly;
unsigned int ppmtodly;
unsigned int flashdly;
volatile unsigned int setupdly;
volatile unsigned int ppmtodly;
volatile unsigned int flashdly;
volatile unsigned int dly1;
 
unsigned char flags;
 
unsigned char setup;
unsigned int lmax;
unsigned int lmin;
unsigned int max;
unsigned int min;
unsigned char temp;
signed long temp1;
signed long temp2;
 
flags = 0;
 
DDRB = (CH0_B|CH1_B|CH2_B);
PORTB = 0x00;
 
253,10 → 263,10
DDRD = (ledgreen|CH3_D|CH4_D|CH5_D);
PORTD = 0x00;
 
CH0 = 0;
CH1 = 0;
CH2 = 0;
CH3 = 0;
CH0 = 0xFF; //PORTB RGBLED red
CH1 = 0xFF; //PORTB RGBLED green
CH2 = 0xFF; //PORTB RGBLED blue
CH3 = 0;
CH4 = 0;
CH5 = 0;
 
263,7 → 273,7
lmax = 0x0000;
lmin = 0xffff;
 
// StartUART();
StartUART();
StartPPM();
//StartI2C();
StartPWM();
287,9 → 297,10
 
 
setup = 0; //reset setup toggle counter
temp = (1<<0);
setupdly = SetDelay(5000);
ppmtodly = SetDelay(5000);
flashdly = SetDelay(1000);
ppmtodly = SetDelay(2000);
flashdly = SetDelay(200);
while (1)
{
323,10 → 334,25
 
if (CheckDelay(flashdly))
{
CH0 = CH0 ^ 0xff;
CH0 = (temp & (1<<0)) * 255;
CH1 = (temp & (1<<1)) * 255;
CH2 = (temp & (1<<2)) * 255;
CH3 = (temp & (1<<3)) * 255;
CH4 = (temp & (1<<4)) * 255;
CH5 = (temp & (1<<5)) * 255;
temp <<= 1;
if (temp == (1<<6)) temp = (1<<0);
 
/*
CH0 = CH0 ^ 0xff; //invert brightness
CH1 = CH1 ^ 0xff;
CH2 = CH2 ^ 0xff;
flashdly = SetDelay(250);
CH3 = CH3 ^ 0xff;
CH4 = CH4 ^ 0xff;
CH5 = CH5 ^ 0xff;
*/
 
flashdly = SetDelay(100);
}
}
 
347,32 → 373,45
{
if (CheckDelay(flashdly)) //each 25ms toggle PWM's
{
CH0 = CH0 ^ 0xff;
CH0 = CH0 ^ 0xff; //invert brightness
CH1 = CH1 ^ 0xff;
CH2 = CH2 ^ 0xff;
CH3 = CH3 ^ 0xff;
CH4 = CH4 ^ 0xff;
CH5 = CH5 ^ 0xff;
 
flashdly = SetDelay(25);
}
}
 
if (CheckDelay(setupdly)) //setup timeout reached
if ((CheckDelay(setupdly)) && setup < 8) //setup timeout reached
{
setup = 8; //lockdown setup
PORTD clrbit ledgreen;
CH0 = 0; //start CH3
CH1 = 85; //CH4
CH2 = 170; //and CH4 with about 120° phase shift
 
flags = 0;
dly1 = SetDelay(100);
}
 
if (setup == 8)
{
 
temp1 = ((long)STEP * 6 * 20000) / ((max-REDUCE) - (min+REDUCE));
 
/************************************************************************************/
/* control CH3, CH4 and CH5 (RGB LED) */
/************************************************************************************/
 
temp1 = ((long)STEP * 7 * 40000) / ((max-REDUCE) - (min+REDUCE));
temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1);
color = temp2 / 20000;
color = temp2 / 40000;
if (color < 0) color = 0;
if (color > ((STEP*6)+1)) color = ((STEP*6)+1);
if (color > ((STEP*7)+1)) color = ((STEP*7)+1);
 
//printf("p %u ",ppm);
382,52 → 421,123
//printf("c %i\n ",color);
// Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb >
// Farbablauf: off > red > purple > blue > cyan > green > yellow > white
if ((color >= (STEP * 0)) && (color < (STEP * 1)))
{
CH0 = MUL * ((color - (STEP * 0))); //fade in red > red (red only)
CH1 = 0;
CH2 = 0;
CH3 = MUL * ((color - (STEP * 0))); //fade in red > red (red only)
CH4 = 0;
CH5 = 0;
}
if ((color >= (STEP * 1)) && (color < (STEP * 2)))
{
CH0 = ((STEP-1) * MUL);
CH1 = 0;
CH2 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue)
CH3 = ((STEP-1) * MUL);
CH4 = 0;
CH5 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue)
}
if ((color >= (STEP * 2)) && (color < (STEP * 3)))
{
CH0 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only)
CH1 = 0;
CH2 = ((STEP-1) * MUL);
CH3 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only)
CH4 = 0;
CH5 = ((STEP-1) * MUL);
}
if ((color >= (STEP * 3)) && (color < (STEP * 4)))
{
CH0 = 0;
CH1 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green)
CH2 = ((STEP-1) * MUL);
CH3 = 0;
CH4 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green)
CH5 = ((STEP-1) * MUL);
}
if ((color >= (STEP * 4)) && (color < (STEP * 5)))
{
CH0 = 0;
CH1 = ((STEP-1) * MUL);
CH2 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only)
CH3 = 0;
CH4 = ((STEP-1) * MUL);
CH5 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only)
}
if ((color >= (STEP * 5)) && (color < (STEP * 6)))
{
CH0 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red)
CH1 = ((STEP-1) * MUL);
CH2 = 0;
CH3 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red)
CH4 = ((STEP-1) * MUL);
CH5 = 0;
}
if (color >= (STEP * 6))
if ((color >= (STEP * 6)) && (color < (STEP * 7)))
{
CH0 = ((STEP-1) * MUL); //fade in red > yellow (green + red)
CH1 = ((STEP-1) * MUL);
CH2 = 0;
CH3 = ((STEP-1) * MUL);
CH4 = ((STEP-1) * MUL);
CH5 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue)
}
 
if (color >= (STEP * 7))
{
CH3 = ((STEP-1) * MUL);
CH4 = ((STEP-1) * MUL);
CH5 = ((STEP-1) * MUL);
}
 
/************************************************************************************/
/* control CH0, CH1 and CH2 */
/************************************************************************************/
 
if (CheckDelay(dly1)) //timeout reached ?
{
 
if ((flags & (1<<0))==0) //check if up or down
{
if (CH0++ == 254) //run CH0 up to 255
{
flags setbit (1<<0); //255 reached next time go down
 
}
}
else //run down
{
if (CH0-- == 1) //run CH0 down to 0
{
flags clrbit (1<<0); //0 reached next time go up
}
}
 
 
if ((flags & (1<<1))==0) //same for CH1
{
if (CH1++ == 254)
{
flags setbit (1<<1);
}
}
else
{
if (CH1-- == 1)
{
flags clrbit (1<<1);
}
}
 
 
if ((flags & (1<<2))==0) //and same for CH2
{
if (CH2++ == 254)
{
flags setbit (1<<2);
}
}
else
{
if (CH2-- == 1)
{
flags clrbit (1<<2);
}
}
 
 
dly1 = SetDelay(1); //set next timeout in 25ms
 
// printf("ch3:%i\n",CH0);
}
 
}
 
 
}
 
}