555 timer -  (or millis() during interrupt)

Hi-

I’m roughing out an idea and thought I would ask for some input.

I want to trigger something during an interrupt and have it last <= 50 ms. I read that I can’t use millis() during an interrupt so that I can’t do something like this in the ISR:

  dripStopTime = millis() + 50;
  digitalWrite(output12v1, HIGH);

and then in my loop() check if millis() >= dripStopTime and set that pin back to low.

(if I am incorrect here I would be glad to know!)

So I was thinking about 555 timers - and the circuits look easy - but I haven’t found any info about cap charging rates, etc that would be in the 50 ms range. I don’t need it to be precise - I just need it to be a really small time slice.

thanks for any insight!

–Roy

You can call millis() from inside an ISR, you just can't loop on it because the value it returns will not change while you are in your ISR since the ISR that drives it cannot execute. If your ISR is short (i.e. under a millisecond or two), you can safely set a global equal to millis() inside that ISR and have it be accurate. You will just need to conduct your delay outside the ISR where millis() will function.

It's also possible to re-enable interrupts inside your ISR so that millis() will continue to update, but this can lead to problems so you should only do this if your really know what you're doing.

  • Ben