AnsweredAssumed Answered

9S12ZVL Waterfall effect on RGB LED with other operation

Question asked by Efrain Castro on Jan 10, 2019
Latest reply on Jan 11, 2019 by Diana Batrlova

Hello NXP community

I have been trying to run an RGB led and some WHITE leds at the same time using the timer and the delays in the S12ZVL64.
The RGB LED works as a waterfall to show different LED colors, let's say it produces an environment, while the WHITE LED is only for lighting, like turning on the light. What I'm trying to do is that the RGB is always on, while I can still turn on the WHITE leds through a button. The only problem I have is that when the RGB is running I can not turn on the WHITE leds unless I put a break; in the FOR of the RGB causing the cascade effect to disappear but at least the WHITE leds turn on.

What can I do so that the waterfall effect on the RGB led does not interfere with the WHITE leds?

 

void LED_Colors(void)
{ int i;

while(1){
//for(; ;)
//Red
//{
for(i=0;i<0xFF;i++)
{
BigTimerDelay(1);
PWM1DTY5+=1; //Red
PWM0DTY3=0x00; //Green
PWM0DTY7-=1; //Blue
}
//Green
for(i=0;i<0xFF;i++)
{
BigTimerDelay(1);
PWM1DTY5-=1; //Red
PWM0DTY3+=1; //Green
PWM0DTY7=0x00; //Blue
}
//Blue
for(i=0;i<0xFF;i++)
{
BigTimerDelay(1);
PWM1DTY5=0x00; //Red
PWM0DTY3-=1; //Green
PWM0DTY7+=1; //Blue
}
break;
// }
}
}

 

void BigTimerDelay(unsigned int ttime)
{
unsigned int i;

TIM0TSCR1 = 0x80; //enable timer
TIM0TSCR2 = 0x01; //Prescaler=1 (2nd way to control Delay size is using 0 to 7)

for(i=0;i<ttime;i++)
{

TIM0TFLG2 = 0x80; //clear the TOF flag

//while (!(TIM0TFLG2 & TIM0TFLG2_TOF_MASK)); //wait for Timer Overflow
while ((TIM0TFLG2 &0x80)==0); //you can use this line instead
}

}

Outcomes