|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
loop problems
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 will take about 0.5 second right? anyways I get a syntax error, can somebody help me? Thanks! |
|
#2
|
|||||
|
|||||
|
Re: loop problems
Four problems jump out at me immediately.
1) This code will execute in a fraction of an eyeblink. It won't even come close to a half second. 2) 255 is not a proper value to send to a pwm. The highest number you should use is 254. 3) You aren't calling Putdata(&txdata) inside the loop. That means the value being stored in pwm06 will not be sent to the hardware until some time after the whole thing is done, so it'll never be set to the high value. 4) Finally, you didn't tell us what the syntax error is, so we can't easily tell you how to fix it. It's almost never a good idea to put a timing loop like this inside your code, even if you get the loop time set to what you want. If you don't like interrupt-based timers, you can use the fact that Process_Data_From_Master_uP() is called about 39 times per second and maintain a counter to do things after a certain number of calls. |
|
#3
|
|||
|
|||
|
Re: loop problems
Ok..
Im passing on to the real timers. Can somebody explain me shortly how to use them, and what files do I need and where to include them? I had some problem with this. |
|
#4
|
|||||
|
|||||
|
Re: loop problems
Quote:
|
|
#5
|
||||
|
||||
|
Re: loop problems
Max
You can try something like this to set the pwm value to 127 after 30 loops: Code:
void pulse(void)
{
static int loop_count = 0;
if(loop_count < 30)
{
pwm06 = 254;
}
else
{
pwm06 = 127;
}
loop_count++;
}
|
|
#6
|
|||
|
|||
|
Re: loop problems
Quote:
|
|
#7
|
|||
|
|||
|
Re: loop problems
Quote:
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Loop time for OperatorControl function? Debug blows... | Chris_Elston | Programming | 10 | 13-02-2006 14:42 |
| Anyone Else Having Problems with Q&A on FIRST? | Windwarrior | General Forum | 6 | 25-01-2006 10:54 |
| While Loop Require in OperatorControl? | Chris_Elston | Programming | 2 | 15-01-2006 14:29 |
| Rewriting main loop | Max Lobovsky | Programming | 4 | 04-01-2005 18:35 |
| laser radar with BS2p using RS232 problems... | chei_UCF19 | Programming | 6 | 26-02-2004 15:21 |