Hardware Reference
In-Depth Information
Each interrupt correctly shows that pin GPA7 changed. But look closely at the
captured values for the inputs:
1.
The captured level of the input is 0 (line 1).
2.
The captured level change of the input is now 1 (line 2).
3.
The next input change shows a captured level of 1 (line 3).
How does the state of an input change from a 1 to a 1? Clearly what happens is that
the input GPA7 changes to low but returns to high by the time the interrupt is captured.
Push button, switch, and key bounces can occur often with a variety of pulse widths,
in the range of microseconds to milliseconds, until the contact stabilizes (off or on). The
very action of pushing a button can initiate a series of a thousand pulses. Some pulses
will be too short for the software to notice, so it must be prepared to deal with this.
Sometimes electronics circuits are applied to eliminate “key debouncing” so that the
software will see a clean and singular event. This is what is accomplished in Chapter 8,
where a flip-flop is used.
Response Times
You should be aware of the interrupt notification limitations provided by the poll(2)
system call. The input lines could easily change faster than the Raspberry Pi can respond.
Consider the process involved:
1.
An input GPIO extender pin changes in value.
2.
The MCP23017 device activates INT A by bringing it from a
high to a low (a few cycles later).
3.
The Raspberry Pi's GPIO 17 pin sees a falling input level
change.
4.
The device driver responds to the GPIO pin change by
servicing an interrupt and then notifies the application
waiting in poll(2) .
5.
The application sends some I2C traffic to query the INTFA and
INTFB flag registers in the MCP23017.
6.
Registers GPIOA and GPIOB must also be read to clear the
interrupt, involving more I/O on the I2C bus.
Consequently, there is considerable delay in sensing a GPIO change and the clearing
of the device interrupt.
An informal test using select(2) purely for delay purposes (no file descriptors)
required a minimum of approximately 150 μs on a 700 MHz Pi. The poll(2) call is likely
to be nearly identical. Attempting to set smaller timed delays bottom ed o ut near
150 μs. This suggests that the quickest turnaround for reacting to an INT signal from the
MCP23017 will be 150 μs (excluding the time needed to actually service the registers in
 
 
Search WWH ::




Custom Search