SimpleIDE, C: Counting milliseconds
ptiago
Posts: 37
Hi,
Probably the question is not new...
I need to count the milliseconds, and i would like to be efficient and reliable.
I made a simple C program to test (attached).
To make it short: this is the method executed in a cog:
volatile static unsigned long millis=0;
void countMillis(void *par)
{
while(1)
{
millis++;
waitcnt(CLKFREQ_1000 + CNT);
}
}
this is the code to measure the 1sec waiting
ts1 = millis;
waitcnt(CLKFREQ + CNT);
ts2 = millis;
the delta (ts2-ts1) is 992/993 ms, there is a gap of 7 to 8 ms, countMillis, performs two sum operations and the measure code one sum operation plus the assigning variables etc.
what i can do minimize the gap, or to obtain the most realist milliseconds counter ?
Thanks,
Tiago
Probably the question is not new...
I need to count the milliseconds, and i would like to be efficient and reliable.
I made a simple C program to test (attached).
To make it short: this is the method executed in a cog:
volatile static unsigned long millis=0;
void countMillis(void *par)
{
while(1)
{
millis++;
waitcnt(CLKFREQ_1000 + CNT);
}
}
this is the code to measure the 1sec waiting
ts1 = millis;
waitcnt(CLKFREQ + CNT);
ts2 = millis;
the delta (ts2-ts1) is 992/993 ms, there is a gap of 7 to 8 ms, countMillis, performs two sum operations and the measure code one sum operation plus the assigning variables etc.
what i can do minimize the gap, or to obtain the most realist milliseconds counter ?
Thanks,
Tiago
Comments
Thanks, it works !!!!
1000 ms, in all the cogs at same time.
Tiago