Temporarily Disabling External Interrrupts

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Due to a bad hardware design, I am having an intermittent problem with noise when a relay opens. About every 3rd time I command the controller to open the relay, it triggers INT2 -

Of course the best solution would be to fix the hardware. Since I can't "easily" do that, I need a software solution.

Here's what I have (pseudo code):

SIGNAL int2
{
     set flag2;
}

SIGNAL int3
{
     set flag3;
}

main
{
     while (1)
     {
          if (flag2) {}
          if (flag3) {}
     }
}

When I push the button attached to int3, my relay shuts off, and the noise or whatever triggers (about every 3rd time) int2 (always int2). I know I can disable int2 (EIMSK) and clear any other interupts waiting for int2 (EIFR), but I am not sure where to do it....

I tried this:

created functions:

switches_off
{
     EIMSK &= ~(_BV(INT2));
     EIFR = (_BV(INTF2));
}

switches_on
{
     EIFR = (_BV(INTF2));
     EIMSK |= _BV(INT2);
}

and then in my main, while, if statement, did this:

if (flag3)
{
     switches_off();
     shut_off_relay();
     wait_for_a_long_time_to_let_noise_dissipate();
     switches_on():
}

....it doesn't work....

Pullups are enabled.

Any ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fix the hardware

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Somewhat aside: Is the relay connected to the AVR, and if so how? If this is not done properly with eg. "freewheeling" diodes, it will probably hammer Your AVR to death in a short time due to "back EMF".

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really agree with js and JohanEkdahl.

However, since lots of people stubbornly ignore the best advice, if you are trying to use INT2 for something legitimate and it is triggering on noise that you will not take care of, then the best solution is to answer the noise interrupt on INT2 and let the interrupt software figure out if it was noise or not. That is if you can get enough information together inside the interrupt routine and you have enough spare processing cycles available in your INT2 interrupt processing overhead. Maybe there is something in the INT2 hardware that the interrupt software can check to see if it was a legitimate INT2 interrupt?

Using software to mask off INT2 and manually reseting its flag can lead to lost INT2 interrupts (those would be the legitimate ones you do want to respond to).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Poll the buttons & debounce. Almost all switches need debouncing anyway, over a period of milliseconds. Rarely is instant response needed, and processing every edge can lead to vicious bouncing problems.

But if the INTn is going off "by itself" due to the relay then, indeed, fix that cause. (But still poll & debounce your switches.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps when you trigger your relay, you can set a flag somewhere. Then sometime later on a timer event or something clear the flag. Then have your Int2 routine check the flag to see if should pay attention to the flag.

Hint: Sneak in at night and solder a diode across the relay coil so it's reverse biased. Will do wonders for your project. Amazingly, just a resistor can help.

---
Formerly Torby. Stitch626 just seemed a more descriptive nicname.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVR is connected to the relay via PORTC driving a transistor to activate the relay coil.

Debouncing is being taken care of in hardware via a MC14490 IC.

The coil on the relay already has a diode across it.

About the only thing I'm thinking I could do to fix the hardware properly is to put an optocoupler on the driving circuit.

Does anyone see anything obvious in my code to disable the INT2 interrupt? I am not concerned about missing an interrupt.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Pullups are enabled

Pullups are pretty hign value. Try an exernal pullup and a cap ( 2k2 and 100nF to ****+5V***) if there is that much noise around.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What kind of current/voltage is switched by the relay? If it has to switch mains voltages or any high power levels, do we have a snubber circuit or equivalent (Varistor, Transorb etc.) across the contacts?

Andreas