1
\$\begingroup\$

I am using infineon XC866-1FR controller for my project. For the motor control, I am in need of exciting the coil by the combination of two external interrupts(external interrupt 1 && external interrupt 2) at a time. Can I do a single operation using the result of AND operation of two external interrupts?

\$\endgroup\$
2
  • \$\begingroup\$ The XC866 allows nested interrupts, so you could detect whether you were in an ISR for a given interrupt when the "other" interrupt is triggered by using flags or whatever. This does not sound like a very good thing to do. ISRs should be brief. \$\endgroup\$ Commented Apr 18, 2014 at 4:40
  • \$\begingroup\$ I think you will have to specify how close in time these interrupts need to occur to count as being "at the same time". As @EvertW mentions, interrupts are triggered by edges, not levels, so you can't "and them together" per se. Perhaps you mean instead that there's some pair of signals which each last some length of time, and it's the beginning of the time when both are on together that you need to perform your coil exciting operation? Could you just use an AND gate to AND the two signals together? \$\endgroup\$
    – gwideman
    Commented Apr 18, 2014 at 9:35

1 Answer 1

1
\$\begingroup\$

This sounds like a bad idea:

  • Interrupts should be independent from each other, otherwise very nasty race conditions and deadlocks can occur.
  • Only one interrupt can run code at a time.
  • Interrupts are triggered by signal edges, not signal level.

All this means that it will be very difficult to detect when the condition you want occurs, and when it stops.

If you want to do this in software, you will need to run a loop that polls the two signals to detect if the situation occurs. If your MCU has nothing else to do, this can be very fast & reliable, but other interrupts might upset the timing.

If polling is not fast enough because the condition only lasts very briefly, you will need a bit of external hardware, such as an AND gate, to combine the two signals and trigger an interrupt. This will detect very brief events.

For extremely accurate & fast signal generation, you can use the AND signal as external trigger for a timer.

\$\endgroup\$
2
  • \$\begingroup\$ FWIW, you can have level-triggered interrupts, at least on ATmega and ATxmega MCUs. The interrupt fires continuously as long as the input is held in the asserted state (either active high, or active low). \$\endgroup\$ Commented Apr 18, 2014 at 9:30
  • \$\begingroup\$ fair enough point. And in that case, the ISR for each could check if the other one is asserted for the AND function. Though this seems like rather an ill-defined way to proceed. Still need a good definition of the combination of the two events happening together. \$\endgroup\$
    – gwideman
    Commented Apr 18, 2014 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.