Page 1 of 1

Interrupt speed

Posted: Tue May 05, 2020 11:48 am
by echase
How do interrupts work at the nanosecond level in PICs and Flowcode? Say I have a 8 bit all port interrupt. When any of the 8 bits changes state it triggers the interrupt “instantly”. But in practice I assume that it works at processor clock speed rather than instantly so needs say 1 to 4 clocks to generate the interrupt. Thus if say the clock period is 20ns on a 50MHz PIC and I have a data change lasting only 5nS will that trigger the interrupt?

I ask because I want to detect changes on a fast multi bit signal. and store the results. Say it changes from 1111 to 1100. Due to rise and fall times and propagation delays there is a very short period when it may have an indeterminate value, like 1110 or 1101, before changing solidly to 1100. Say on one clock cycle it is 1111, on the next 1101 and the third 1100. Will the interrupt thus trigger twice?

This is rather like debouncing a switch input. Do interrupts effectively debounce and over what period of time? I’d follow the interrupt with “read the port” command by which time the data is hopefully solid. But it will not give the right answer if it rapidly triggers twice or more so I end up storing more than one result in quick succession.

Re: Interrupt speed

Posted: Wed May 06, 2020 3:17 pm
by Benj
Hello,

You might find the amount of time required to generate an interrupt in the electrical characteristics section of the datasheet. As long as the signal is pulled low and high so you get nice clean edges that go to VCC/VSS then you should be ok.

The interrupt will have some latency before the routine is triggered. I think there is usually a few instructions cycles to set things up before we jump into the user macro. The compiler takes care of this. The interrupt flag generally gets cleared when you leave the interrupt macro so any other interrupts that happen while you are still inside the macro or waiting to jump into the macro will likely go undetected.
Thus if say the clock period is 20ns on a 50MHz PIC and I have a data change lasting only 5nS will that trigger the interrupt?
The interrupt is hardware driven and so yes it should still happen. Though please try and find the information in the datasheet regarding the minimum pulse length. If you do have issues you could always use something like a latching buffer to maintain the state until you have detected and serviced the pulse.