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

Interrupt Port Ghosts


  • Please log in to reply
10 replies to this topic

#1 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 09 December 2015 - 06:03 PM

Hello all,

 

I am working on a project with my Netduino Plus 2. I am encountering a strange problem.

 

In a nutshell, the device I'm designing is running tests on a circuit board to check for functionality. I am using the Netduino to send signals to this board. I have 6 push-buttons that trigger interrupts which send certain signals to the board being tested. If the correct level is detected at this board's output pin, a corresponding LED is turned on. If an incorrect level is detected, the LED is flashed. The interrupt ports are interruptedgehigh with accompanying pull down resistors. The N+2 is being powered by 8 volts coming from a power supply circuit which itself is powered with your basic 120VAC. 

 

The board I am testing requires 120VAC to be sent through 4 paths one at a time. This tests functionality of the components located on that particular path. So I have 4 line/neutral pairs sent to the board. But since the paths must be run one at a time, I have each line switched. This way, when I want to run the AC line tests, I flip line switch 1, press the test's push-button to trigger the interrupt which runs the test, and then check the test results via the LED. 

 

Now here is where my problem arises. My test seems to function correctly, but when I switch on the AC during any of the four AC line tests, either that test's LED flashes or another AC line test's LED flashes. So to be specific, let's say I flip the switch to send AC through Line Test 1. No lights should turn on or flash until I press the push-button to trigger the interrupt. However, any of the four Line Test LED's flash. It's as if the interrupts are being triggered without the push-button being pressed. 
 
I have included my entire program code below. I know this is long winded but I am just stumped as to a hardware cause and want to check all bases software wise before wracking my brain any further. Thanks so much for any and all help!
 
using System;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace TLS_350_Pump_Sense_Module_Test_Program
{
    
    public class Program
    {
        private static InterruptPort LT1Switch = new InterruptPort(Pins.GPIO_PIN_D6, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static InterruptPort LT2Switch = new InterruptPort(Pins.GPIO_PIN_D7, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static InterruptPort LT3Switch = new InterruptPort(Pins.GPIO_PIN_D2, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static InterruptPort LT4Switch = new InterruptPort(Pins.GPIO_PIN_D3, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static InterruptPort TransTestSwitch = new InterruptPort(Pins.GPIO_PIN_D5, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static InterruptPort U1TestSwitch = new InterruptPort(Pins.GPIO_PIN_D4, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        private static OutputPort J1pin3 = new OutputPort(Pins.GPIO_PIN_D0, false);
        private static InputPort J1pin4 = new InputPort(Pins.GPIO_PIN_D13, true, Port.ResistorMode.Disabled);
        private static OutputPort J1pin5 = new OutputPort(Pins.GPIO_PIN_D9, false);
        private static OutputPort J1pin7 = new OutputPort(Pins.GPIO_PIN_D10, false);
        private static OutputPort J1pin9 = new OutputPort(Pins.GPIO_PIN_D11, false);
        private static OutputPort J1pin10 = new OutputPort(Pins.GPIO_PIN_D12, true);
        private static OutputPort LT1LED = new OutputPort(Pins.GPIO_PIN_D8, false);
        private static OutputPort LT2LED = new OutputPort(Pins.GPIO_PIN_A1, false);
        private static OutputPort LT3LED = new OutputPort(Pins.GPIO_PIN_A2, false);
        private static OutputPort LT4LED = new OutputPort(Pins.GPIO_PIN_A3, false);
        private static OutputPort TTLED = new OutputPort(Pins.GPIO_PIN_A4, false);
        private static OutputPort U1TLED = new OutputPort(Pins.GPIO_PIN_A5, false);
        private static DateTime lastEvent = DateTime.Now;

        public static double ReadRaw()
        {
            AnalogInput TransistorTest = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); 
            const double maxVoltage = 3.3;
            const int maxADCValue = 4095;
            double rawValue = TransistorTest.ReadRaw();
            TransistorTest.Dispose();
            double voltagevalue = (rawValue * maxVoltage) / maxADCValue;
            double realworldvalue=(((voltagevalue - 0.5) * 1000) / 10) - 4;
            return voltagevalue;
         }
        
             
        public static void Main()
        {
            TransTestSwitch.OnInterrupt += new NativeEventHandler(TransTestSwitch_OnInterrupt);
            LT1Switch.OnInterrupt += new NativeEventHandler(LT1Switch_OnInterrupt);
            LT2Switch.OnInterrupt += new NativeEventHandler(LT2Switch_OnInterrupt);
            LT3Switch.OnInterrupt += new NativeEventHandler(LT3Switch_OnInterrupt);
            LT4Switch.OnInterrupt += new NativeEventHandler(LT4Switch_OnInterrupt);
            U1TestSwitch.OnInterrupt += new NativeEventHandler(U1TestSwitch_OnInterrupt);

            Debug.Print(ReadRaw().ToString("f"));
            Thread.Sleep(300); 

            Thread.Sleep(Timeout.Infinite);
        }



        static void U1TestSwitch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(false);
            J1pin5.Write(true);
            J1pin7.Write(false);
            J1pin4.Read();
            U1TestSwitch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
            {
                lastEvent = time.AddMilliseconds(500);

                if (J1pin4.Read() == true)
                {
                    U1TLED.Write(true);
                }

                else
                {
                    int U1number = 7;
                    for (int i = 0; i < U1number; i++)
                    {
                        U1TLED.Write(true);
                        Thread.Sleep(200);
                        U1TLED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }


        static void TransTestSwitch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(true);
            J1pin5.Write(true);
            J1pin7.Write(true);
            J1pin9.Write(true);
            ReadRaw();
            TransTestSwitch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
            {
                lastEvent = time.AddMilliseconds(500);

                if (ReadRaw() > 2.4 && ReadRaw() <= 2.7)
                {
                    TTLED.Write(true);
                    Debug.Print(ReadRaw().ToString("f"));
                    Thread.Sleep(300);
                }

                else
                {
                    int Tnumber = 7;
                    for (int i = 0; i < Tnumber; i++)
                    {
                        TTLED.Write(true);
                        Thread.Sleep(200);
                        TTLED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }

        static void LT1Switch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(false);
            J1pin5.Write(false);
            J1pin7.Write(false);
            J1pin4.Read();
            LT1Switch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
            {
                lastEvent = time.AddMilliseconds(500);

                if (J1pin4.Read() == false)
                {
                    LT1LED.Write(true);
                }

                else
                {
                    int L1number = 7;
                    for (int i = 0; i < L1number; i++)
                    {
                        LT1LED.Write(true);
                        Thread.Sleep(200);
                        LT1LED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }

        static void LT2Switch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(true);
            J1pin5.Write(false);
            J1pin7.Write(false);
            J1pin4.Read();
            LT2Switch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
            {
                lastEvent = time.AddMilliseconds(500);

                if (J1pin4.Read() == false)
                {
                    LT2LED.Write(true);
                }

                else
                {
                    int L2number = 7;
                    for (int i = 0; i < L2number; i++)
                    {
                        LT2LED.Write(true);
                        Thread.Sleep(200);
                        LT2LED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }

        static void LT3Switch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(false);
            J1pin5.Write(true);
            J1pin7.Write(false);
            J1pin4.Read();
            LT3Switch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
           {
                lastEvent = time.AddMilliseconds(500);

                if (J1pin4.Read() == false)
                {
                    LT3LED.Write(true);
                }

                else
                {
                    int L3number = 7;
                    for (int i = 0; i < L3number; i++)
                    {
                        LT3LED.Write(true);
                        Thread.Sleep(200);
                        LT3LED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }

        static void LT4Switch_OnInterrupt(uint data1, uint data2, DateTime time)
        {
            J1pin3.Write(true);
            J1pin5.Write(true);
            J1pin7.Write(false);
            J1pin4.Read();
            LT4Switch.ClearInterrupt();

            if (time.AddMilliseconds(-500) > lastEvent)
            {
                lastEvent = time.AddMilliseconds(500);

                if (J1pin4.Read() == false)
                {
                    LT4LED.Write(true);
                }

                else
                {
                    int L4number = 7;
                    for (int i = 0; i < L4number; i++)
                    {
                        LT4LED.Write(true);
                        Thread.Sleep(200);
                        LT4LED.Write(false);
                        Thread.Sleep(200);
                    }
                }
            }
        }
    }

}




#2 HSven1611

HSven1611

    Member

  • Members
  • PipPip
  • 14 posts

Posted 10 December 2015 - 03:14 PM

This might be an electrical problem. Can you upload a circuit diagram?

 

Regards

 

Sven



#3 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 December 2015 - 03:59 PM

I seem to be unable to upload any files. Any time I select my file to upload, it loads for a second and then says that "no file was selected for upload". Is this a common problem on the forum?



#4 Architect

Architect

    New Member

  • Members
  • Pip
  • 7 posts

Posted 10 December 2015 - 06:46 PM

Some sort of self-induction happening. The circuit diagram and/or photos of your setup might help.



#5 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 December 2015 - 07:01 PM

Every time I try to upload the diagram, I get an error saying that "no file was selected for upload." Is this a common problem on the forums?



#6 Architect

Architect

    New Member

  • Members
  • Pip
  • 7 posts

Posted 10 December 2015 - 08:32 PM

Just come on over to the GHI forum. Much more activity over there and you will be able to post pictures directly. Just use .NET Micro Framework board on the forum, since this is about Netduino and not GHI products.



#7 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 12 December 2015 - 09:59 AM

Hi WriterGuy,

 

Just quickly scanned you code (haven't had a chance to build & try on a device yet) and was wondering if you could try flashing the LEDs with a TImer(s) rather than a couple of Thread.Sleep ?

 

I always try to keep interrupt handlers really short and snappy and your could take nearly 3 secs?

 

 

@KiwiBryn

blog.devmobile.co.nz



#8 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 14 December 2015 - 07:17 PM

KiwiDev,

 

Thanks for the reply. I actually just went the Thread.Sleep route because I wasn't having luck with the timers. Would setting up a timer for each of my 6 interrupts be relatively easy or would it be adding a lot of extra code?



#9 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 17 December 2015 - 04:36 PM

I was able to fix the problem by adding .1uF capacitors between the interrupt port pins used and ground. This seemed to stabilize the circuit and there are no random flashing lights at all! Thanks to all that helped out!



#10 WriterGuy

WriterGuy

    Member

  • Members
  • PipPip
  • 10 posts

Posted 18 December 2015 - 03:39 PM

Unfortunately, I had to unsolve my problem. Replacing all the components back into my case seems to have brought my phantom flashing LEDs back from the grave. The capacitors are in place and making good connection, its just something about having everything together inside the case is triggering the issue anyway. 



#11 KiwiDev

KiwiDev

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationNew Zealand

Posted 29 December 2015 - 04:46 AM

Hi WriterGuy,

 

I wrote some sample code and built a test rig with some SeeedStudio kit I have.

 

PM me and I'll email to you directly.

 

The forums blew up when I replied to your post with the code.

 

@KiwiBryn

blog.devmobile.co.nz






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.