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.
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); } } } } } }