Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Deqing Sun, Peiqi SuITP, Fall, 2018
Prototyping Electronic Devices
Bus & Signal Processing
Class 12
What is bus
2
Prototyping Electronic Devices - Class 12 |
Differences between Bus and Cab ?
3
Prototyping Electronic Devices - Class 12 |
Differences between Bus and Cab Bus is capable to carry many passengers that sharing the same route.
4
Prototyping Electronic Devices - Class 12 |
In electronicsHow to connect different devices so that they can communicate with each other?
5
“Cab” Concept “Bus” Concept
DeviceA
DeviceB
DeviceC
DeviceD
DeviceA
DeviceB
DeviceC
DeviceD
Prototyping Electronic Devices - Class 12 |
Bus in electronicsBus is a set of connections shared by multiple hardware components.
Signals are dropped off or picked up at every device attached to the bus.
What’s the advantage to use bus?
6
“Cab” Concept “Bus” Concept
Prototyping Electronic Devices - Class 12 |
Advantage of BusThe purpose of buses is to reduce connections between components. It carries out all communications over a single data channel.
7
“Cab” Concept “Bus” Concept
Prototyping Electronic Devices - Class 12 |
Parallel bus and Serial busBuses can be divided into two types:
● Parallel:Conveying multiple binary digits (bits), simultaneously
● Serial:Sending data one bit at a time, sequentially
8
Prototyping Electronic Devices - Class 12 |
Examples of serial and parallel interface
Flag semaphoreParallel. Multiple bits at same time(two flags with various position)
9
Morse codeSerial. One bit at a time (either on or off)
Prototyping Electronic Devices - Class 12 |
Serial/Parallel Hard drivesHard drive buses shifted from Parallel (left) to Serial (right) since 2003.
Serial bus has 2 main advantages
● Fewer wires (Very useful)
● Faster clock speed capability
10
Prototyping Electronic Devices - Class 12 |
Parallel Bus is rare todayDue to the complexity in connection, parallel bus is rarely used today.
Memory module is one of the few hardware still using parallel bus.
As we won’t use it, we won’t talk much about it in this class.
11
Prototyping Electronic Devices - Class 12 |
Common serial buses in ITP projectsSynchronous● I2C - 2 wires● SPI - 3 wires+1 slave select for each device (e.g. 4 wires for one device, 5 for 2)
Asynchronous● RS-485 - 2 wires● 1-Wire - 1 wire
12
Prototyping Electronic Devices - Class 12 |
Diff. between synchronous and asynchronousWhether the interface uses a clock line to synchronize signal.
Asynchronous interface sends data at certain rate. Receiver needs to count time by itself.
Synchronous interface has a clock line that inform receiver when to receive a new bit.
What if sender freezes for a while? 13
USB
14
Prototyping Electronic Devices - Class 12 |
USB’s advantage
USB can supply some power
USB is robust
USB support hub
USB is supported by a lot of devices
15
Prototyping Electronic Devices - Class 12 |
Extend USBExtend USB with repeater:
This type of USB extension cord has a hub on it’s female end. It decode signal and encode again to fix distortion in transmission.
Limited Length, High reliability, High speed.
16
Prototyping Electronic Devices - Class 12 |
Extend USBExtend USB with ethernet cable:
This pair of adaptor convert USB signal on Ethernet cable and back. You can use a long cable for connection.
Longer Length, Lower reliability, Low speed.
Arduino, thermal printer, etc OKWebcam, Kinect, Storage, etc, NOT OK
17
Prototyping Electronic Devices - Class 12 |
Lesson we learned from USB extensionWe used non-shield ethernet 30ft cable to extend USB from computer to control circuit. Everything works well until show starts. Frequent disconnections happens.
Using shielded cable will be more reliable, especially in space filled with radio noise like trade shows.
18
I2C
19
Prototyping Electronic Devices - Class 12 |
What is I2CThe Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips.
It uses 2 wires. Normally we only have one master and Microcontroller will take that role.
It requires pull-up resistors.20
Prototyping Electronic Devices - Class 12 |
Pull-up & Pull-up resistorWhen you use a button and connect the button between input Pin and GND, you need to add a resistor between input Pin and VCC, to pull input Pin level to VCC.
Such resistor is called Pull-up resistor.
21
Prototyping Electronic Devices - Class 12 |
How I2C worksMaster sends out clock and address of a slave device.If there is a slave device with matching address, it will respond and all other slave devices will keep silent.Arduino's Wire Library handles all lower level work.
22
Prototyping Electronic Devices - Class 12 |
Address of slave deviceThe Wire library uses 7 bit addresses.The addresses from 0 to 7 are not used because they are reserved.So, there are addresses are available. 128-8=120
As long as slave devices have different address, there will be no conflict.
23
Prototyping Electronic Devices - Class 12 |
Address of slave device is not arbitraryWhen you get a I2C chip. Manufacturer usually already pre-programmed its slave address.
Some chips may let you change the last few bits of its address, but you can not change all bits of it.
If you are using a microcontroller as slave, you may change the whole address.
24
Prototyping Electronic Devices - Class 12 |
Figure out the slave addressLet’s say we like this LED matrix from adafruit.
It has a controller called HT16K33.
We open it’s datasheet.
25
Prototyping Electronic Devices - Class 12 |
Address of HT16K33The address is (binary) 1 1 1 0 A2 A1 A0And A2, A1, A0 is configurable. If one pin is unconnected, the corresponding bit will be zero.
For example, If we only connect A1, The devices address will be 1110010=0x72
Quiz: if A0 and A2 are connected, the address?1110101=0x75
26
Prototyping Electronic Devices - Class 12 |
Pads for address configurationThese 3 pad are used for configuration. You can bridge them to change address.
Quiz: How should we set address to 0x74 (1110100)?Bridge A2 pad only
Quiz: In the same I2C bus, how many HT16K33 can I connect?8 (000,001,010,011,100,101,110,111)
27
Prototyping Electronic Devices - Class 12 |
A common I2C device: EEPROM
28
EDID EEPROM, describes monitor’s parameters in VGA, DVI and HDMI
SPD EEPROM, describes memory module’s size, type and speed, etc.
Simple IC card, used to keep non-critical simple data. Used in early laundry system, etc.
SPI
29
Prototyping Electronic Devices - Class 12 |
SPI connectionSPI uses separate connections for sending and receiving data.
Each slave has own slave select.
SPI device doesn’t have address.
30
Prototyping Electronic Devices - Class 12 |
Compare to I2CSPI has separate input and output lines.SPI don’t need to send address.SPI is faster and used on BLE module and SD cards.
Due to the complexity of wiring (at least 4 vs 2), SPI is not as common as I2C.
31
One Wire
32
Prototyping Electronic Devices - Class 12 |
1-Wire1-Wire is an interesting bus that only use one wire. For low power application, even power wire can be removed by using data line to provide power.
Each 1-wire device has been programmed with a unique ID. Master device can perform a search algorithm to find all available devices on bus.
33
Prototyping Electronic Devices - Class 12 |
1-wire devicesTemperature sensor
IO breakout
iButtonWidely used as checkpoints in security guard tour system
34
RS485
35
Prototyping Electronic Devices - Class 12 |
Rs485RS485 is a type serial communication, but it uses a pair of wires to send one signal.
You can use a transceiver to translate serial on Arduino to and from RS485.
36
Prototyping Electronic Devices - Class 12 |
Why do we need RS485RS485 use twisted wire pair to transmit data.
If you do wiring in industrial standard level, RS485 can go up to 4000ft (1200m)
37
Prototyping Electronic Devices - Class 12 |
Where we should use RS485If you need to send data in a long distance, RS485 is a good choice.
In public theater, we used RS485 to transfer data from main controller to LED displays.
38
Quiz
39
Prototyping Electronic Devices - Class 12 |
Quiz: which bus to use? Scenario: The Penis Wall4 x 4 feet; 81 modules; control each module individually
40
Prototyping Electronic Devices - Class 12 |
Quiz: which bus to use? Scenario: The Bay Lights1.8 miles (2.9 km) of the cables; 25,000 individual white LEDs; control each LED individually
41
Prototyping Electronic Devices - Class 12 |
Quiz: which bus to use? A light bulb?
For power transmission without communication. Bus is not needed.
42
in-class practicei2C
43
Prototyping Electronic Devices - Class 12 |
What will we doWe will connect 2 Arduino with i2c.
The master Arduino will send a value to slave Arduino to control the onboard LED, and read analog value on A0 from slave Arduino.
44
Prototyping Electronic Devices - Class 12 |
Connect 2 ArduinoConnect 5V, GND, SCL and SDA ports.
On Arduino Uno:
SCL is on A5SDA is on A4
45
Arduino_i2c_master.ino Arduino_i2c_slave.ino
USB to computer
Prototyping Electronic Devices - Class 12 |
Code on Master ArduinoUpload class12/Arduino_i2c_master to Master Arduino
github.com/DeqingSun/Prototyping-Electronic-Devices
46
Prototyping Electronic Devices - Class 12 |
Code on Slave ArduinoUpload class12/Arduino_i2c_slave to Slave Arduino
github.com/DeqingSun/Prototyping-Electronic-Devices
47
Prototyping Electronic Devices - Class 12 |
What to observeAfter uploading code to slave Arduino, connect USB to master Arduino. Open Serial monitor.
How the LED on slave blinks? How you change the blinking timing?
Try to connect A0 of slave Arduino to 5V or GND. What you see?
If you finish the experiment, how you connect 2 slave Arduino to one master one?
48
Signal Processing
49
Prototyping Electronic Devices - Class 12 |
Signal ProcessingSignal Processing
- Averaging- Hysteresis- Peak detection- Envelope detection
50
Prototyping Electronic Devices - Class 12 |
Why we need signal processing?When getting signals from physical world, we get some noisy signal.
For example, you read a sensor value or do computer vision and get location.You can do signal processing to clean signal or extract feature from signal.
51
Prototyping Electronic Devices - Class 12 |
When we need it
FSR sensor:Noise affects ON/OFF triggering, we don’t want false trigger caused by noise.
52
Prototyping Electronic Devices - Class 12 |
When we need it
Pulse sensor:If we know position of each peak, we can calculate heart rate
53
Prototyping Electronic Devices - Class 12 |
When we need it
Kinect:We want to know whether user waved his hand.The position of hand can be seen as an input signal.We know X,Y position of hand. What kind of change in hand position can be defined as waving?
54
Prototyping Electronic Devices - Class 12 |
Platform we usedeqingsun.github.io/Javascript-Signal-Processing/
Short link: bit.do/signalprocessing
Open this link on phone
Open this link on Laptop
55
Prototyping Electronic Devices - Class 12 |
UI explanationGraph of Values View of camera
JS code playground
56
Prototyping Electronic Devices - Class 12 |
Camera viewIn camera view, it’s looking for a magenta object in its view.You should see a green rectangle around your phone.Your phone’s vertical position will be used as input, copied to global variable “value_input”
57
Prototyping Electronic Devices - Class 12 |
Graph of valuesglobal variable “value_input” is drawn in Red
global variable “value_output” is drawn in Blue
Now Red and blue is overlapping.
Value 0~255
Time0
255
58
Prototyping Electronic Devices - Class 12 |
Code PlaygroundThis is the place you can write code to do signal processing. Code in this box will be executed every frame.
After finishing coding, click “Apply code”. If there is no syntax error, your code will be applied to graph. Otherwise you will see the error message.
Try to type:value_output=255-value_input;
59
Prototyping Electronic Devices - Class 12 |
Use a new variableIn Javascript if we read a variable before we create it, we will get an error.
if(typeof new_var === 'undefined'){ new_var=0;};
Is this variable not created yet?
Create a variable and assign a new value
60
Algorithm
61
Prototyping Electronic Devices - Class 12 |
What if we need a smoother signal?We get a noisy signal, how to clean it?
62
Average Filtering
63
Prototyping Electronic Devices - Class 12 |
Average
Let refresh what is averaging. We basically add a few values together and divide the sum with count of the values.
64
Prototyping Electronic Devices - Class 12 |
Average Filtering (smoothing)To smooth of a signal, we don’t average all data points.
We take each sample points and average them with a few values before it.
The spikes are suppressed and the signal become much more smooth.
65
Prototyping Electronic Devices - Class 12 |
How to average a streaming signalWe store N recent values and calculate their average.
We can create a queue of certain length to store recent data points from stream. New data will be added and old data will be discarded.
66
Prototyping Electronic Devices - Class 12 |
Use ring buffer to keep dataIn real application, shift values in array may takes a long time.
We can treat an array as ring buffer. New data will overwrite old data automatically.
67
Prototyping Electronic Devices - Class 12 |
Live demoTry this code in browser and play with it.
68
Prototyping Electronic Devices - Class 12 |
Code//average filtering
if(typeof data_filter === 'undefined'){ //We need to initialize variable before we use them
data_filter=[0,0,0,0,0,0,0,0];
};
if(typeof data_pointer === 'undefined'){
data_pointer=0;
};
data_filter[data_pointer]=value_input; //store previous values into array
data_pointer++;
if (data_pointer==8) data_pointer=0;
sum=0;
for (i=0;i<8;i++){ //get average value from array
sum+=data_filter[i];
}
value_output=sum/8;
69
Prototyping Electronic Devices - Class 12 |
Trade off of queue length
Too short: not enough to smooth noise (demo)Too long: desired signal will be smoothed (demo)
You may want to do some experiment on how long queue you are going to use.
if(typeof data_filter === 'undefined'){ //We need to
initialize variable before we use them
data_filter=[0,0,0,0,0,0,0,0];
};
if (data_pointer==8) data_pointer=0;
70
Prototyping Electronic Devices - Class 12 |
Try different queue length 5 Mins
71
Prototyping Electronic Devices - Class 12 |
What if we need a threshold on a noisy signal
How we void jumping result caused by noise?
72
Hysteresis
73
Prototyping Electronic Devices - Class 12 |
Hysteresis in comparatorWhen trying to convert a signal to boolean values, we may get unwanted transition due to noisy signal.
74
Prototyping Electronic Devices - Class 12 |
Live demo of a simple comparatorNoise introduces glitches.
//Direct Comparison
if (value_input>(128)){
value_output=255;
}else{
value_output=0;
}
75
Prototyping Electronic Devices - Class 12 |
How to solve the problemUsing 2 different threshold!
76
Prototyping Electronic Devices - Class 12 |
Live demo
77
Prototyping Electronic Devices - Class 12 |
Code to do thresholdif(typeof value_was_above_threshold ===
'undefined'){ //We need to initialize
variable before we use them
value_was_above_threshold=false;
};
if (value_was_above_threshold){
value_threshold=128-5;
}else{
value_threshold=128+5;
}
if (value_input>value_threshold){
value_was_above_threshold=true;
}else{
value_was_above_threshold=false;
}
if (value_was_above_threshold){
value_output=255;
}else{
value_output=0;
}
78
Prototyping Electronic Devices - Class 12 |
Try bigger and smaller Hysteresis5 Mins
79
Prototyping Electronic Devices - Class 12 |
We need heartrate from heartbeat signalHow we know when is heartbeat?
80
Peak detection
81
Prototyping Electronic Devices - Class 12 |
Peak detectionWhat is a peak:A point higher than previous value and next value.
82
Prototyping Electronic Devices - Class 12 |
Live demo
83
Prototyping Electronic Devices - Class 12 |
Code to do peak detection (Simple)if(typeof previous_frame_data === 'undefined'){ //We need to initialize variable before we use
them
previous_frame_data=0;
};
if(typeof two_frame_ago_data === 'undefined'){ //We need to initialize variable before we use them
two_frame_ago_data=0;
};
if (value_input<previous_frame_data && two_frame_ago_data<previous_frame_data){ //the Y axis is
pointing downward this this example
value_output=255;
}else{
value_output=0;
}
two_frame_ago_data=previous_frame_data; //push new data and discard old ones.
previous_frame_data=value_input; 84
Prototyping Electronic Devices - Class 12 |
Try to modify code to valley detection5 Mins
85
Prototyping Electronic Devices - Class 12 |
Improved Peak DetectionYou may miss some peaks if you just compare 3 points.
A better way to do peak detection is to check if signal has changed its trend.
86
Prototyping Electronic Devices - Class 12 |
Improved Peak DetectionWhen algorithm is looking for peak, it will record highest value since last valley point. Once current value is lower than highest value by delta, then we found a peak.
Then we look for valley in opposite way until we find it
Looking for Peak
Looking for Valley
Signal decreased from highest point by delta
Signal increased from lowest point by delta
87
Prototyping Electronic Devices - Class 12 |
Adjust sensitivity of algorithmYou can change delta to change sensitivity of the algorithm
A bigger delta will be more resistant to noise, at the cost of latency.
Delta = 3
Delta = 30
88
Prototyping Electronic Devices - Class 12 |
Try “better peak detection”Try the code and change delta.
5 Mins
89
Envelope detection
90
Prototyping Electronic Devices - Class 12 |
How we know a person is waving hand?
91
Prototyping Electronic Devices - Class 12 |
What is envelopeEnvelope function is a smooth curve outlining its extremes.
92
Prototyping Electronic Devices - Class 12 |
Hand movement and EnvelopeIf you hand hold still and them move up and down, the difference of upper and lower envelope will increase.
So you can use difference of upper and lower envelope to figure out if you hand is waving or still.
Upper Envelope
Lower Envelope
93
Prototyping Electronic Devices - Class 12 |
Envelope detectionWhen we want to know the range of a changing signal we can detect it’s envelop to determine it.
We have a slowly decreasing value, but it will go up to signal value if it is smaller than signal
94
Prototyping Electronic Devices - Class 12 |
Live demo
95
Prototyping Electronic Devices - Class 12 |
Code to do Envelop detection//envelop detection lower
if (value_input<value_output){
value_output=value_input;
}else{
value_output+=0.5;
}
//envelop detection upper
if (value_input>value_output2){
value_output2=value_input;
}else{
value_output2-=0.5;
}96
Prototyping Electronic Devices - Class 12 |
Change decrease speed of envelope 5 Mins
97
Wrap Up
Prototyping Electronic Devices - Class 12 |
Next classWe will discuss:● Design a case for PCB● Bluetooth low energy
Please bring:A Computer with Chrome installedA iOS device supports BLE and you can install app
99