while (1)
{
// cycles led according to brightness
if (!counter[C_TEST])
{
if (lighton == 1)
{
lighton = 0;
ledBits = 0x03;
setCounter(C_TEST,brightness);
}
else
{
lighton = 1;
ledBits = 0x00;
setCounter(C_TEST,10-brightness);
}
serviceLEDs();
}
//causes fade variable to slowly increase and decrease from 1 to 10 and back
if (!counter[C_TEST2])
{
setCounter(C_TEST2,2400);
if (fadedirection == 0)
{
brightness--;
if(brightness <= 0){fadedirection = 1;}
}
else
{
brightness++;
if(brightness >= 10){fadedirection = 0;}
}
}
}
}
//This pulses the servo line
if (!counter[C_SERVO])
{
if (ServoPortOn == 1)
{
ServoPortOn = 0;
ServoPin = 1;
setCounter(C_SERVO,ServoPulseLength);
}
else
{
ServoPortOn = 1;
ServoPin = 0;
setCounter(C_SERVO,ServoPulseLength);
}
}
ok a char is -128 to +127 and a unsigned char is 0-254 ...
//This pulses the servo line
//4000 = 1 second so 80 = 20mS 2 = 0.5 mS and 10 = 2.5mS
ServoPulseLength = brightness;
if(ServoPulseLength > 10){ServoPulseLength = 10;}
if(ServoPulseLength < 2){ServoPulseLength = 2;}
if (!counter[C_SERVO])
{
if (ServoPortOn == 1)
{
ServoPortOn = 0;
ServoPin = 1;
setCounter(C_SERVO,ServoPulseLength);
}
else
{
ServoPortOn = 1;
ServoPin = 0;
setCounter(C_SERVO,80-ServoPulseLength);
}
}
Actually unsigned char is 0...255.
Max can be found with: max=2^bit_length-1. For 8 bits that makes 2^8=256 steps and max. value is 2^8-1 = 255.
while(1) // main loop
{
if (!kTimer[CRITICAL])
{
taskCritical();
}
else
{
// other tasks here
if (!kTimer[BLINK])
{
taskBlink();
}
if (!kTimer[BEEP])
{
taskBeep();
}
}
while(waitForTimer);
waitForTimer = TRUE;
}
-------------
As a rule the kTimer update should only happen while we are waiting at the bottom of the loop.But it sounds like what you're saying is that unless the next Ktimer update happens while 2 is occuring, nothing will be missed. Is that right?
1. (INIT)
setup hardware to capture pulse length
block on hardware done flag
seq=2
2. (DOIT)
copy pulse length to some var
clear done flag
setup hardware to capture pulse length
block on done flag
seq=2
sorry, what do you mean by doing it using hardware? You mean like the capture compare module on the chip?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?