Update to the code. Pretty minor, I just changed the initial state of the input pin. It was too prone to floating and was picking up crosstalk from the wire next to it, enough that the two wires going to the E-Stop was transferring enough signal that it would still trigger the detector with the switch off. 'Doh! Anyway, pulling it up with the internal 20K pullup resistor was sufficient.
Code:
//*Frequency*counter*sketch,*for*measuring*frequencies*low*enough*to*execute*an*interrupt*for*each*cycle
//*Connect*the*frequency*source*to*the*INT0*pin*(digital*pin*2*on*an*Arduino*Uno)
volatile*unsigned long firstPulseTime;
volatile*unsigned long lastPulseTime;
volatile*unsigned long numPulses;
int ledPin = 13;
int relay1Pin = 3;
int relay2Pin = 4;
int relay3Pin = 5;
int relay4Pin = 6;
void isr()
{
**unsigned long now = micros();
**if (numPulses == 1)
**{
****firstPulseTime*=*now;
**}
**else
**{
****lastPulseTime*=*now;
**}
**++numPulses;
}
void setup()
{
Serial.begin(19200); // this is here so that we can print the result
digitalWrite (relay1Pin, HIGH);
digitalWrite (relay2Pin, HIGH);
digitalWrite (relay3Pin, HIGH);
digitalWrite (relay4Pin, HIGH);
pinMode(2,INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
pinMode(relay4Pin, OUTPUT);
**digitalWrite (ledPin, HIGH);
**Serial.println("Delaying 60 Seconds to allow PC Boot");
**delay (10000);
****digitalWrite (ledPin, LOW);
**Serial.println("50 Seconds Remaining");
**delay (10000);
****digitalWrite (ledPin, HIGH);
**Serial.println("40 Seconds Remaining");
**delay (10000);
****digitalWrite (ledPin, LOW);
**Serial.println("30 Seconds Remaining");
**delay (10000);
****digitalWrite (ledPin, HIGH);
**Serial.println("20 Seconds Remaining");
**delay (10000);
**digitalWrite (ledPin, LOW);
**Serial.println("10 Seconds Remaining");
**delay (10000);
****digitalWrite (ledPin, HIGH);
**Serial.println("Charge Pump Started");
}
//*Measure*the*frequency*over*the*specified*sample*time*in*milliseconds,*returning*the*frequency*in*Hz
float readFrequency(unsigned int sampleTime)
{*numPulses*=*0;**********************// prime the system to start a new reading
**attachInterrupt(0, isr, RISING); // enable the interrupt
**delay(sampleTime);
**detachInterrupt(0);
**return (numPulses < 3) ? 0 : (1000000.0 * (float)(numPulses - 2))/(float)(lastPulseTime - firstPulseTime);
}
void loop()
{
**
**float freq = readFrequency(100);
****if ( freq > 2000)
{
**digitalWrite (ledPin, HIGH);
**digitalWrite (relay1Pin, LOW);
**digitalWrite (relay2Pin, LOW);
**digitalWrite (relay3Pin, LOW);
**digitalWrite (relay4Pin, LOW);
**
**Serial.print("ChargePump Active. Current Frequency: ");
**Serial.println(freq);
}
else
{
**digitalWrite (ledPin, LOW);
**digitalWrite (relay1Pin, HIGH);
**digitalWrite (relay2Pin, HIGH);
**digitalWrite (relay3Pin, HIGH);
**digitalWrite (relay4Pin, HIGH);
**Serial.print("ChargePump Inactive. Current Frequency: ");
**Serial.println(freq);
}
**delay(100);
}