[En-Nut-Discussion] Timing issues on Ethernut 1.3 (AVR)

Daniel ziu82 at gmx.de
Tue Nov 10 18:58:01 CET 2009


Hi Guys,
 
After working since weeks with strange timing behavior, I now have to ask
you for help.
 
Issue 1, NutGetMillis()
=======================
I tried the following code in a large application (10 Threads, 105kByte
compiled code):
 
uint32_t start = NutGetMillis();
uint32_t end   = start + 500;     // Timeout after 500ms
uint16_t i     = 0;
 
do
{
    NutThreadYield();
   
    // Get a status byte from somewhere
 
    i++;
    if(i > 500)
    {
                printf("Current Millis: %lu ms\n", NutGetMillis());
                i=0;
    }
while(!(status & 0x80) && (NutGetMillis() < end));
 
 
Wenn i execute this code, then the output of NutGetMillis() needs 9 real
seconds to count 100ms.
Consequent to this timing, the loop exits after around 45 seconds.
 
When i output NutGetMillis() in a 1-Thread-app, it works fine. So, why it
does not work in my large app?

 
Issue 2, NutGetTickCount()
======================
Maybe it's the same problem like above. I tried to log my thread timing (10
Threads, 105kByte compiled code) with this pseudo code:

THREAD(MyThread, arg)
{
	// insert unique thread number and Tick Count to a buffer at start
of execution
	AddBuffer(ThisThreadNumber, NutGetTickCount());

	/*  Some code here, sometimes large routines */

	// insert unique thread number and Tick Count to a buffer at the end
of execution
	AddBuffer(ThisThreadNumber, NutGetTickCount());
}

After executing my application a few seconds, i outputted my buffer. I
expect that the ticks - logged at the end of each thread - must be greater
than the ticks at the start. But at every Thread, the ticks at start and end
are the same. See a small log below.

Thread, Ticks
8, 11223
8, 11223 
1, 11244 
1, 11244 
2, 11296 
2, 11296 
1, 11296 
1, 11296 
4, 11296 

So it seems to be the same problem like i have with NutGetMillis(), because
it's calculated out of the tick counts.


The only hint i have is that I'm using the _delay_us(x) function, which is
not from Ethernut. Maybe there`s the problem?


Best regards,
Daniel




More information about the En-Nut-Discussion mailing list