1 / 28

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs. ECE 372 – Microcontroller Design Parallel IO Ports - Inputs. 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:

khoi
Download Presentation

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs

  2. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • 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. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Hardware De-bouncing • Use hardware to de-bounce button presses • Button/Switch bounce removed using capacitor and Schmitt Trigger Inverter with Schmitt Trigger Why is this a bad circuit?

  4. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Hardware De-bouncing • Good hardware de-bounce implementation • Limit instantaneous current to avoid sparks

  8. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing • Flowchart for software code Software de-bounce for button press Software de-bounce for button release

  10. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing for Button Press - Assembly Assembly Code: waitPress ldda PORTT ;wait for press anda #$01 bne waitPress ldd DELAY ;wait 10ms loop decd bne loop rts

  11. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing for Button Press - Assembly C Code: void waitPress(void) { while (PORTT & 0x01); /*wait for press*/ for(i=0; i<DELAY; i++); /* delay */ }

  12. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing for Button Release - Assembly Assembly Code: waitRelease ldaa PORTT anda #$01 beq waitRelease ldd DELAY loop decd bne loop rts

  13. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing for Button Release - Assembly C Code: void waitforrelease(void) { while(!(PORTT & 0x01)); for(i=0; i<DELAY; i++); }

  14. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing • Timing is not very accurate • How can we better code the subroutines? • Use internal timer (TCNT)

  15. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Software De-bouncing • Alternative simple software de-bouncing • Read switch/button until you read the same value twice

  16. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel IO Ports - Inputs • Keypads

  18. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel 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. Set each row output sequentially to output 0 1 1 1 2. Check column inputs to see if key was pressed What if this key is pressed?

  20. ECE 372 – Microcontroller DesignParallel 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. Set each row output sequentially to output 0 1 1 1 1 No key pressed on first row 2. Check column inputs to see if key was pressed 1 1 1

  21. ECE 372 – Microcontroller DesignParallel 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. Set each row output sequentially to output 0 0 1 1 1 No key pressed on first row 2. Check column inputs to see if key was pressed 1 1 1

  22. ECE 372 – Microcontroller DesignParallel 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. Set each row output sequentially to output 0 1 0 1 1 Key press detected in second column 2. Check column inputs to see if key was pressed 0 1 1

  23. ECE 372 – Microcontroller DesignParallel 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. Set each row output sequentially to output 0 1 1 0 1 No key pressed on first row 2. Check column inputs to see if key was pressed 1 1 1

  24. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel 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. ECE 372 – Microcontroller DesignParallel IO Ports - Outputs • Mill Game

  28. 3 Rows ECE 372 – Microcontroller DesignParallel IO Ports - Outputs • Mill Game 8 Columns

More Related