I have a 4x4 Matrix Keypad and i successfully interface it with micro-controller.
Everything is working properly, but is there any way to detect whether matrix keypad is present or not present in the slot.
Actually in my project i have to generate error if Matrix Keypad is not present.
Any idea how can i implement it, do i need to modify my hardware.
A matrix keypad with no key pressed is just an open circuit. It can't be detected as such. You'll need to add other identification elements, e.g. resistor connected between matrix lines or additional signals.
swtich all lines to the default state (I assume pulled up)
then switch only one line to GND
Wait some ms
Then switch the same line to pull up. (If possible use a very weak pullup)
Read the port (and count the loops) until it becomes HIGH.
Without keypad it should be faster HIGH than with connected keypad.
I´m nor sure if it works. It depends on pullup value, and capacitance..
A matrix keypad with no key pressed is just an open circuit. It can't be detected as such. You'll need to add other identification elements, e.g. resistor connected between matrix lines or additional signals.
Hmm this will definitely work, but for this i have to order customized keypads with one such extra sensing signal. I think this is not possible in membrane based keypads available in markets/online.
- - - Updated - - -
swtich all lines to the default state (I assume pulled up) You means all rows and columns configured as input mode
then switch only one line to GND Sorry but i didn't get this point
Wait some ms
Then switch the same line to pull up. (If possible use a very weak pullup)
Read the port (and count the loops) until it becomes HIGH.
Assuming a 4x4 keypad, perhaps just adding 1 up to 4 diodes ( katodes tied together ) in parallel with the matrix polarized in the opposite direction of which is intended to scan the nibble, this way you could check at large intervals for existing connection. Indeed, this is suited to work only with routines that scan only one key pressed at a time - the standard procedure ( routines that read multiple keys pressed at a once, performs reading of entire nible, alternating row/column ).
its not possible with just the matrix keyboard. However you could do a key test, in the same way that is done by a PC during bootup (ie: check if a key is pressed by mistake or stuck), the criteria here is that during startup ensure no keys are pressed,
however this will not work if only the pullups are connected and not the keyboard.
If you are able to change the electrical design, the simplest method is to fit the pull-down (or pull-up) resistors to the keypad itself. On one or more of the microcontroller input lines, connect a high value resistor pulling to the opposite polarity. Reading the lines without the keypad will show the high value resistor state, with it plugged in, the lower value resistors on the keypad will reverse the state. It isn't foolproof, it can mistake a keypad with all the keys held down at once as no keypad at all but that's an unlikely scenario.
I have a 4x4 Matrix Keypad and i successfully interface it with micro-controller.
Everything is working properly, but is there any way to detect whether matrix keypad is present or not present in the slot.
Actually in my project i have to generate error if Matrix Keypad is not present.
Any idea how can i implement it, do i need to modify my hardware.
Simple method is to provide ground loopback to a logic with pullup input to detect device installed. When installed input becomes grounded, which can be 1 of many status bits in an addressable latch for self test or auto-config.
If the keyboard lines are connected to lines that can be switched temporarily one to PWM and another one to ADC you could try generating a very high frequency pulse train sending it down the line and measure the disturbance it creates on the ADC line coming from electromagnetic coupling between lines from the cables or parallel traces in the keyboard's pcb. You could add an RF diode as rectifier and a small cap in the ADC linec to read DC from the rectification coming from the RF pickup.