Interrupt LOW not looping

Hi all,

Im trying to make a emergencystop with a latching button NC with pull down configuration. If the NC is triggered the 5V control voltage is no more and the pulldown makes sure the pin is pulled down to 0V.

I expect the interrupt to loop because the trigger is still LOW but the for loop is completed instead of interrupted till the NC is no longer triggered.

Why doesn't the ISR loop?

/* Function:    
 * Version:     
 * Date(Y/M/D): 
 * Author:      Quinten Spiering
 * Company:     HHS
 */

//libs

//defines/constants
#define SERIALSPEED 115200
#define DEBUG 0
#if DEBUG
#else
#endif
//Variables


//functions
const byte ledPin = 13;
const byte interruptPin = 2;
const byte Setrvo = 8;
volatile bool Nood = false;
//setup
void setup() {
  Serial.begin(SERIALSPEED);
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, LOW);
}

void loop() {
  digitalWrite(ledPin, LOW);

  // do {
  Nood = false;
  if (!Nood) {
    for (int x = 0; x <= 254; x++) {
      Nood = false;
      Serial.print(x);
      Serial.print("\t");
      Serial.println(Nood);
      delay(10);
      analogWrite(Setrvo, 127);
    }
  }
}

void blink() {
  Nood = true;
}
242 0
243 0
244 0
245 0
246 0
247 0
248 0
249 1
250 1
251 1
252 1
253 1
254 1

You don't give much opportunity for Nood to be set true… you only need to reset Nood to false after the ISR hss set it true, and you have handled that fact in you main loop code.

a7

You don't need an interrupt. Just do this:

/* Function:    
 * Version:     
 * Date(Y/M/D): 
 * Author:      Quinten Spiering
 * Company:     HHS
 */

//libs

//defines/constants
#define SERIALSPEED 115200
#define DEBUG 0
#if DEBUG
#else
#endif
//Variables


//functions
const byte ledPin = 13;
const byte interruptPin = 2;
const byte Setrvo = 8;
//setup
void setup() {
  Serial.begin(SERIALSPEED);
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT);
}

void loop() {
  digitalWrite(ledPin, LOW);

  for (int x = 0; x <= 254; x++) {
    if (digitalRead(interruptPin) == LOW) break;
    Serial.println(x);
    delay(10);
    analogWrite(Setrvo, 127);
  }
}

The problem is that I expect the trigger for the interrupt to be set again directly after the ISR is completed making a loop of ISR. Cause state LOW is kept. I expect the for loop too block and resumed when the E-stop is deactivated.

An emergency stop should not involve software.


The calling of the next adress is indeed the thing I did not account for. The goal of the E-stop in this manner is blocking the Arduino process mid everything, you know like interrupting it. The motors are all connected with the power cut-off NC line. And it is for educational purposes only.

The fun thing is when I put a serial.print in the ISR it kinda works as expected. But this is bad habit. So i guess I will have to make safety flags a thing now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.