AttachInterrupt and zero crossiing detector

Hi all

I am to build a simple zero crossing detector which will output a 5V narrow pulse each time 50Hz mains voltage reaches the zero level.

I am not so experienced so i'd like your help. I have two questions.

  1. I am to use Ext int 2 pin of a 2560 board. Each time the detector's output pulse reaches the interrupt pin, a routine follows which last 19ms. We know that detector gives a pulse every 10ms. What will happen at this case? My goal is to run this routine every 20ms with not any break in between.

  2. Do I need any resistor between (detector's output & Ext int 2 pin) to ground?

Thanks

  1. 19ms is a really really long time to be in an ISR with everything else disabled. Are you positive that there's not a better way to do that?

  2. You would have to ask someone who knows something about the particular detector you have. You failed to mention any of that in your post.

  1. Yes routine lasts 19ms exactly. What the implications would be for that? I am sure that there would be more ways for doing that, but I find it simple and according to my very little knowledge.

  2. Detector outputs a 5V pulse of about 50 uS @ 0.5mA. I will use the "change" detecting the rising slope. EMERGING TECHNOLOGIES: SIMPLE ZERO CROSSING DETECTOR USING OPTO COUPLER

Jeg_1:

  1. Yes routine lasts 19ms exactly. What the implications would be for that? I am sure that there would be more ways for doing that, but I find it simple and according to my very little knowledge.

Sometimes what looks simple for those with very little knowledge is actually the hard way to do things. 19ms is a long long time to be in an ISR. During that time your timing interrupt isn't running, so millis() and delay() don't work. Serial communications don't work. All other background interrupts are disabled. You don't want to run 19ms of code in an interrupt context is the overall point.

It's impossible to help you much more than that without knowing what it is that you are building and how you intend for it to work.

Jeg_1:
2. Detector outputs a 5V pulse of about 50 uS @ 0.5mA. I will use the "change" detecting the rising slope.

OK, catch that with an interrupt and set a flag you can react to in the loop for the 19ms long routine.