Hello, some further comments about the switch matrix method -
Your requirement could be met with any one of the following configurations,
2 inputs, 4 outputs
3 inputs, 3 outputs
4 inputs, 2 outputs
If you really require to use interrupts, perhaps because you first need to wakeup the MCU from STOP mode, only the inputs require to be part of the KBI block. The outputs can use other GPIO pins. Assuming active low input configuration, you might use the following process -
- Prior to entering STOP mode, set all outputs to low state. This will ensure that wakeup and interrupt will occur if any key is pressed.
- After wakeup, you have a choice whether to handle the key scanning (and debounce) process within the ISR code, or within the main loop. I would probably opt for the latter.
- The scanning method I would possibly use would be to -
a) Set all outputs to high state,
b) wait 20-50ms debounce delay,
c) Identify the row and column of the switch closure by progressively setting each output low, and examining the input status. Perhaps the KBI needs to be disabled during this process, if within main loop.
With some additional complexity to the code, it would also be possible to prioritize multiple key presses.
If two simultaneous key presses should occur that happen to use the same input, but different outputs, it may be possible for excessive current to occur during the scanning process (3c above). A high output will become shorted to a low output. To avoid this, either use series (Schottky) diodes, as Encoder has done, or alternatively, do not drive the outputs active high. This is achieved by setting each output to an input with pullup, when a high state is required.
Regards,
Mac
Message Edited by bigmac on
2008-01-30 05:23 PM