Interrupt response time

Look at the ExtendedTimer class.

This is a complete code to what Gus described above:

using System;
using System.Threading;
using Microsoft.SPOT;

using GHIElectronics.NETMF.Hardware.LowLevel;
using GHIElectronics.NETMF.Hardware;

namespace MFConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            Register PCONP = new Register(0xE01FC0C4);
            PCONP.SetBits(1 << 22);//enable timer2 

            // Select IO0 on EMX CAP2.0
            Register PINSEL0 = new Register(0xE002C000);
            PINSEL0.SetBits((3 << 8));//set bits 8 and 9

            // To enable timer/counter
            Register T2TCR = new Register(0xE0070004);
            T2TCR.Write(1);

            // set prescale to 0
            Register T2PR = new Register(0xE007000C);
            T2PR.Write(0);
            
            Register T2CTCR = new Register(0xE0070070);
            T2CTCR.Write(2 << 0 | 0 << 2);//count on falling edge and use CAPn.0
            
            // should be 0 for a counter
            Register T2CCR = new Register(0xE0070028);
            T2CCR.ClearBits(0x07);

            // Don't do anything on match
            Register T2MCR = new Register(0xE0070014);
            T2MCR.Write(0);

            // To reset the counter
            T2TCR.SetBits((1 << 1));
            T2TCR.ClearBits((1 << 1));

            // To read
            Register T2TC = new Register(0xE0070008);
            while (true)
            {
                uint count = T2TC.Read();

                Debug.Print("Total count: " + count);

                Thread.Sleep(1000);
            }
        }
    }
}

Nice
This is exactly what I needed. I couldn’t get Timer 2 to work for some reason.
Thanks.
The processor supports interrupts when a match between a counter and a match register occurs. Is there any way to “subscribe” to such an interrupt.
On way is to toogle a pin and then wire this pin to another pin and then add an InterruptPort on that to get an “external” interrupt, but thats a bit ugly in my oppinion.

Hope you can help

Thanks again for the example.

Regards Kenneth

You cannot hook up native interrupts from managed code…
Looping every second doesn’t work? Native interrupt doesn’t have advantages if you need it every second.

I didn’t think it was possible, but worth asking :smiley:
Well I will either loop and read from the register or use the approach I mentioned. The advantage of the latter is that I will only need to do some work when I get an external interrupt on a match.

Thanks

/Kenneth

Hi

I’ve run into an issue playing arround with the internal timers. It seems that every 5 seconds a delay/blocking occurs. First I tried the approach I described above…wire two pins together and have the processor toogle the pin when a match of 100 pulses occur at a rate of 1 per ms. That results in 1 screwed up pulse every 5 second. Now I only have a thread that loops every 10 ms doing nothing (not even reading from the register) and no pins wired together. And still every 5 seconds it sleeps for way more than arround 10 ms (actually about 100 ms more).
What could be doing this? It can’t be the GC because I don’t do anything in the thread so nothing should be GC’ed and that wouldn’t happen every 5 seconds precisely.

I’m not even sure that it’s related to the internal timers?
Hope you can help.

Regards Kenneth

How do you know this? (every 5 seconds, there is a delay).
Please provide code that we can look into.

Ok here you go.

I just made a new console app that only has the following loop. If the sleep time for some reason gets above 100 ms. I do a Debug.Print. On my devices (2 EMX dev. boards, 1 EM module, 1 FEZ Cobra) they all sleep for more than 100 ms. every 5 seconds.
The first times it might not be 5 seconds, but after a few times it gets stable arround 5 seconds.

The code:

    private static DateTime now;
    private static DateTime last = DateTime.Now;
    public static void Main()
    {
        while (true)
        {
            now = DateTime.Now;
            if ((now - last).Milliseconds > 100)
                Debug.Print(now.ToString()); 
            last = DateTime.Now;
            Thread.Sleep(10);
        }
    }

Thats all I’m doing atm. The registers get reset when power is removed right?

/Kenneth

NETMF is not real-time so it is normal and expected to see different delays

If it is not 100 then it will be a bit more like maybe 110 but it should not be 10000 for example

The FAQ explains this in details

[quote]I do a Debug.Print. On my devices (2 EMX dev. boards, 1 EM module, 1 FEZ Cobra) they all sleep for more than 100 ms. every 5 seconds.
[/quote]

What does “they all sleep for more than 100 ms every 5 seconds” mean. The processor will not sleep unless you tell it to so I’m not sure what your meaning is…

I have a diffrent question, I have implemented a demo and now I want to change the pin, where the signals came to count, is this posible?

I have read the Manuel and in PINSEL0 you can select diffrent pins, but I never get any other Pin to count.

Can you give me a hint how to change the pin?

best regards

Go back to my original post where I detail what each line does. This is very advanced anyway and you are expected to full understand the internals of the processor

I know the processor only sleeps if I tell it to. I tell it to sleep for 10 ms and it ends up sleeping for more than 100 ms. That’s not normal, even though it’s not realtime…it should be 9,10,11 ms. or some where around those numbers. I have not seen this behavior before and I have been working with embedded master since the first .net micro framework releases.

Could you please try my little sample in the previous post?

Even better, here is complete code and explanation :wink:
http://www.tinyclr.com/forum/10/1458/

Gus,

Wrong link.
We are in the 1458 thread.
:wink:

Gus would it be possible to repost your register class code? It appears the code snippets were lost when things were converted over to the new forum.

There is tutorial for register class under “support”. Please check it out.