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

Simple timer

timer interrupt start button

  • Please log in to reply
1 reply to this topic

#1 mihulich

mihulich

    New Member

  • Members
  • Pip
  • 1 posts
  • LocationSaint Petersburg, Russia

Posted 01 April 2013 - 04:36 PM

Please, be kind! Here is another topic "Netduino Timers", but there is no usefull information for me. I need to measure a friquency of incoming impulses, so i decided to use timers and interrupts. I want to start a timer with first interrupt from a sensor and then stop this timer with a second interrupt. In TimerCallback I wanted to add 1 with every timer tick. But do not understand how to start and stop a timer with the same event! Help me please.. At fist i want to test it with button interrupt, but it does not work correctly( The second interrupt does not work and timer ticks constantly :mellow:

My code:

 

namespace Timer_testing_LED{    public class Program    {        private static Timer oneHerzTimer = null;        private static OutputPort LED = null;        private static InterruptPort button = null;        public static int i = 0;        public static int j = 0;        public static void Main()        {            LED = new OutputPort(Pins.ONBOARD_LED, false);            button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLevelHigh);            button.OnInterrupt += new NativeEventHandler(button_Interrupt_Event);            //timerEvent = new TimerCallback(TimerInterrupt);            while (j < 2)            {                if (j > 0)                {                    oneHerzTimer = new Timer(new TimerCallback((object data) =>                    {                        i++;                        LED.Write(!LED.Read());                    })                        , null, 100, 500);                    Thread.Sleep(Timeout.Infinite);                }            }        }        private static void TimerInterrupt(object state)        {            i++;            //LED.Write(!LED.Read());        }        private static void button_Interrupt_Event(uint data1, uint data2, System.DateTime time)        {            if (j > 0)            {                oneHerzTimer.Dispose();                oneHerzTimer = null;                for (int k = 0; k <= (i / 2); k++)                {                    LED.Write(true);                    Thread.Sleep(50);                    LED.Write(false);                    Thread.Sleep(350);                }            }            j = 2;        }    }}

 

 

 



#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 01 April 2013 - 07:38 PM

Welcome to the community.

 

Not sure why you need a timer as the third parameter to the interrupt handler is the time at which the interrupt happened.  Can't you just use that.  Say, store the value the first time the interrupt happens and then take the difference the second time it happens.

 

If timers are the only route then check out this post on NETMF Timers.

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter






Also tagged with one or more of these keywords: timer, interrupt, start, button

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.