Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Using the Internal Real-Time Timer (RTT)

gfcwfzkm

  • Please log in to reply
5 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 19 June 2013 - 07:01 AM

Hi,

(I have the Netduino Plus)

I need and Interrupt every 1 Second. How can i use the Real-Time Timer (RTT) of the AT92SAM7X512 ?

 

If its not possible, is there an other way to do it? I need to run Some Code every Second.

 

mfg & thx

 

gfcwfzkm



#2 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 19 June 2013 - 09:49 PM

Hello,

 

You can use a timer method from the .NETMF http://msdn.microsoft.com/en-us/library/hh435851.aspx

 

For example:

class Program    {        public static void Main()        {                Timer everySecond = new Timer(someMethod, null, 0, 1000);                // Continue with code here        }        private static void someMethod(object state)        {                // Do something        }    }

You could create a new class with an event handler triggered by the timer to create a sort of interrupt:

class interruptTimer    {	    public delegate void timerEventDelegate(object sender, timerArgs e);	    public event timerEventDelegate timerEvent;        // Any arguments you'd like passed by the timer event	    public class timerArgs : EventArgs	    {		    public string Options { get; internal set; }	    }	    private void onTimerEvent(timerArgs e)	    {		    if (timerEvent != null)			    timerEvent(this, e);	    }                private Timer interrupter;        	    public interruptTimer(int period, int delay = 0)	    {		    interrupter = new Timer(triggerInterrupt, null, delay, period);	    }	    private void triggerInterrupt(object state)	    {		    timerArgs args = new timerArgs();		    args.Options = "foo";		    onTimerEvent(args);	    }    }

And use it like this:

public class Program    {        public static void Main()        {            interruptTimer timer = new interruptTimer(1000, 0);            timer.timerEvent += new interruptTimer.timerEventDelegate(someMethod);        }        private static void someMethod(object sender, interruptTimer.timerArgs e)        {            // Your code here        }    }

Apparently the timer will run in a new thread created by the system, so if you need a very precise execution (e.g. every second exactly) this may not be for you since in will rely on the task scheduling engine. Also, periodic timers aren't rescheduled until after the called method finishes, so you might end up with a longer than one second period if your called method takes a while to execute. I don't know if it's possible to directly access the hardware timer on the chip through the TinyCLR, but if it isn't, you may need to do some custom firmware modifications.

 

Hope this helps!



#3 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 20 June 2013 - 07:04 AM

=D Thanks, this helps a lot. But that means, that i cant use the Internal Hardware from the MCU directly?



#4 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 20 June 2013 - 02:11 PM

As far as I know, you can't access the MCU hardware timer directly through managed code, as the runtime abstracts away from the hardware. I could be wrong, but I think the runtime itself does use the hardware timer for its timing functions, so when you call Thread.Sleep() for instance, the runtime knows how long to sleep by using the internal timer. So in a way, you are accessing the internal timer, just through the runtime.

 

Out of curiosity, what project is this for? Does it require very precise timing?



#5 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 24 June 2013 - 01:36 PM

Its to repeat the Value of a TemperatureSensor (LM75A) over UART. But its more for Home-Stuff ^^



#6 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 24 June 2013 - 10:02 PM

Sounds like fun! If you're just repeating a temperature reading over UART I think using the Timer class should work fine, either directly or as a class with an event handler. Whatever you come up with, good luck and keep us posted!







Also tagged with one or more of these keywords: gfcwfzkm

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.