How could i re-format my ISR so it could properly pause/resume the main code

Hi,

I'm making a simple controller for a welder and a caddy to automate a specific weld. All is working properly except for my start/pause function. I thought of using an interrupt to handle the pause but now i'm doomed because millis seems to not work properly and i need to de-bounce the interrupt as it pause/restart too quick. I've used a while loop to have a non bloking pause befire i sample the switch pin manually but the loop deadlock because of the use of millis from what i've read so far...

If you have another way to debounce the switch so the pause function properly i would appreciate. But i doubt that it will work because i also use millis to make a pause time calculation after the while pause...

If there is no workaround and i need to compltely re-think the way i will pause the weld let me know.

Thanks

autoweld.ino (9.19 KB)

An ISR is the wrong way to handle a pause. Why not simply read the pin in loop() and react to it when it becomes pressed or released ?

  while (millis() - timers < startDelays) {} //Empty loop used as a non blocking delays

Despite what the comment says, this is a blocking delay

UKHeliBob:
An ISR is the wrong way to handle a pause. Why not simply read the pin in loop() and react to it when it becomes pressed or released ?

  while (millis() - timers < startDelays) {} //Empty loop used as a non blocking delays

Despite what the comment says, this is a blocking delay

Maybe my perception of it was wrong then. From what i know of it in between every check of the condition for the while loop the chip can process interrupt normally? That was the point to use this way of doing it. Explain to me where i'm wrong it will be appreciated. thx

Your while loop will allow an interrupt to be serviced but apart from that it it blocking code, However, if the ISR includes any code that relies on interrupts, such as millis() or Serial.print(), then it will not work as you intend.

In general it is best to keep loop() repeating as quickly as possible and to read pins and test for a timing period to end etc without blocking its free running

UKHeliBob:
Your while loop will allow an interrupt to be serviced but apart from that it it blocking code, However, if the ISR includes any code that relies on interrupts, such as millis() or Serial.print(), then it will not work as you intend.

In general it is best to keep loop() repeating as quickly as possible and to read pins and test for a timing period to end etc without blocking its free running

Ok see my code design was bad from the start as i was missing some crucial information about inner interrupt working. Error made, lesson learned.

Now my question is, can i salvage this code? I'm thinking about re-enabling all interrupt from within the ISR and disabling only the intterupt of the specified pin for the duration of the interrupt. That way i can trig my pause whenever needed, and enable the use of millis() from within my ISR while negating potential problem of recalling the isr from within it. Only need to find how to do it to test if it works.

Next time i'll design the code so the ISR only change flag vars.

Seems like a good candidate for a state machine approach. I wouldn't use an interrupt for a switch input either TBH.

In about 80% of typical Arduino sketches, user-defined interrupts are unnecessary, or even counterproductive.
Once you understand polling methods and ‘non-blocking code’ this will become more obvious.

Blackfin:
Seems like a good candidate for a state machine approach. I wouldn't use an interrupt for a switch input either TBH.

I've tried numerous things to save the code but i think i'm better to start from scratch, i made too many mistake. I've read about state machine for the last 4 hours and yes i think it's the way to go. Never tried such a thing so far so it will be a good opportunity to learn a new approch to code. Thanks for the suggestion!