This was just a question I thought of as I started working through a design project. Let's say I have a hall effect sensor on an encoder motor. I need to catch every pulse from this encoder so I use the readings on an interrupt pin to trigger whenever the value from the hall sensor changes from high to low or low to high. The example code from the motor manufacturer has the ISR read the hall sensors pins to read whether it is now low or now high. My question is: is it possible in the time between the pin triggering the ISR for the pin to change values? For example, say it changed to low from high, triggering an interrupt, but in the time it takes for the ISR to store registers and jump and start the ISR, could a fluctuation or noise push the pin back up to the high voltage reading? I know that with most MCUs we're dealing with something in the range of 10s of nanoseconds but I didn't know how sensitive this system would be to a problem like this. Thanks for the responses
ISR latency is often plenty short: under a microsecond. Unless your microcontroller is very slow, each edge interrupt should yield a proper logic level inside the interrupt routine. But that's not the whole story...
If you have other peripherals interrupting, you may have to wait for them to complete before your Hall sensor interrupt routine runs. Usually, interrupt routines take little time to complete, so a later Hall-level read (when the Hall interrupt is finally serviced) still won't be a problem.
If other interrupts cause service to be so slow that Hall level changes after its interrupt is scheduled, you may be able to prioritize interrupts, so that Hall interrupts are serviced promptly, while others are serviced only when Hall interrupts finish.
A different problem may occur at the slow-rotating end, when the Hall encoder sends out a just a few pulses each second. Logic edges may be unstable as they transit from low-to-high or from high-to-low, oscillating at a high frequency instead of providing a single, clean, sharp edge. A fast-responding interrupt routine may try to count each oscillation, resulting in many interrupts rather than the single-edge interrupt required.
This problem is similar to mechanical switches, which require edge "de-bouncing". A digital Hall sensor may include in its internal preamplifier some hysteresis to alleviate these unclean output edges.
In any case, check that very slow shaft rotation yields the proper edge-count. Also check that interrupt service captures every fast-rotating shaft logic edges.
"My question is: is it possible in the time between the pin triggering the ISR for the pin to change values?"
Yes in general it is possible. But then it becomes a misapplication of interrupts if the reason is because your encoder spins fast enough and has enough resolution to beat the ISR execution time. And if noise (or other signal instability) can cause the value to change like that then you have insufficient signal conditioning.
In general I really try to avoid using interrupts for encoder A and B channels.