1 ece 372 – microcontroller design parallel io ports - inputs

28
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

Upload: jean-floyd

Post on 05-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

1

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

Page 2: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

2

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: Some expensive switches do not bounce We can debounce switches with hardware We can debounce switches with software

Page 3: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 4: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 5: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 6: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 7: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

7

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

Hardware De-bouncing Good hardware de-bounce implementation

Limit instantaneous current to avoid sparks

Page 8: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 9: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 10: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

10

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

Software De-bouncing for Button Press - Assembly

waitPress ldda PORTT ;wait for press

anda #$01

bne waitPress

ldd DELAY ;wait 10ms

loop decd

bne loop

rts

Assembly Code:

Page 11: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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:

Page 12: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

loop decd

bne loop

rts

Assembly Code:

Page 13: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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:

Page 14: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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)

Page 15: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 16: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 17: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

17

ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

Keypads

Page 18: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 19: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

0111

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?

Page 20: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

0111

1. Set each row output sequentially to output 0

2. Check column inputs to see if key was pressed

1111

No key pressed on

first row

Page 21: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

1011

1. Set each row output sequentially to output 0

2. Check column inputs to see if key was pressed

1111

No key pressed on

first row

Page 22: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

1101

1. Set each row output sequentially to output 0

2. Check column inputs to see if key was pressed

1011

Key press detected in second column

Page 23: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

1110

1. Set each row output sequentially to output 0

2. Check column inputs to see if key was pressed

1111

No key pressed on

first row

Page 24: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 25: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 26: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

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

Page 27: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

27

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs

Mill Game

Page 28: 1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs

28

ECE 372 – Microcontroller Design Parallel IO Ports - Outputs

Mill Game

3 Rows8 Columns