We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all,
The C167 has edge based external interrupts (programmable to rising/falling/both). Does anybody have a reference to info on how to interface it with a level based interrupt device (e.g. an external multi-port UART)? When you OR several interrupt sources together, you miss interrupts. What's the "industry standard" way of handling this?
I just checked the datasheet of an XC167 and it also has edge based external interrupts only. Could somebody explain, to a simple software engineer :-), what the advantage of edge based interrupts is? Level based seems to make alot more sense to me; it's plain and simple.
Regards, Joost Leeuwesteijn
For a simple software engineer it might be more software to handle a level based interrupt if the level persists for more time then his ISR and he wants to serve only once per interrupt (which might be more often)!!!!!!! The edge will on other hand trigger the ISR only once.
in general (I know not other case) level interrupts can only be used where the ISR issue an I/O signal that makes the interrupting device remove the interrupt level.
Erik
That's how our UART works, but the C167 can only handle edge based external interrupts. I was wondering how to interface the two. Level based makes more sense to me, handle the interrupt and give an ACK by clearing the interrupt.
The second issue is that the UART has 4 ports, each generating a level based interrupt but we only have one external interrupt port available on the C167. A simple OR of the interrupts lines (sharing) doesn't work because the C167 is only edge based. When 2 ports generate an interrupt, the C167 will not be able to detect both interrupts/edges. Level based interrupts seem to be more flexible. If you share an interrupt line, a second interrupt source will keep the line high, even after clearing a first interrupt source. With edge based interrupts that's not possible, the edge is already gone. There's a chance that you miss interrupts when using edge based.
Is there anyone who ran into this before and figured out a solution? Interfacing multiple level based interrupt sources to a C167 seems like something that has been done before. (Maybe I shouldn't have set the toolset to C16X to reach a bigger crowd).
If the C166 is able to read the logic level of the pin that is used for the external interrupt, you will have to write your interrupt handler so that it polls the different UARTs and service them until the ORed interrupt signal gets deactivated.
Just to make sure, you should also consider adding a poll of the interrupt input pin in the main loop, in case you manage to get your interrupt handler out of sync.
Whether it's level based or edge based, if you are sharing an interrupt through wired-OR lines, your interrupt service routine must loop through every interrupt source. It must test and clear every source, and the loop termination condition must be that all sources have been cleared.
The C167 should not miss any interrupt edges unless they occur before the interrupt is enabled. If this is important, the best solution is to test the level of the pin just after you enable the interrupt, and assert the interrupt request bit in your program.