[AMENDED topic] Detecting an Emergency Stop on Arduino

Hi,

I have a project on which I would like to implement an emergency stop.

I'm thinking of creating an eStop variable and use the external interrupt to set its state.

so eStop = 0; //not enabled, eStop = 1 // eStop enables.

so in concepts in the loop routine it would look:

void loop{

if(eStop ==0){

//my rest of code here

}

}

However I have the following problem with this routine:

the interrupt can set "eStop" anywhere during the code execution but will only it will only be effective once the loop restarts.

Is there are way, whether implemented in the interrupt or elsewhere, that when the interrupt is triggered the loop is reset to the top ( if(eStop ==0) ) to stop all execution?

If a different approach is possible, I'm open to suggestions! :wink:

If a different approach is possible, I'm open to suggestions!

Don't do emergency stop buttons in software.

If your goal is to actually implement an "emergency stop" then you are not just barking up the wrong tree you are hunting in the wrong forest.

Your solution should not involve any software nor any decisions (like the "if" in your example) and should use the minimum possible number of parts to reach the goal.

This is a very effective emergency stop (explosive charge that stops blade rotation within milliseconds)...
https://www.google.com/search?q=saw+stop

the intent is to recognise that there was an eStop request and stop the code there and then. Since the arduino is connected to a PC, killing power to the board is not really an option.

Currently and eStop button will stop the physical process when pressed but the code keeps running.

Implementing my initial post works to detect the eStop request, but it still needs to completed the loop before detecting the eStop set

What I had in mind what something like to safely stop the code:

On intr, eStop = 1 -> safely stop code then Goto 0 (which the start of the loop)

Since the arduino is connected to a PC, killing power to the board is not really an option.

Oh yes it is if you modify the USB cable.

Hi,
An E-Stop removes power from everything, not just the output devices, but also the input devices.

An E-Stop is unconditional, you may want to hit the E-Stop because;

  • An output device , motor, valve, light has malfunctioned.
  • A process is out of sync.
  • A life is in danger, electric shock, caught in machinery, hazardous situation occurs.
  • An input device has failed.
  • Controller fails.
  • Power supply fault.

Everything has to shut down.

Tom... :slight_smile:

sherzaad:
What I had in mind what something like to safely stop the code:

Don't use code for a safety stop.

Just have a big red button that cuts off power to the dangerous part of the machine.

As an extra you could have code in the Arduino that detects when the big red button is triggered - but only AFTER the safety stop has happened.

...R

Maybe put it to sleep? Of course, this would shut down any display peripherals, possibly making it hard to diagnose the cause.

An alternative might be to call a function (often) which monitors the E-stop input. When it's activated the code just loops there, think 'while()', until the E-stop is removed.

YMMV

Lets define an emergency stop as opposed to an error condition. An "emergency" stop is when someone removes a safety cover and has their arm caught in a chain driven gear. An error condition is when the machine is filling cans with tomatoes and the cans jam and the tomatoes are spilling on the floor.

Which condition are you attempting to cover? If it is really an emergency, then the advice to stop all power immediately is the correct answer.

Paul

Robin2:
Don't use code for a safety stop.

Just have a big red button that cuts off power to the dangerous part of the machine.

As an extra you could have code in the Arduino that detects when the big red button is triggered - but only AFTER the safety stop has happened.

...R

That's EXACTLY what I want - "Arduino that detects when the big red button is triggered - but only AFTER the safety stop has happened."

I what I am trying to achive to to stop the CODE safely to avoid it returning/reading undesired values the moment the e-stop is pressed.

As I already said is my previous post what I would like to do (if possible) is:

On intr,
set eStop = 1
safely stop code
Goto 0 (which the start of the loop)

Is that achievable?

sherzaad:
Is that achievable?

Yes. Kill power to the board.

(There are exceptions to killing all power. However, given your struggle to understand I am confident you have not crossed paths with an exception.)

sherzaad:
That's EXACTLY what I want - "Arduino that detects when the big red button is triggered - but only AFTER the safety stop has happened."

I what I am trying to achive to to stop the CODE safely to avoid it returning/reading undesired values the moment the e-stop is pressed.

Obviously cutting off power to the Arduino as well as to the dangerous machine is one option.

If you want the Arduino to continue working but to be aware that the E-stop has been triggered then you need some means for the Arduino to detect that.

As you have not given us any information about what you are controlling, how the E-stop button is wired etc etc etc any advice would be guesswork and might be dangerous.

...R

I'm beginning to think that my english is not transparent enough....

@ Robin,

please allow me to re-summerise my query below.
As the PC station is away from the rig, what I am trying to achieve is to notify to the PC that eStop has been pressed that any further data received (ie until the loop restarts if a Goto 0 is really not possible) is invalid

The eStop button kills the power to my rig as should any eStop button.

the arduino board is connected, powered and communicating with a PC and therefore will not power down when the eStop is pressed (unless I do what UKHeliBob suggested which is not really my preferred option)

I would like to implement an INTERRUPT to detect the eStop condition, so that the arduino knows that an eStop has happened and that, where ever it is in "loop", whatever data it is receiving is now invalid

To avoid me adding many "if" statements checking the eStop variable in my loop surely there much be a way of implementing a "Goto 0" which the start of the loop so that I have only ONE if statement that checks the eStop to decide whether or not to run the "normal" code

so is psudo code:

on interrupt{

eStop= 1;

}

void loop{

if(eStop!=1){

//normal code

}
else{

//eStop codition
}

}

The simple, non-blocking state-machine is your friend.

sherzaad:
so is psudo code:

I think that should work.

As to your English, I think a lot of the confusion would have been avoided if your Original Post had said
I have a project on which I would like to detect an emergency stop.
rather than
I have a project on which I would like to implement an emergency stop.

...R

Robin2:
I think that should work.

As to your English, I think a lot of the confusion would have been avoided if your Original Post had said
I have a project on which I would like to detect an emergency stop.
rather than
I have a project on which I would like to implement an emergency stop.

...R

Thank you for highlighting to me the confusing point. I've amended the title.

I know that should work in principle.

Where the challenge lies is the second part to my query: Is possible to reset the loop to the start the moment the interrupt is triggered?

sherzaad:
Where the challenge lies is the second part to my query: Is possible to reset the loop to the start the moment the interrupt is triggered?

It seems to me that the pseudo code you posted will do exactly that - unless, of course, the code that is being executed at the time the interrupt is triggered takes a long time to complete before returning to loop(). Code should be designed to return to loop() very quickly even if there is no interrupt being used.

Have a look at the code in Several things at a time. Note how each function runs very briefly and returns to loop() so the next one can be called. And there may be dozens of calls to a function before it is actually time for it to do anything.

If these ideas do not solve the problem then you need to explain what is happening that needs to stop even more quickly and post the code that you are using.

...R

the closest idea that I found that I think will fit my purpose I found the software example shown here:

or this:

void software_Reset()
// Restarts program from beginning but 
{
  asm volatile ("  jmp 0");  
}

sherzaad:
the closest idea that I found that I think will fit my purpose I found the software example shown here:

IMHO that is because you are thinking of the wrong type of solution. Why would you need to restart the whole program?

And AFAIK a jmp 0 is not the same as pressing the reset button. If you really do need to restart the Arduino then get the E-stop process to trigger the Arduino reset pin using a suitable electrical circuit.

Can you respond to my comments in Reply #16?

...R

sherzaad:
I'm beginning to think that my english is not transparent enough....

Your English is fine.

What is missing is an answer to a simple question: Is the Arduino controlling anything that loses power when an emergency stop occurs?

My suspicion is that you are deliberately excluding the answer so people will help you.