Download presentation
Presentation is loading. Please wait.
1
Robocon 2007 Electronics Quickstart!
Session 3 Switch Reading & State Prepared by KI Chi Keung [chikeung@ust.hk] WONG Long Sing (Sam) [sam@hellosam.net]
2
Today’s Timeline Reading a button State Debouncing
Level / Edge Detection State Edge Detection Finite State Machine
3
Bouncing Switch takes a while to settle down 5V 0V ~1ms Point of time
when user press the button
4
Hardware Debouncing By using a capacitor 5V 0V ~1ms Point of time
when user press the button
5
Software Debouncing By using delay 5V 0V
Ignore the pin reading for some time after being triggered 5V 0V ~1ms Point of time when user press the button
6
Software Debouncing Human cannot press switch at 1kHz anyway (Or the switch will probably break) Read less frequently, 20Hz may be a good choice. Time of sampling 5V 0V ~1ms Point of time when user press the button
7
Level Detection With simple if-then code, you get level detection.
Events Clock 5V High Level 0V Low Level
8
Edge Detection But most of the time you want to do edge detection.
Falling Edge Events Clock 5V 0V Rising Edge Falling Edge
9
Task Description Change the LED status once when the button is pushed.
Can be solved in two ways Simple Edge Detection Finite State Machine
10
Simple Edge Detection Save the previous state
Compare with current state Profit!
11
Finite State Machine To facilitate edge detection, you need state machine.
12
Finite State Machine Less state is good. Let’s simplify it.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.