Download presentation
Presentation is loading. Please wait.
Published byJean Floyd Modified over 9 years ago
1
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs
2
2 Button Inputs - Bounce Problem We want to recognize this as a single press of the switch rather than multiple presses as indicated in the voltage diagram Solutions: Some expensive switches do not bounce We can debounce switches with hardware We can debounce switches with software
3
3 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Hardware De-bouncing Use hardware to de-bounce button presses Button/Switch bounce removed using capacitor and Schmitt Trigger Why is this a bad circuit? Inverter with Schmitt Trigger
4
4 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Hardware De-bouncing Use hardware to de-bounce button presses Button/Switch bounce removed using capacitor and Schmitt Trigger Switch/button touch/press removed by capacitor Switch/button release also removed by capacitor
5
5 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Hardware De-bouncing Choose capacitor value large enough such that the inverter input does not exceed 0.7V threshold. If this exceeds the input threshold, we will not have de-bounced the switch/button
6
6 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Hardware De-bouncing Resistance of contact is 0.1Ω Instantaneous current when switch closes is large enough to cause a spark Will shorten life of your button
7
7 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Hardware De-bouncing Good hardware de-bounce implementation Limit instantaneous current to avoid sparks
8
8 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing De-bounce switch/button using software code on your microcontroller No additional hardware required Steps: Wait for key to be presses Delay 10 ms (should be longer than expected bounce time) Wait for key to be released Delay 10 ms
9
9 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing Flowchart for software code Software de-bounce for button press Software de-bounce for button release
10
10 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing for Button Press - Assembly waitPressldda PORTT ;wait for press anda #$01 bne waitPress ldd DELAY ;wait 10ms loopdecd bne loop rts Assembly Code:
11
11 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing for Button Press - Assembly void waitPress(void) { while (PORTT & 0x01); /*wait for press*/ for(i=0; i<DELAY; i++); /* delay */ } C Code:
12
12 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing for Button Release - Assembly waitRelease ldaa PORTT anda #$01 beq waitRelease ldd DELAY loopdecd bne loop rts Assembly Code:
13
13 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing for Button Release - Assembly void waitforrelease(void) { while(!(PORTT & 0x01)); for(i=0; i<DELAY; i++); } C Code:
14
14 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing Timing is not very accurate How can we better code the subroutines? Use internal timer (TCNT)
15
15 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Software De-bouncing Alternative simple software de-bouncing Read switch/button until you read the same value twice
16
16 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypads Collection of several keys grouped into a single device Can buy keypads in many different configurations Build your own keypad using individual buttons How can we read dozens of keys on the keypad without requiring dozens on individual input ports on our microprocessor? Hint: It’s similar to how we can interface with dozens of outputs using only a few pins
17
17 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypads
18
18 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed
19
19 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed 0 1 1 1 1. Set each row output sequentially to output 0 2. Check column inputs to see if key was pressed What if this key is pressed?
20
20 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed 0 1 1 1 1. Set each row output sequentially to output 0 2. Check column inputs to see if key was pressed 1 1 1 1 No key pressed on first row
21
21 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed 1 0 1 1 1. Set each row output sequentially to output 0 2. Check column inputs to see if key was pressed 1 1 1 1 No key pressed on first row
22
22 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed 1 1 0 1 1. Set each row output sequentially to output 0 2. Check column inputs to see if key was pressed 1 0 1 1 Key press detected in second column
23
23 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Scanning Similar to scanning for controlling multiple output LEDs Scan the keys one row at a time and read the column lines to see if any key on that row were pressed 1 1 1 0 1. Set each row output sequentially to output 0 2. Check column inputs to see if key was pressed 1 1 1 1 No key pressed on first row
24
24 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Multiplexing Could also use keypad multiplexing Enable each row one at a time by outputting the row address to the decoder input Decoder will enable only one row Use encoder to read key press and output column address of keypress to microcontroller + 5V
25
25 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Multiplexing – Challenges Can one handle one key press at a time How do we recognize the when no keys are pressed? + 5V
26
26 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs Keypad Multiplexing Need an encoder to provide the column address of the key that was pressed Can use the output E0 of the following encoder to detect if no key are pressed
27
27 ECE 372 – Microcontroller Design Parallel IO Ports - Outputs Mill Game
28
28 ECE 372 – Microcontroller Design Parallel IO Ports - Outputs Mill Game 3 Rows 8 Columns
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.