Society of Robots - Robot Forum

Software => Software => Topic started by: minmx on May 08, 2010, 11:33:00 AM

Title: question for c
Post by: minmx on May 08, 2010, 11:33:00 AM
hi, i have a question: how can i put the pause inb c code?
Title: Re: question for c
Post by: amando96 on May 08, 2010, 01:04:10 PM
in milliseconds: delay();
in microseconds: delaymicroseconds();
Title: Re: question for c
Post by: Benn on May 08, 2010, 02:05:47 PM
hmmm...depends...
There are some IDE that give you function like those amando96 said...but there are others that don't.
The most simple solution is something like this:

void delay(int a)
{
    int i;
    for (i = 0; i < a; i++)
    {
        _nop();
    }
}

main(void)
{
    ....
    delay(100000);
    ....
}

Also depends on what uC you use. The one i worh with has the _nop() function that does NOTHING, but wait for a tick. Here comes the frequency setup. But in my example, the function will delay around 1.25ms , with 80MHz frequency.
I say around, because there are others ticks lost when the compiler transforms the C code into ASM.
Title: Re: question for c
Post by: Admin on May 11, 2010, 05:15:42 AM
Going from what Benn said . . . what microcontroller are you using?