Resolution of netMF timer on G120 SOM

I am using the G120 SOM. I need a timer with 1-millisecond resolution. Is this possible with a netMF timer?

NETMF is not real time. You will need to use tasks through RLP to get that resolution.

what are you trying to accomplish?

I need a free-running 16-bit 1ms timer. I would like to poll it often enough to maintain 2-3ms accuracy. I need to time multiple valves opening and closing with minimum 7-12 ms duration. I also need to time the wait between opening/closing, maximum of 5 seconds. I have 30-60 events to control, however none of them last longer than 10 seconds per event. I would like to use software control because the timing varies in real-time based on external events.

NETMF is not well suited for what you need. Typically, our customers use NETMF to control the user interface display and networking and use a small micro to handle the little time critical tasks. Using RLP tasks is another option but i have limited info to tell you if it is going to work.

OK, so that I can understand what I need to move off of the G120 or do in RLP tasks, can NETMF handle somewhere between 5ms and 20ms resolution?

Also, is there a small micro in GHI’s catalog you would recommend?

The thread handler runs on idle or every 29ms.

We have many modules with small micros. Take DL40 for example.

OK, so when I set up a timer using netMF according to the example below, I’m thinking I shouldn’t set ## to anything smaller than 30. Otherwise, if the thread is busy, I can miss a tick.

class Timer
{
    static Timer TIMER;
    static UInt16 TICK;

    public void Init()
    {
       TIMER = new Timer(new TimerCallback(Service), null, 0,##);
    }
    void Service(object obj)
    {
        TICK++;
    }
    public UInt16 GetTick()
    {
       return RETURN_TICK;
    }

}

Why?

You could set it lower.

Gus was telling me that the thread handler runs on idle or every 29 ms. So, if I have 25 ms set and I keep the thread busy, it will run longer than a tick, and I will miss the tick.

20ms

The best would be to read how threads are handled in the documentation of the porting kit.

OK, thanks, I will download the porting kit and read how threads are handled. In the meantime I won’t try to set the timer below 20ms.

You can set it to 1ms and it will work but if you have a busy system them it may not happen for 20ms or multiple of it.

OK, thanks, that clarifies the situation for me. It also explains why some previous code worked with a shorter timer-- the system was less busy. I have one main thread, which is set up to be a service loop. It does a Thread.Sleep(0) each time through the service loop, which I think is required so that the timer can be polled. A 20ms timer works right now, but as the code grows I will need to keep the service loop short or I will start missing ticks.