Download presentation
Presentation is loading. Please wait.
1
CSCI1600: Embedded and Real Time Software
Lecture 16: Input/Output II Steven Reiss, Fall 2016
2
Simon Game Tasks Detect buttons Initialize Reset
Periodically (every 10 ms) check 3 sets of buttons Set flags indicating on for > 20 ms Initialize Based on selected game flag Set up play array play[32], play_length Set up state time, play time Reset If start is ever pressed, go back to initialization state Lecture 16: Input/Output II 12/6/2018
3
Simon Game Tasks Game Task
Alternate between play and read More sophisticated for 2 player Play: incr ctr, play current sequence through counter Handle illegal inputs Set light and sound variable accordingly Increment counter every k ms Reset counter when done, enter read Read: incr ctr, read input for current sequence element Time out (> k sec in state) go to error Input matches loop back Input doesn’t match go to lose state ctr == length, go to play state with next element or to win state Lecture 16: Input/Output II 12/6/2018
4
Simon Game Tasks Win/Lose task Play sound task (run every 1/8 ms)
Choose sequence based on win/lose Play that sequence Afterwards go to start state Play sound task (run every 1/8 ms) Based on sound variable Set output at proper frequency Lights task Set light based on light variable Lecture 16: Input/Output II 12/6/2018
5
Simon Tasks What do the models for these tasks look like
What will the code look like The code should reflect the models The models should reflect the code Lecture 16: Input/Output II 12/6/2018
6
Input Management We can attach inputs to the Arduino
Directly or indirectly What are the problems Sampling Latency Conditioning Range, sensitivity, noise Lecture 16: Input/Output II 12/6/2018
7
A simple switch You want to read the switch
Can’t do it continually – you need to sample How fast should you sample? What does this depend upon? Minimum On time Minimum Off time Bouncing Lecture 16: Input/Output II 12/6/2018
8
Switch Input Ideal Switch Minimum inter-event sampling time
Assume min on-time is 2 units Assume min off-time is 1 units What is the minimum sampling rate What is a safe sampling rate Minimum inter-event sampling time Might need to compute these values How to check min on time given sampling rate Lecture 16: Input/Output II 12/6/2018
9
Switch Input Real switches bounce
Input takes some time to stablize Possibly ms What happens if you sample faster than that Debouncing Sample > 50 ms Condition the inputs Check it is on/off for at least k samples Lecture 16: Input/Output II 12/6/2018
10
Input Issues Pull-Up Set Arduino switch mode
Lecture 16: Input/Output II 12/6/2018
11
Sampling Actual Signals
Actual signals are continuous Digital inputs are discrete Certain number of values This determines the accuracy of your input Sensors have different response curves Lecture 16: Input/Output II 12/6/2018
12
Actual Signals Microphone Thermistor Light Sensitive Diode
Lecture 16: Input/Output II 12/6/2018
13
Response Curves Different devices react differently
Can be linear, log, … Can saturate Lecture 16: Input/Output II 12/6/2018
14
Response Curves May be other Specific to the device
Lecture 16: Input/Output II 12/6/2018
15
Sampling Changing Inputs
Suppose we sample audio How fast should we sample? Need to avoid aliasing Need to be > 2 times the maximum input frequency What is audio range? What is a CD range? Lecture 16: Input/Output II 12/6/2018
16
Aliasing Suppose there is a high-frequency component to the input
What would this show up as in low-frequency sampling? Need for a low-pass (anti-aliasing) filter Can be done in software (if you sample fast enough) Very easy to do in hardware (capacitor and resistor) Lecture 16: Input/Output II 12/6/2018
17
Low Pass Filter Lecture 16: Input/Output II 12/6/2018
18
Low Pass Filter Lecture 16: Input/Output II 12/6/2018
19
Analog Signals Include Noise Need to know S/N ratio
Input should take this into account Lecture 16: Input/Output II 12/6/2018
20
Input Issues: Analog to Digital
Analog signals are continuous, digital discrete Digital signal Set of bits (8, 12, …) Binary value represents the voltage level Lecture 16: Input/Output II 12/6/2018
21
Analog-Digital Conversion
Range Highest and lowest possible values (0 .. 7, ) Precision Number of bits (0..255, , …) This is all you can tell apart Sampling Rate How fast the ADC can sample (it’s not immediate) Samples per second Lecture 16: Input/Output II 12/6/2018
22
How a ADC works Successive approximation Controller guesses next value
DAC converts guess to analog value Comparator sees compares input and reference value Controller takes result and makes next guess Lecture 16: Input/Output II 12/6/2018
23
Analog to Digital Lecture 16: Input/Output II 12/6/2018
24
Input Arrays Does this work? What can go wrong
Lecture 16: Input/Output II 12/6/2018
25
Input Array Issues First note that if no switch is pressed, noting is connected to the input ports – might get random values. Hence diagram 2 Second note what happends if switches 3,5,6 are pressed – it will look like 2,3,5,6 are all on. Hence the use of diodes as in second figure Lecture 16: Input/Output II 12/6/2018
26
Input Array Issues In the second case the pins serve double duty depending on their polarity. 4 pins used for 12 switches What happens with multiple switches on the first example. R1*R1/(R1+R2). What type of precision would you need on the analog input for 8 switches. What about pair-wise? Lecture 16: Input/Output II 12/6/2018
27
Latency Difference in time between input and corresponding output
What if user pushes switch for his TTT move The machine does computation to determine its move Then it turns on both lights Would this work? Difference between setting output and actual output Motor won’t react immediately Lecture 16: Input/Output II 12/6/2018
28
Acceptable Latency Reaction should be << 100 ms
100 ms is noticeable How is latency affected by conditioning Filtering, waiting for stability, eliminating noise How does this affect the sampling rate When latency is important Processing sound, other multimedia Detecting events (button presses, mouse movement, …) Lecture 16: Input/Output II 12/6/2018
29
Other I/O Issues To be covered later Communications between components
Serial I/O and timing Handshaking Protocols Lecture 16: Input/Output II 12/6/2018
30
Homework Read Chapters 8.2 and 9 Exercises 8.3, 9.2, 9.3
Other parts of 8 might be interesting (not covered) Exercises 8.3, 9.2, 9.3 Lecture 16: Input/Output II 12/6/2018
31
Output Array This lecture might be short. Lecture 16: Input/Output II
12/6/2018
32
Output Array Alternatives
First is shift register with serial input Second is latch register with parallel input Lecture 16: Input/Output II 12/6/2018
33
Output Issues: Glitches
Intermediate values Output glitches Arduino library minimizes these Lecture 16: Input/Output II 12/6/2018
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.