Hello all!
I'm having a (seemingly peculiar) error when deploying some code to my Netduino Mini. I just received the Mini, dumped a simple Blink program on it to verify it works, and then tried to dump the following code onto the Mini.
The error I am getting is "An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll" Occuring on Line:33
I have tried changing the Input pin, but same issue. Currently running .NETMF 4.1 as my current program framework. Any ideas?
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoMini; //R0.0 - Base Project (Nevin Steinbrink 7/25/2014) //R0.1 - Added PWM motor control functionality (Nevin Steinbrink 8/2/2014) //R0.2 - Added third Program Select input, changed Status Pointer configuration (Nevin Steinbrink 9/21/2014) namespace NetduinoMiniApplication1 { public class ICE_Box { public static int StatusPointer; //Used for Status LED flash pattern public static void Main() { Thread a = new Thread(Status); //Thread for Status LED control a.Start(); Thread b = new Thread(BlowerControl); //Thread for Blower Motor control b.Start(); while (true) { Thread.Sleep(Timeout.Infinite); } } static void BlowerControl() { InputPort StartButton = new InputPort(Pins.GPIO_PIN_13, true, Port.ResistorMode.PullDown); //Start button input InputPort PS_1 = new InputPort(Pins.GPIO_PIN_6, true, Port.ResistorMode.PullDown); //Program select 1 input, 1 Liter InputPort PS_2 = new InputPort(Pins.GPIO_PIN_7, true, Port.ResistorMode.PullDown); //Program select 2 input, 3 Liter InputPort PS_3 = new InputPort(Pins.GPIO_PIN_8, true, Port.ResistorMode.PullDown); //Program select 3 input, 5 Liter PWM BlowerOutput = new PWM(Pins.GPIO_PIN_17); //PWM output for blower relay bool PS_1State = false; //Program select 1, initialize as LOW bool PS_2State = false; //Program select 2, initialize as LOW bool PS_3State = false; //Program select 3, initialize as LOW bool StartButtonState = false; //Start button, initialize as LOW bool StartLatch = false; bool BlowerRunning = false; int RunTime = 0; //Blower ON time in ms int PWMDutyCycle = 0; //In percent, initialize at 0% uint PWMFreq = 400; //In Hz <-- Adjust this value uint PWMPeriod; uint PWMPulseWidth; //In microseconds PWMPeriod = ((1 / PWMFreq) / 1000000); //In microseconds while (true) { StatusPointer = 1; //Ready LED indication PS_1State = PS_1.Read(); //Read state of Program Select switch PS_2State = PS_2.Read(); //Read state of Program Select switch StartButtonState = StartButton.Read(); //Read state of Start button if (StartButtonState == true) //Check if Start button is pressed { StartLatch = true; //Start button debounce } if (PS_1State == true) //Check which program is selected, Program 1 selected { RunTime = 5000; //Blower ON for 5 seconds PWMDutyCycle = 50; //Blower at 50% power } if (PS_2State == true) //Check which program is selected, Program 2 selected { RunTime = 8000; //Blower ON for 8 seconds PWMDutyCycle = 90; //Blower at 90% power } if (PS_3State == true) //Check which program is selected, Program 3 selected { RunTime = 10000; //Blower ON for 10 seconds PWMDutyCycle = 90; //Blower at 90% power } while (StartLatch == true & BlowerRunning == false) //Check if OK to start and blower is currently OFF { PWMPulseWidth = (uint)(PWMPeriod * (PWMDutyCycle / 100)); BlowerRunning = true; //Prevents re-entering while loop StatusPointer = 2; //Changes LED indication to 'in operation' BlowerOutput.SetPulse(PWMPeriod, PWMPulseWidth); //Turn on Blower at set PWM Thread.Sleep(RunTime); //For this long StartLatch = false; //Reset StartLatch BlowerRunning = false; //Reset BlowerRunning StatusPointer = 3; //Changes LED indication to 'completed' } } } static void Status() { OutputPort StatusLED = new OutputPort(Pins.GPIO_PIN_9, true); while (true) { if (StatusPointer == 1) //LED indication 'Ready' { StatusLED.Write(false); Thread.Sleep(1000); StatusLED.Write(true); Thread.Sleep(1000); } if (StatusPointer == 2) //LED indication 'In Operation' { StatusLED.Write(false); Thread.Sleep(800); StatusLED.Write(true); Thread.Sleep(800); } if (StatusPointer == 3) //LED indication 'Completed' { StatusLED.Write(false); Thread.Sleep(200); StatusLED.Write(true); Thread.Sleep(200); StatusLED.Write(false); Thread.Sleep(200); StatusLED.Write(true); Thread.Sleep(1000); } if (StatusPointer == 4) //LED indication 'Error' { StatusLED.Write(false); Thread.Sleep(200); StatusLED.Write(true); Thread.Sleep(200); StatusLED.Write(false); Thread.Sleep(200); StatusLED.Write(true); Thread.Sleep(200); } } } } }
Thanks for the help in advance!
-Nevin