element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
NexGen Flight Simuator Tech Tip VII: To HE!! with Keyboard Scanning!
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: phoenixcomm
  • Date Created: 18 Jan 2020 8:04 PM Date Created
  • Views 618 views
  • Likes 5 likes
  • Comments 2 comments
  • keyboard scanning
  • interrupt from keyboards
  • tech tip
  • keyboard with interrupts
  • priority encoder
  • dont scan keyboards
  • schmitt trigger
  • 7414
  • 74x148
  • arduino
  • 4x4 matrix keyboard
Related
Recommended

Tech Tip VII: To HE!! with Keyboard Scanning!

phoenixcomm
phoenixcomm
18 Jan 2020

image Ok, am I a little harsh, maybe, but when you have a keyboard that you don't use very much, just think of the wasted CPU cycles scanning the Keyboard! I one minute, in one hour? So what to do? In steps our 8 input to 3-line, Priority Encoder TI SN74x148.

A0 A1 A3 = GS
H H H 0 H
0 0 1 4 L
Table 1

 

Ok, you ask what is a Priority Encoder? Put it simply it is a device that will generate the proper output for any given key. Without a keypress, the encoder's output is 0.(update #2)  So let's say you pressed 4 to a ground state, its output would be 001 hex or 4 (table 1). Plus the GS pin will go low. Cool. But beware if you doing this method you will be generating a processor interrupt, so you must eliminate switch bounce with a Schmitt Trigger.

 

The picture below is from the TI datasheet mentioned in the link above. Please remember that to pull the TTL device to the ground from a high, one of the switches must be connected to the ground while the other side of the switch is wired to a pin on the priority encoder is high which means that you will need a pull-up resistor.image

The Priority Flag Pin must be connected to a Schmitt Trigger for debounce which is connected to your interrupt pin. (update #1)

So the only thing your software has to do when the interrupt is active is to read the 4 BCD data lines and perform a table lookup.

So in recap here is what you need:

  • SN74x148  Priority Encoder
  • SN74x08 or SN74x00
  • SN74x14 Schmitt Trigger
  • Resistor Networks x2 (9 pin 8 10k ohm) for pull-ups
  • RC network for Schmitt Trigger.

OBTW

Your software is now simplified as if you know the value of the nibble, a simple 1-dimensional table would be all you need as you most likely want ASCII output. A quick review of C ints and Chars are the SAME! My keyboard has 0-9, ENT, KBD, CLR, TGT

30 31 32 33 34 35 36 37 38 39 10 41 42 43
0 1 2 3 4 5 6 7 8 9 ENT CLR KBD TGT

 


char keyboardDecoder( int value ) {

    static int decoder[ ] = { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 10, 41, 42, 43 }

     return ( decoder[ value ] ); }

 

 

 

UPDATES

  1. Added the sentence starting with The Priority Flag Pin 1/18/2020 CAH
  2. Added the sentence with Without a keypress  1/18/2020 CAH
  3. To make decoding without the zero as an input you can start as the array index as 1, not zero so my array would start as 1 outputting 30. 1/18/2020 CAH
  4. PLEASE NOTE: The implied decimal zero condition requires no input condition, as zero is encoded when all nine data lines are at a high logic level. TI DATA BOOK
  5. UPDATED PAGE after "They Moved to a new provider"    JUNE 7, 2023 -CAH
  • Sign in to reply

Top Comments

  • phoenixcomm
    phoenixcomm over 5 years ago in reply to Jan Cumps +2
    Jan Cumps no you need an RC network before the Schmitt Trigger input itself. Maybe I did not make myself clear yes A0-A3 will bounce around. But when you press a button GS also goes low telling you that…
  • phoenixcomm
    phoenixcomm over 5 years ago in reply to Jan Cumps

    Jan Cumps no you need an RC network before the Schmitt Trigger input itself. Maybe I did not make myself clear yes A0-A3 will bounce around. But when you press a button

    GS also goes low telling you that have data available, good, bad, or otherwise so GS must be attached to the junction  R1 & R2 (SW1 not there) The RC network of R2/C1

    will give you one pulse even after the jitter. Remember that the output of the Schmitt Trigger is tied to the interrupt of the CPU. By the time the cpu looks at the input pins A0 A3 you will have a nice clean input.  got it? Go look at https://hackaday.com/2015/12/09/embed-with-elliot-debounce-your-noisy-buttons-part-i/  for pretty scope traces.  And I also put a 74xx14 Schmitt trigger in as well instead of the inverter.  Think of it this way the RC network filters out the jitter and the 7414 makes a very nice square wave.

    image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    I have a question about the Schmitt trigger. How does it help here against bouncing when its input, the SN74x08, only outputs 0s and 1s? It would pass through any high-low bouncing, wouldn't it?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube