All, I found that using Uno as a input to the PID was not feasible since the fuel valve changes need to be in Run.
Tab #14 Run
/* Start Container/Mode - The requirements are as follows:
* 1.The emergency stop status is checked.
* 2. Oil presure is read and confirmed to be within acceptable limits. Green LED is lighted if okay.
* 3. Oil temperaure and Exhaust Gas Temperature (EGT)are read and are required to below allowable start temperatures.
* Orange LED is lighted if egt is greater than 1250 degrees F
*
* The steps required are as follows:
*
* A. FADEC control passes to Run from Accel when it is called from Loop
* B. A RunStart timer is created and entered
* C. Emergency stop is checked
* D. Functions to check oil pressure, oil temperature and exhaust gas temperatue are called.
* E. The oil pressure and egt status are reported via LEDs
* F. A while loop based on Compressure Discharge Pressure(CDP) is created
* G. The Fuel Metering Valve(FMV) is modulated to maintain a constant CDP of 45 psig.
* H. The operator then iniates Run by push button action
* I. CDP is used instead of gasifier speed/rpm in this version of the control. It is planned to add gasifer speed/rpm in future versions of the control.
* J. Power turbine RPM is checked to see if rotation has or is occurring.
* K. When Run has been completed for the current sitution the PID controller is exited by push button action. After the PID controller is
* exited the control delays for 30 secs and then exits Run and Loop calls Decel.
*
* TO DO LIST
* 1. Add gasifier and power turbine speeds/rpms
*
*/
/* Test matrix
* cdpsi is initialize at 10 and varied in the while function that sets idle duration
*
* cdpsi test value Resulted Action
* 41 cdpok = not okay (false), Fuel shutoff valve closes (false)
* 42 cdpok = not okay (false), Fuel shutoff valve closes (false)
* 43 Raises fuel valve setting to 135
* 44 Raises fuel valve setting to 135, passes max and min pressure limits
* 45 Unit cdp stays at 45 for prescribed time period without a fuel valve position change.
* 46 Lowers fuel valve setting to 125
* 47 Lowers fuel valve setting to 125
* 48 Announce cdpok false, shut fuel gas valve and call Decel during testing
*
* probably best to shut the fuel valve if cdpsi is out of bounds
*/
void Run () //Run function defination
{
Serial.println("In Run:");
delay(500);
// Run Container Variables for reference - created in Global
//bool RunStartBIT = false;
//bool RunInitializeBIT = true;
//bool RunInProcessBIT = false;
//bool RunCompleteBIT = false;
//bool RunFaultBIT = false;
bool cdpok = false;
bool PID_pinstate = false; //if push button pressed the first time PID_pinstate changes to Auto
//(true)
//when push button is pressed the second time control returns to
//Manual(false)
long RunFaultTMR = 0; //Initialize RunTMR
long RunStartTMR = 0; //Initialize RunStart TMR
unsigned long StartRunTimer = millis();
estop = digitalRead(estopsig_pin); // Read emergency stop valve - it must be true to continue
int fuelpwmout_val = 130; //Initalize fuelpwmout_val ; fuelpwmout_pin 44
int gasfuelshutoff_val = true;
int cdpsi = 45; //TR - Initalize cdpsi
int cdpupperbound = 46; // TR - added 01/05/2020
int cdplowerbound = 44; // TR - added 01/05/2020
int cdpmaxpressure = 47; // TR - added 01/05/2020
int cdpminpressure = 43; // TR - added 01/05/2020
/*initialize PID working variables for reference. They must be initized in pid function
unsigned long lastTime = 0;
double Input = 160, Output = 0, Setpoint = 200;
double errSum = 0, lastErr = millis()-1000;
double kp = 1, ki = .0001, kd = .01;
*/
if(estop == false)
{
}
else
{
estop = true; // Dummy for code check
}
oilokay = digitalRead(oilokay_pin); // check oil pressure status
oilokay = true; // Dummy for code check
RunStartBIT = true; // Not required to accomplish requirements
RunInitializeBIT == true; // Not required to accomplish requirements
RunCompleteBIT = false; // Initialize bool
RunFaultBIT = false; // Initialize bool
while(RunFaultTMR != 3)
{
if(RunStartBIT == true && RunInitializeBIT == true && RunCompleteBIT == false
&& RunFaultBIT == false && estop == true && oilokay == true)
{
RunInProcessBIT = true;
Serial.println("RunInProcessBIT =");
Serial.println(RunInProcessBIT);
}
//In plain english, this line of code says that if the action is not
//currently in process, there is no fault, the container is not
//initialized and someone has pressed the start button, then the
//action is executed and the watchdog timer has begun counting time.
RunFaultTMR++;
Serial.println("RunFaultTMR =");
Serial.println(RunFaultTMR);
delay(1000);
if (RunInProcessBIT == true ) //Deleted && RunFaultTMR != 5500
{
RunCompleteBIT = true;
}
else
if (RunInitializeBIT == true)
{
RunCompleteBIT = true;
}
//If the action is in process, the watchdog timer has not timed
//out, then the container is considered
//complete. Additionally, if the user initializes the whole machine,
//this container settles in a complete state, which means all moving
//parts will return to their home position.
if(RunInProcessBIT == true && RunFaultTMR == 5500)
{
RunFaultBIT ==true;
}
estop = digitalRead(estopsig_pin); // Read emergency stop valve - it must be true to continue
oilokay = digitalRead(oilokay_pin); // check oil pressure status
estop = true; // Dummy for code check
oilokay = true; // Dummy for code check
while((estop == true) && (oilokay == true)) // Begin while
{
estop = digitalRead(estopsig_pin);
oilokay = digitalRead(oilokay_pin);
}
state = 5; //RUN
Serial.println("Run State = 5");
delay (1000);
/**********************************MANUAL CONTORL *************************************************
* ************************************************************************************************
*/
while(millis() - StartRunTimer <= 22500) //Begin StartRunTimer WHILE - 60000 milliseconds is equal to a minute
//idle.
{
temperatureegt = 1200; // TR - input egt so software can be checked
Serial.println("EGT = ");
Serial.println(temperatureegt);
delay(1000);
cdpsi = Serial3.read();
cdpsi = 45; // TR - assign cdpsi a value so software can be checked
Serial.println("CDP = ");
Serial.println(cdpsi);
delay(1000);
Serial.println("StartRunTimer = ");
Serial.println(StartRunTimer);
delay(1000);
Serial.println("millis() = ");
Serial.println(millis());
delay(1000);
if((cdpsi > cdpmaxpressure)||(cdpsi < cdpminpressure))
{
cdpok = false; // Compressor discharge pressure (CDP) is outside for the 44 and 46 psi target range.
Serial.println("cdpok = ");
Serial.println(cdpok);
digitalWrite(gasfuelshutoff_val, false);
Serial.println("Gas Fuel Shutoff Valve = ");
Serial.println(gasfuelshutoff_val = 0); //set equal to zero so that the code can be checked
delay(1000);
/* following three statements to be commented out during actual operation */
Serial.println("Exit Run:");
delay(1000);
Decel();
}
else
{
cdpok = true; // Compressor discharge pressure (CDP) is with the acceptable range of 44 to 46 psi.
Serial.println("cdpok = ");
Serial.println(cdpok);
}
if(cdpsi >= cdpupperbound )
{
analogWrite(fuelpwmout_pin, 125);
fuelpwmout_val = 125;
delay(1000);
Serial.println("CDP = ");
Serial.println(cdpsi);
Serial.println("Fuel Valve Position = ");
Serial.println(fuelpwmout_val);
// End 1st cdpsi check after ignition
cdpsi = Serial3.read();
cdpsi = 45; // TR - assign cdpsi a value so software can be checked
Serial.println("CDP = ");
Serial.println(cdpsi);
delay (1000);
}
else
{
cdpok = true; // Compressor discharge pressure (CDP) is within the acceptable range of 44 to 46 psi.
Serial.println("cdpok = ");
Serial.println(cdpok);
}
if( cdpsi <= cdplowerbound)
{
analogWrite(fuelpwmout_pin, 135);
fuelpwmout_val = 135;
delay(1000);
Serial.println("CDP = ");
Serial.println(cdpsi);
Serial.println("Fuel Valve Position = ");
Serial.println(fuelpwmout_val);
cdpsi = Serial3.read();
cdpsi = 45; // TR - assign cdpsi a value so software can be checked
Serial.println("CDP = ");
Serial.println(cdpsi);
delay (1000);
}
else
{
cdpok = true; // Compressor discharge pressure (CDP) is with the acceptable range of 44 to 46 psi.
Serial.println("cdpok = ");
Serial.println(cdpok);
}
// WHILE termination phase
} // WHILE ends
/*********************************AUTO CONTROL ***************************************************
*
*/
//PID push button pressed = Auto(true); button not pressed = Manual(false);
while(!digitalRead(PID_pinstate) && millis() - StartRunTimer <= 6000 );
{ //Start push button WHILE
//int inPin = 2; the number of the pushbutton input pin
//int outPin = 32; the number of the pushbutton output pin
//int state = true; the current state of the output pin - added to tabs d - changed to PID_pinstate
//int reading; the current reading from the input pin- added to tabs d
//int previous = true; the previous reading from the input pin- added to tabs d
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
//void loop() function Run is called in loop
//{//} function Run is called in loop
reading = digitalRead(inPin);
reading = true; //to test code
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == true && previous == false && millis() - time > debounce) //&& millis() - time > debounce
{
if (PID_pinstate == true)
{
PID_pinstate = false;
Serial.println("PID_pinstate = ");
Serial.println(PID_pinstate = 0);
delay (1000);
}
else
{
PID_pinstate = true;
Serial.println("PID_pinstate = ");
Serial.println(PID_pinstate = 1);
delay (1000);
time = millis();
}
}
digitalWrite(outPin, PID_pinstate);
previous = reading;
//} function Run is called in loop
} // push button WHILE
//end StartRunTimer WHILE
Serial.println("Setpoint = 200"); // to test code
Serial.println(Setpoint);
delay(1000);
Serial.println("Input = 160"); // to test code
Serial.println(Input);
delay(1000);
//for(;
//infinite loop to be exited by push button
//{
double delta_output;
Input = analogRead(A6);
Input = 160; //to test code
Output = pid(Input);
delta_output = Output + Input;
analogWrite(A7,delta_output);
Serial.println("delta_output = "); // to test code
Serial.println(delta_output);
delay(3000);
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
reading = digitalRead(inPin);
reading = false; //to test code
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == true && previous == false && millis() - time > debounce) //&& millis() - time > debounce
{
if (PID_pinstate == true)
{
PID_pinstate = false;
Serial.println("PID_pinstate = ");
Serial.println(PID_pinstate = 0);
delay (1000);
}
else
{
PID_pinstate = true;
Serial.println("PID_pinstate = ");
Serial.println(PID_pinstate = 1);
delay (1000);
time = millis();
}
}
digitalWrite(outPin, PID_pinstate);
previous = reading;
//} function Run is called in loop
//} // push button WHILE
Serial.println("Exit Run:");
delay(1000);
Decel();
//}
} //End while StartFaultTimer
//The following sets up a fault BIT monitor in your serial window.
//Serial.println ("RunFaultBIT: ");
//Serial.println( RunFaultBIT);
//Serial.println ("Box Fill Fault BIT: "); Serial.println( boxFillFaultBIT);
//Serial.println ("Conveyor 2 Fault BIT: "); Serial.println( conveyor2FaultBIT);
//Serial.println ("Tape Station Fault BIT: "); Serial.println( tapeStationFaultBIT);
//Serial.println ("Conveyor 3 Fault BIT: "); Serial.println( conveyor3FaultBIT);
//Serial.println ("End_of_Line Pusher Fault BIT: "); Serial.println( eolPusherFaultBIT)
while(RunStartTMR != 3)
{
digitalWrite(startengsol_pin, true); // Turn on starter solenoid
Serial.println("In Run Start:");
RunStartTMR++;
Serial.println("RunStartTMR =");
Serial.println(RunStartTMR);
delay(1000);
}
delay(1000);
digitalWrite(startengsol_pin, false); // Turn off starter solenoid
Serial.println("Exit Run Start:");
delay(1000);
//The following sets up a fault BIT monitor in your serial window.
oilokay = true;
hot = true;
if(oilokay == true && hot == true)
{
Decel();
}
else
{
Serial.println ("ReadyFaultBIT: ");
Serial.println( ReadyFaultBIT);
digitalWrite(FADECred_pin, true); //If ReadyFaultTMR expires before the action is completed the red fault led is lighted.
FADECredLED_val = FADECred_pin;
Serial.println("Fault!");
Serial.println(FADECredLED_val);
}
Serial.println("Exit Run:");
delay(1000);
} //end of Run function