100 ms. delay


I have a question: Is there some sort of background thread/timer or something running in the firmware that causes a blocking/delay approx. every 5 seconds? I have now done a lot of testing to make sure that this was not caused by me. I made a fresh start, erased everything and made a new tiny project containing only the following lines of code:

private static DateTime now;
        private static DateTime last = DateTime.Now;
        public static void Main()
            while (true)
                now = DateTime.Now;
                TimeSpan time = (now - last);//calculate the time between now and the last run
                last = DateTime.Now;
                Debug.Print(now.ToString() + " - " + time.Milliseconds);

The code will do a debug.print of the time differences of each run in a loop. In my setup the debug.write (which I know is slow) takes about 13-14 ms. to complete, but at about every 5 seconds the processing takes exactly 100 ms extra to complete. Below is a small dump of the output:

01/01/2009 00:01:26 - 14
01/01/2009 00:01:26 - 113
01/01/2009 00:01:26 - 13

01/01/2009 00:01:31 - 14
01/01/2009 00:01:32 - 113
01/01/2009 00:01:32 - 14

01/01/2009 00:01:37 - 14
01/01/2009 00:01:37 - 114
01/01/2009 00:01:37 - 13

What could be causing this?
It’s to precise to be cause by the GC and that would also cause debug info to be written to the output window…as far as I know. I also testet this using thread.sleep and added the times to a list without doing debug.prints and it’s the same result: a 100 ms. delay.

This is a real problem for me. Because I need to count pulses and close a valve on a pump and a 100 ms. delay really messes this up.

I realise it’s not a realtime system, and small variations can happen, but this is just to much of a variation.

Kind regards


Plug in Ethernet cable, does that delay go away?

I have also experienced this behavior. In my case I was using PWM output to fade LED in and out. I noticed that every few seconds the LED is not fading smoothly (hangs) for a small period of time. Tricon Data test however is more accurate. I am not using Ethernet connection.

@ Garlin, was it cobra?

@ Gus Correct

I did not even start with micro.NET, but even than I think I know source of your problem:
Debug.Print(now.ToString() + " - " + time.Milliseconds);

You are creating several objects of type String in each cycle. Framework has to sweep away them from time to time. I expect your delay is simply garbage collector.

Quick easy way to test the GC for sure is to force collection at the end of each loop. If that stabilizes things you know where your problem lies. Also check that ethernet cable suggestion.

@ Gus
My thouhgts exactly. I suspect that it’s a result of the EthernetOscillator too (at least thats what I think you are thinking ;D), but I haven’t been able to turn if off. Using the following method freezes the entire module:


Anyway your trick works: as soon as I plug in an ehternet cable the delay disappears.
So how do I turn it off without a cable (that would result in very long cables for this project)? :wink:

@ m-land
Believe me I have done several test as I mention in my post using different approaches and its always 5 seconds. And the GC would never run in such precise intervals (every 5 seconds). But thanks for your suggestion, nice that people try to help ;D

Kind Regards

@ Tricon Data
OK, I belive you :wink: I did not catch in your initial post that it is 5 seconds with every program, not only with this particular one - sorry. Because for such program like your example there is perfect reason for framework to run GC in regular intervals (this program does still the same - and allocates still amount of memory to do so - so GC will run in precise intervals)

We are on it…you do nto have to do anything, just wait and we will come up with a fix :slight_smile:

Please try this firmware:

Thanks for the fast response guys,

I will try it out and let you know how it goes. :slight_smile:

@ Tricon,

Let me know how the beta works out for you; I may use it myself.

It works in my case. This beta firmware contains fix only for this issue or more ?

That was only one fix, a firmware generated just for your problem :slight_smile: How is that for tight support? :wink:

This makes us feel that we’re not left alone :wink: Will you include this fix in next release ?

Hi Gus & Co

The firmware solves the problem.
Very nice support indeed :o)



Absolutely but for now just use this firmware.

This is great news to me too. Two weeks ago I was trying to pick the best host PC interface for my datalogger app and was chosing between WiFi and Ethernet (on EXM dev board). With WiFi I was getting these same weird delays every five seconds and with Ethernet everything was fine. Of course I was blaming my WiFi infrastructure and ZG2100 for all this… Turns out this was a bug in Ethernet :slight_smile:

Thanks for solving the problem you guys!!

Just found this post. Does this problem was related to the EthernetOscillator or not? because in the last release, disabling the Oscillator still goes on to freeze the board.