EmbeddedRelated.com
Forums

Matrix keyboard

Started by Morphy Zhores June 17, 2006
Hi,
I am planning to interface a matrix 4x4 keyboard to LPC2138 using
interrupts. I am using the keil MCB2130 board. I am thinking of using one
interrupt pin and 8 GPIO to receive the data. Please advice regarding the
interrupt to be given. Help regarding is really appreciated.

Regards,
Morphy.


An Engineer's Guide to the LPC2100 Series

Hi,
You can control 16 keys using one pin of your processor but at he cost of extra chip which would be the 555.

Now, you could configure the 555 as an astable multivibrator, where the clock could be varied depending on the resistors. The resistors should be connected in the rows and columns in your case four for each. Now, when you press any key, a pair of resistors will be chosen whose sum will be unique cause they would be serial. Now that the net resistance value is different, the clock of the oscillator would vary. This clock could be connected to the Interrupt pin ( configured as egde triggered ).

Now, how to know which key is pressed?

When the interrupt occurs on the oscillator, start a timer and stop the timer on the second edge. You would know the width of the pulse. Hence the key number.

Cheers,
Vineet.

Morphy Zhores wrote: Hi,
I am planning to interface a matrix 4x4 keyboard to LPC2138 using
interrupts. I am using the keil MCB2130 board. I am thinking of using one
interrupt pin and 8 GPIO to receive the data. Please advice regarding the
interrupt to be given. Help regarding is really appreciated.

Regards,
Morphy.








---------------------------------
How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.







A method I have used is to simply run the resistor network into an A/D
pin or else add a capacitor and treat it as an RC timing network using a
single digital I/O.

Morphy seems to want a no pain hardware solution that simply interrupts
the cpu but even at this very basic basic level lacks the skills to
implement it. I think if he spends at least a few minutes on it he
should figure it out for himself. Many students resort to internet
"copy&paste" to fill in the blanks without ever really learning. This
way we "encourage" him to learn, wouldn't you agree?

*Peter*

vineet jain wrote:
> Hi,
> You can control 16 keys using one pin of your processor but at he cost
> of extra chip which would be the 555.
>
> Now, you could configure the 555 as an astable multivibrator, where the
> clock could be varied depending on the resistors. The resistors should
> be connected in the rows and columns in your case four for each. Now,
> when you press any key, a pair of resistors will be chosen whose sum
> will be unique cause they would be serial. Now that the net resistance
> value is different, the clock of the oscillator would vary. This clock
> could be connected to the Interrupt pin ( configured as egde triggered ).
>
> Now, how to know which key is pressed?
>
> When the interrupt occurs on the oscillator, start a timer and stop the
> timer on the second edge. You would know the width of the pulse. Hence
> the key number.
>
> Cheers,
> Vineet.
>
> Morphy Zhores > > wrote: Hi,
> I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> interrupts. I am using the keil MCB2130 board. I am thinking of using one
> interrupt pin and 8 GPIO to receive the data. Please advice regarding the
> interrupt to be given. Help regarding is really appreciated.

Never worked with 2138, didnt know there was an ADC.Anyways solutions are plenty, choice is yours...

Cheers,
Vineet.

Peter Jakacki wrote: A method I have used is to simply run the resistor network into an A/D
pin or else add a capacitor and treat it as an RC timing network using a
single digital I/O.

Morphy seems to want a no pain hardware solution that simply interrupts
the cpu but even at this very basic basic level lacks the skills to
implement it. I think if he spends at least a few minutes on it he
should figure it out for himself. Many students resort to internet
"copy&paste" to fill in the blanks without ever really learning. This
way we "encourage" him to learn, wouldn't you agree?

*Peter*

vineet jain wrote:
>
>
> Hi,
> You can control 16 keys using one pin of your processor but at he cost
> of extra chip which would be the 555.
>
> Now, you could configure the 555 as an astable multivibrator, where the
> clock could be varied depending on the resistors. The resistors should
> be connected in the rows and columns in your case four for each. Now,
> when you press any key, a pair of resistors will be chosen whose sum
> will be unique cause they would be serial. Now that the net resistance
> value is different, the clock of the oscillator would vary. This clock
> could be connected to the Interrupt pin ( configured as egde triggered ).
>
> Now, how to know which key is pressed?
>
> When the interrupt occurs on the oscillator, start a timer and stop the
> timer on the second edge. You would know the width of the pulse. Hence
> the key number.
>
> Cheers,
> Vineet.
>
> Morphy Zhores > > wrote: Hi,
> I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> interrupts. I am using the keil MCB2130 board. I am thinking of using one
> interrupt pin and 8 GPIO to receive the data. Please advice regarding the
> interrupt to be given. Help regarding is really appreciated.

__________________________________________________



Hi,
Thank you Vineet and Peter. Using 555 is quite interesting. Using this
method the long press could repeat the functionality on the key right?. So
for no-Press the osc should produce some frequency and this could be taken
as the break event right? Please correct me if wrong.

Let me continue with the project and contact you with the realtime problems.

Once again thanks a lot.

Regards,
Morphy.
On 6/18/06, vineet jain wrote:
>
> Never worked with 2138, didnt know there was an ADC.Anyways solutions are
> plenty, choice is yours...
>
> Cheers,
> Vineet.
>
> Peter Jakacki wrote: A
> method I have used is to simply run the resistor network into an A/D
> pin or else add a capacitor and treat it as an RC timing network using a
> single digital I/O.
>
> Morphy seems to want a no pain hardware solution that simply interrupts
> the cpu but even at this very basic basic level lacks the skills to
> implement it. I think if he spends at least a few minutes on it he
> should figure it out for himself. Many students resort to internet
> "copy&paste" to fill in the blanks without ever really learning. This
> way we "encourage" him to learn, wouldn't you agree?
>
> *Peter*
>
> vineet jain wrote:
> >
> >
> > Hi,
> > You can control 16 keys using one pin of your processor but at he cost
> > of extra chip which would be the 555.
> >
> > Now, you could configure the 555 as an astable multivibrator, where the
> > clock could be varied depending on the resistors. The resistors should
> > be connected in the rows and columns in your case four for each. Now,
> > when you press any key, a pair of resistors will be chosen whose sum
> > will be unique cause they would be serial. Now that the net resistance
> > value is different, the clock of the oscillator would vary. This clock
> > could be connected to the Interrupt pin ( configured as egde triggered
> ).
> >
> > Now, how to know which key is pressed?
> >
> > When the interrupt occurs on the oscillator, start a timer and stop the
> > timer on the second edge. You would know the width of the pulse. Hence
> > the key number.
> >
> > Cheers,
> > Vineet.
> >
> > Morphy Zhores > > > wrote: Hi,
> > I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> > interrupts. I am using the keil MCB2130 board. I am thinking of using
> one
> > interrupt pin and 8 GPIO to receive the data. Please advice regarding
> the
> > interrupt to be given. Help regarding is really appreciated.
>
> __________________________________________________
>
Hi,
Yes, if the key is pressed for long one frequency would be generated triggering a lot of interrupts. Hence you should have a debouncing delayfor sometime...say 50ms and then process the interrupt for key being pressed.

Cheers,
Vineet.

Morphy Zhores wrote: Hi,
Thank you Vineet and Peter. Using 555 is quite interesting. Using this
method the long press could repeat the functionality on the key right?. So
for no-Press the osc should produce some frequency and this could be taken
as the break event right? Please correct me if wrong.

Let me continue with the project and contact you with the realtime problems.

Once again thanks a lot.

Regards,
Morphy.

On 6/18/06, vineet jain wrote:
>
> Never worked with 2138, didnt know there was an ADC.Anyways solutions are
> plenty, choice is yours...
>
> Cheers,
> Vineet.
>
> Peter Jakacki wrote: A
> method I have used is to simply run the resistor network into an A/D
> pin or else add a capacitor and treat it as an RC timing network using a
> single digital I/O.
>
> Morphy seems to want a no pain hardware solution that simply interrupts
> the cpu but even at this very basic basic level lacks the skills to
> implement it. I think if he spends at least a few minutes on it he
> should figure it out for himself. Many students resort to internet
> "copy&paste" to fill in the blanks without ever really learning. This
> way we "encourage" him to learn, wouldn't you agree?
>
> *Peter*
>
> vineet jain wrote:
> >
> >
> > Hi,
> > You can control 16 keys using one pin of your processor but at he cost
> > of extra chip which would be the 555.
> >
> > Now, you could configure the 555 as an astable multivibrator, where the
> > clock could be varied depending on the resistors. The resistors should
> > be connected in the rows and columns in your case four for each. Now,
> > when you press any key, a pair of resistors will be chosen whose sum
> > will be unique cause they would be serial. Now that the net resistance
> > value is different, the clock of the oscillator would vary. This clock
> > could be connected to the Interrupt pin ( configured as egde triggered
> ).
> >
> > Now, how to know which key is pressed?
> >
> > When the interrupt occurs on the oscillator, start a timer and stop the
> > timer on the second edge. You would know the width of the pulse. Hence
> > the key number.
> >
> > Cheers,
> > Vineet.
> >
> > Morphy Zhores > > > wrote: Hi,
> > I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> > interrupts. I am using the keil MCB2130 board. I am thinking of using
> one
> > interrupt pin and 8 GPIO to receive the data. Please advice regarding
> the
> > interrupt to be given. Help regarding is really appreciated.
>
>
>
>
>
> __________________________________________________
>
>
>
>
>
>
>
>
>
Hi, can you send in the circuit diagram of the 555 timer way of implementing a matrix keyboard. Looks interesting as I have never heard of it.

Thanks,
Jack.

vineet jain wrote:
Hi,
Yes, if the key is pressed for long one frequency would be generated triggering a lot of interrupts. Hence you should have a debouncing delayfor sometime...say 50ms and then process the interrupt for key being pressed.

Cheers,
Vineet.

Morphy Zhores wrote: Hi,
Thank you Vineet and Peter. Using 555 is quite interesting. Using this
method the long press could repeat the functionality on the key right?. So
for no-Press the osc should produce some frequency and this could be taken
as the break event right? Please correct me if wrong.

Let me continue with the project and contact you with the realtime problems.

Once again thanks a lot.

Regards,
Morphy.

On 6/18/06, vineet jain wrote:
>
> Never worked with 2138, didnt know there was an ADC.Anyways solutions are
> plenty, choice is yours...
>
> Cheers,
> Vineet.
>
> Peter Jakacki wrote: A
> method I have used is to simply run the resistor network into an A/D
> pin or else add a capacitor and treat it as an RC timing network using a
> single digital I/O.
>
> Morphy seems to want a no pain hardware solution that simply interrupts
> the cpu but even at this very basic basic level lacks the skills to
> implement it. I think if he spends at least a few minutes on it he
> should figure it out for himself. Many students resort to internet
> "copy&paste" to fill in the blanks without ever really learning. This
> way we "encourage" him to learn, wouldn't you agree?
>
> *Peter*
>
> vineet jain wrote:
> >
> >
> > Hi,
> > You can control 16 keys using one pin of your processor but at he cost
> > of extra chip which would be the 555.
> >
> > Now, you could configure the 555 as an astable multivibrator, where the
> > clock could be varied depending on the resistors. The resistors should
> > be connected in the rows and columns in your case four for each. Now,
> > when you press any key, a pair of resistors will be chosen whose sum
> > will be unique cause they would be serial. Now that the net resistance
> > value is different, the clock of the oscillator would vary. This clock
> > could be connected to the Interrupt pin ( configured as egde triggered
> ).
> >
> > Now, how to know which key is pressed?
> >
> > When the interrupt occurs on the oscillator, start a timer and stop the
> > timer on the second edge. You would know the width of the pulse. Hence
> > the key number.
> >
> > Cheers,
> > Vineet.
> >
> > Morphy Zhores > > > wrote: Hi,
> > I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> > interrupts. I am using the keil MCB2130 board. I am thinking of using
> one
> > interrupt pin and 8 GPIO to receive the data. Please advice regarding
> the
> > interrupt to be given. Help regarding is really appreciated.
>
> __________________________________________________
>
The only good reason I can think of for using interrupts is to come
out of some sort of Sleep/ Low Power mode.

Otherwise the easiest way is to use 4 Gpio's for Column and 4 for Rows
and poll. The poll could be done in an Timer ISR if you like.

All the best.
--- In l..., "Morphy Zhores" wrote:
>
> Hi,
> I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> interrupts. I am using the keil MCB2130 board. I am thinking of
using one
> interrupt pin and 8 GPIO to receive the data. Please advice
regarding the
> interrupt to be given. Help regarding is really appreciated.
>
> Regards,
> Morphy.
>
>

It would be on the net. Read it long time back. The circuit anyways shoudn't be complicated. When you connect swtiches to IO's you need a pull up. See if you can manipulate them to get different values of resistors.

Also since there are 16 switches a combo of 4 resistors should be enough. And plug in that net resistor in the astable multivibrator circuit ( any circuit book will have that ).

See if this helps.

Cheers,
Vineet.

Jack Key wrote:
Hi, can you send in the circuit diagram of the 555 timer way of implementing a matrix keyboard. Looks interesting as I have never heard of it.

Thanks,
Jack.

vineet jain wrote:
Hi,
Yes, if the key is pressed for long one frequency would be generated triggering a lot of interrupts. Hence you should have a debouncing delayfor sometime...say 50ms and then process the interrupt for key being pressed.

Cheers,
Vineet.

Morphy Zhores wrote: Hi,
Thank you Vineet and Peter. Using 555 is quite interesting. Using this
method the long press could repeat the functionality on the key right?. So
for no-Press the osc should produce some frequency and this could be taken
as the break event right? Please correct me if wrong.

Let me continue with the project and contact you with the realtime problems.

Once again thanks a lot.

Regards,
Morphy.

On 6/18/06, vineet jain wrote:
>
> Never worked with 2138, didnt know there was an ADC.Anyways solutions are
> plenty, choice is yours...
>
> Cheers,
> Vineet.
>
> Peter Jakacki wrote: A
> method I have used is to simply run the resistor network into an A/D
> pin or else add a capacitor and treat it as an RC timing network using a
> single digital I/O.
>
> Morphy seems to want a no pain hardware solution that simply interrupts
> the cpu but even at this very basic basic level lacks the skills to
> implement it. I think if he spends at least a few minutes on it he
> should figure it out for himself. Many students resort to internet
> "copy&paste" to fill in the blanks without ever really learning. This
> way we "encourage" him to learn, wouldn't you agree?
>
> *Peter*
>
> vineet jain wrote:
> >
> >
> > Hi,
> > You can control 16 keys using one pin of your processor but at he cost
> > of extra chip which would be the 555.
> >
> > Now, you could configure the 555 as an astable multivibrator, where the
> > clock could be varied depending on the resistors. The resistors should
> > be connected in the rows and columns in your case four for each. Now,
> > when you press any key, a pair of resistors will be chosen whose sum
> > will be unique cause they would be serial. Now that the net resistance
> > value is different, the clock of the oscillator would vary. This clock
> > could be connected to the Interrupt pin ( configured as egde triggered
> ).
> >
> > Now, how to know which key is pressed?
> >
> > When the interrupt occurs on the oscillator, start a timer and stop the
> > timer on the second edge. You would know the width of the pulse. Hence
> > the key number.
> >
> > Cheers,
> > Vineet.
> >
> > Morphy Zhores > > > wrote: Hi,
> > I am planning to interface a matrix 4x4 keyboard to LPC2138 using
> > interrupts. I am using the keil MCB2130 board. I am thinking of using
> one
> > interrupt pin and 8 GPIO to receive the data. Please advice regarding
> the
> > interrupt to be given. Help regarding is really appreciated.
>
> __________________________________________________
>
--- In l..., "fordp2002" wrote:
>
> The only good reason I can think of for using interrupts is to come
> out of some sort of Sleep/ Low Power mode.
>
> Otherwise the easiest way is to use 4 Gpio's for Column and 4 for Rows
> and poll. The poll could be done in an Timer ISR if you like.
>
> All the best.

Don't need a timer ISR and use sleep/low power if you like:

use P0.14, 0.15, o.16 and 0.30 as inputs (these are the EINT pins)
with pull up resistors and take 4 other GPIO pins as output.

Set the 4 outputs to Low, configure the EINT and go into idle mode.
Now the processor will wake up on pressing any of the keys and you can
start scanning the matrix.
Don't forget a debounce.

Rob