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

Multiple InterruptPorts being fired?


  • Please log in to reply
5 replies to this topic

#1 EnergySmithe

EnergySmithe

    Member

  • Members
  • PipPip
  • 10 posts

Posted 14 July 2014 - 05:38 PM

I was wondering if someone could sanity check this schematic and tell me if I am doing something wrong?  What I have is one 3 position momentary toggle switch (common + two poles, normally off in center) and two reed switches all configured with pull down resistors to the Digital IO pin.  (These are simulated in the diagram below with momentary pushbuttons.)  If I define all four inputs (D8, D11, D12, D13) as InterruptPorts and assign NativeEventHandlers what I am seeing is that if I push any one of the buttons then most or all of the other handlers get fired?  The other handlers report that they are False on both edges, but they are still being triggered.

 

Does this make sense?  I am thinking this has something to do with them sharing 3.3v, but not sure?

 

Any thoughts are welcome.  Thanks.

Attached Files



#2 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 14 July 2014 - 06:08 PM

looks fine



#3 EnergySmithe

EnergySmithe

    Member

  • Members
  • PipPip
  • 10 posts

Posted 14 July 2014 - 09:00 PM

The wiring seems basic, but I am confused by the debugging results - I added debugging statements to the events and when the toggle is used it ends up firing the magnetic reed switches handler, etc.  But it appears like the value in data2 param of those other triggers is always false.  So could this be some type of feedback?  



#4 perpetualKid

perpetualKid

    Member

  • Members
  • PipPip
  • 20 posts

Posted 14 July 2014 - 09:34 PM

maybe you can post your code so we can have a look? :)

#5 EnergySmithe

EnergySmithe

    Member

  • Members
  • PipPip
  • 10 posts

Posted 15 July 2014 - 07:17 AM

  Sure, here is test code I was playing with:

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace SwitchDemo
{
    public class Program
    {
        // take care of initializing relay that is connected...
        OutputPort r0 = new OutputPort(Pins.GPIO_PIN_D0, true);
        OutputPort r1 = new OutputPort(Pins.GPIO_PIN_D1, true);
        OutputPort r2 = new OutputPort(Pins.GPIO_PIN_D2, true);
        OutputPort r3 = new OutputPort(Pins.GPIO_PIN_D3, true);
        OutputPort r4 = new OutputPort(Pins.GPIO_PIN_D4, true);
        OutputPort r5 = new OutputPort(Pins.GPIO_PIN_D5, true);
        OutputPort r6 = new OutputPort(Pins.GPIO_PIN_D6, true);
        OutputPort r7 = new OutputPort(Pins.GPIO_PIN_D7, true);
        
        static InterruptPort sensorTop = new InterruptPort(Pins.GPIO_PIN_D8, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
        static InterruptPort sensorBottom = new InterruptPort(Pins.GPIO_PIN_D11, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
        static InterruptPort switchUp = new InterruptPort(Pins.GPIO_PIN_D12, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
        static InterruptPort switchDown = new InterruptPort(Pins.GPIO_PIN_D13, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);


        public static void Main()
        {

            sensorTop.OnInterrupt += new NativeEventHandler(test_events);
            sensorBottom.OnInterrupt += new NativeEventHandler(test_events);
            switchUp.OnInterrupt += new NativeEventHandler(test_events);
            switchDown.OnInterrupt += new NativeEventHandler(test_events);

            Thread.Sleep(Timeout.Infinite);
        }

        private static void test_events(uint data1, uint data2, DateTime time)
        {
            // Debug.Print("data1=" + data1.ToString() + ", data2=" + data2.ToString() + ", time=" + time.Ticks.ToString());
            if (data1 == (uint)sensorTop.Id)
            {
                sensorTop.DisableInterrupt();
                Debug.Print("sensorTop::value=" + data2.ToString());
                sensorTop.EnableInterrupt();
            }
            else if (data1 == (uint)sensorBottom.Id)
            {
                sensorBottom.DisableInterrupt();
                Debug.Print("sensorBottom::value=" + data2.ToString());
                sensorBottom.EnableInterrupt();
            }
            else if (data1 == (uint)switchUp.Id)
            {
                switchUp.DisableInterrupt();
                Debug.Print("switchUp::value=" + data2.ToString());
                switchUp.EnableInterrupt();
            }
            else if (data1 == (uint)switchDown.Id)
            {
                switchDown.DisableInterrupt();
                Debug.Print("switchDown::value=" + data2.ToString());
                switchDown.EnableInterrupt();
            }

        }


    }

}

With a the reed switch (top sensor) when closing the circuit we get this:

 

sensorTop::value=1
sensorTop::value=0
sensorTop::value=1
sensorTop::value=0
sensorTop::value=1

When I open the circuit (pull magnet away) I get this.
sensorTop::value=0

 

So bouncing at the start...

 

But when I flip the toggle switch UP (switchUp) I get this:

switchDown::value=0
switchUp::value=1
switchUp::value=0
switchDown::value=0
switchUp::value=0
switchUp::value=0
switchDown::value=0
switchUp::value=0
switchUp::value=0
switchDown::value=0
switchUp::value=1
switchUp::value=0

 

When I let it return to home (off) I get this:

 

switchUp::value=0

Maybe I need to switch to a pull up resistor configuration with a capacitor for denouncing?

 

Thanks guys



#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 15 July 2014 - 02:32 PM

I guess the output of toggling switch UP is affected by DisableInterrupt() and EnableInterrupt() calls in the event handler - it most likely causes the other interrupts to be ignored/missed.

 

I would recommend you to remove those Disable/EnableInterrupt() calls; and also change the interrupt trigger to InterruptEdgeHigh, so the button release event is not generated (you can add it back again later, if you need it). Also, apparently the switch bounces, so you'd need to implement either hardware or software debouncing (or both).

 

You can make the circuit a little bit simpler by switching to pull-up resistors, because you can enable the built-in ones (in the InterruptPort constructor); then you'd need to use InterruptEdgeLow instead.






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.