Quote:
|
Originally Posted by Max Brin
Hey guys,
I had some problems using the timers and I need something that will take time asap, so I did this:
Code:
void pulse(void)
{
pwm06=255;
for (int i=0;i<30;i++)
{
if (i == 29)
{
pwm06=127;
}
}
}
It means the pwm06 will get 255 and when it gets to 29 it will stop.
It will take about 0.5 second right?
anyways I get a syntax error, can somebody help me?
Thanks!
|
syntax error is caused by trying to declare i in the for loop
in C all variables must be declared at the top of the function.
This still will not do what you want because the pwm value is not sent out until Putdata is called. (see user_routines.c )
One way to accomplish what you want is to use a static counter variable. Increment each time the function is called. When the desired value is reached, change the pwm value and reset the counter variable.