I use codewarrior 3.1 and i want to know how to make delay on
controller with C.
and another question please how to use trigonometric functions
including the required header files.
thanks in advance!
how to make delay with C
Started by ●June 28, 2005
Reply by ●June 28, 20052005-06-28
Hey one way of giving delay is put a for loop.
Ex: int i;
for(i=0;i<2000;i++);
Again this depends upon what processor speed u are using.
To verify you can go to Debugger provided by Code warrior. i.e Green
ICON in your IDE.
In debugger window select Simulator\clock frequency.
Here u can set the desired cpu frequency. After setting the freq set
a break points at before for loop and instruction after for loopthen
execute. At the below u will get the time taken to execute the for
loop. This is crude method of getting a delay.....
If you want accurate delay then configure one of timers in output
compare mode and go ahead.
I think this solves your problem
Ex: int i;
for(i=0;i<2000;i++);
Again this depends upon what processor speed u are using.
To verify you can go to Debugger provided by Code warrior. i.e Green
ICON in your IDE.
In debugger window select Simulator\clock frequency.
Here u can set the desired cpu frequency. After setting the freq set
a break points at before for loop and instruction after for loopthen
execute. At the below u will get the time taken to execute the for
loop. This is crude method of getting a delay.....
If you want accurate delay then configure one of timers in output
compare mode and go ahead.
I think this solves your problem
Reply by ●June 28, 20052005-06-28
If you are using such a busy loop like the one below: make sure that you
write it in assembly/inline assembly so you control the exact time.
For the case below you may want to declare 'i' as volatile: the compiler may
optimize it away as the loop is not doing anything.
A more elegant solution would be to set up a timer.
Erich
write it in assembly/inline assembly so you control the exact time.
For the case below you may want to declare 'i' as volatile: the compiler may
optimize it away as the loop is not doing anything.
A more elegant solution would be to set up a timer.
Erich