How to "delay" a interruption without using delay

Hey Guys!

I'm writing a code that needs to call an interruption everytime a peak voltage is detected in my circuit.

This interruption needs to be executed after a certain time(milliseconds) that I can specify as soon as it's called.

However, I cannot find for a solution to this. Could anyone give me a hint?

And another point: once the voltage supply for my circuit is 0V I cannot allow the arduino to keep sending

the signal. How could I do that?

Thanks

This interruption needs to be executed after a certain time(milliseconds) that I can specify as soon as it's called.

Have the ISR set a flag to indicate that the interrupt has occurred. Test the flag in loop() and take action after the required period has elapsed

@OP

You can create time delay just after entering into the ISR (Interrupt Sub Routine) by putting TC1 (of Atmega328P of Arduino UNO) as a time delay counter where the 'end-of-delay' mark would be sensed by polling the TOV1 (TC1 Overflow Flag) flag of TIFR1 Register.

GolamMostafa:
You can create time delay just after entering into the ISR (Interrupt Sub Routine) by putting TC1 (of Atmega328P of Arduino UNO) as a time delay counter where the 'end-of-delay' mark would be sensed by polling the TOV1 (TC1 Overflow Flag) flag of TIFR1 Register.

That complexity hardly seems necessary as the OP only seems concerned with an interval of some number of milliseconds.

He could use micros() rather than millis() with the solution that @UKHeliBob suggested if he needs more precise timing.

...R

Robin2:
That complexity hardly seems necessary as the OP only seems concerned with an interval of some number of milliseconds.

I have offered an alternative; moreover, the OP has categorically stated that he wants to avoid the use of the delay() function. The micros() and millis() are the delay type routines; the OP would be required to use one of them in the loop() function should he adapt the trick of @UKHeliBob's Post#1.

Crespo94:
everytime a peak voltage is detected in my circuit.

For my own edification, and perhaps others', I'm very keen to know how a peak is detected. How do you say "ok, that's a peak", without the risk of a higher voltage hitting you? (Like when out hiking, you think you got to the top, but just as you were breaking out the tea, you saw more hill in front of you.)

arduin_ologist:
For my own edification, and perhaps others', I'm very keen to know how a peak is detected. How do you say "ok, that's a peak", without the risk of a higher voltage hitting you? (Like when out hiking, you think you got to the top, but just as you were breaking out the tea, you saw more hill in front of you.)

Have you heard the name of 'auto bias peak detection circuit'. The technique is about more that 35 years old, which I encountered with one of the sensors of Schlumberger Oil Company in 1982.

The micros() and millis() are the delay type routines;

WRONG, WRONG, WRONG

delay() stops anything else happening during the timing period

Used properly millis() and micros() allow the loop() function, and any other required code, to continue to run during the timing period

UKHeliBob:
WRONG, WRONG, WRONG

Thank you for reducing my blood pressure :slight_smile:

...R

UKHeliBob:
WRONG, WRONG, WRONG

delay() stops anything else happening during the timing period

Used properly millis() and micros() allow the loop() function, and any other required code, to continue to run during the timing period

void loop()
{
   if(flag1 == HIGH)      //set by the Op's ISR
   {
       presentMillis = millis();
       while(millis() - presentMillis < 500) //assume Op want 500 ms time delay
       {
           ;      //wait here or do something if there is
       }
       presentMillis = millis();
       flag1 == LOW;
   }
}

Is millis() not offering blocking (and hence the delay) in the above codes?

Is millis() not offering blocking in the above codes?

Yes, but note that I said it was non blocking when used properly
Your code sample does not use it properly

I assume that you are familiar with the BlinkWithoutDelay example

UKHeliBob:
Yes, but note that I said it was non blocking when used properly
Your code sample does not use it properly

I assume that you are familiar with the BlinkWithoutDelay example

Now, we are in the same platform; millis() has to be used properly so that it does not impose blocking. I have said that the millis() is a 'delay type function' (and not a 'delay function') from the view point of the codes of my Post#9.

I am glad that we have cleared up the confusion that your post #9 may have caused but the fact of the matter is that millis() and micros() are not in any way "delay type functions" however they are used

GolamMostafa:
Now, we are in the same platform; millis() has to be used properly so that it does not impose blocking.

How can millis() ever impose blocking, or impose non-blocking for that matter, since all it does is report the time?

I can look at the clock then go for a walk while my chicken is cooking, or sit and stare at the oven; my behavioural choice has nothing to do with the clock.

arduin_ologist:
How can millis() ever impose blocking, or impose non-blocking for that matter, since all it does is report the time?

Because someone used a while loop. That is the same as using delay() because delay() is itself exactly that, a while loop.

"while" loops are not a part of state machine programming, they need to be "unfolded" into the loop itself.


The confusion in this thread has been introduced by the word "interruption" - that causes people to become confused with machine interrupts. :roll_eyes:

Paul__B:
Because someone used a while loop. That is the same as using delay()

But that's not millis() "imposing" anything; millis() doesn't impose, it tells us the time is all. What we do with that knowledge of course, is a different matter.