99
Deqing Sun, Peiqi Su ITP, Fall, 2018 Prototyping Electronic Devices Bus & Signal Processing Class 12

Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Deqing Sun, Peiqi SuITP, Fall, 2018

Prototyping Electronic Devices

Bus & Signal Processing

Class 12

Page 2: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

What is bus

2

Page 3: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Differences between Bus and Cab ?

3

Page 4: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Differences between Bus and Cab Bus is capable to carry many passengers that sharing the same route.

4

Page 5: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 6: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 7: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 8: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 9: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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)

Page 10: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 11: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 12: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 13: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 14: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

USB

14

Page 15: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 16: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 17: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 18: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 19: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

I2C

19

Page 20: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 21: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 22: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 23: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 24: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 25: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 26: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 27: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 28: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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.

Page 29: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

SPI

29

Page 30: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 31: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 32: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

One Wire

32

Page 33: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 34: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

1-wire devicesTemperature sensor

IO breakout

iButtonWidely used as checkpoints in security guard tour system

34

Page 35: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

RS485

35

Page 36: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 37: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 38: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 39: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Quiz

39

Page 40: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Quiz: which bus to use? Scenario: The Penis Wall4 x 4 feet; 81 modules; control each module individually

40

Page 41: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 42: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Quiz: which bus to use? A light bulb?

For power transmission without communication. Bus is not needed.

42

Page 43: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

in-class practicei2C

43

Page 44: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 45: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 46: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Code on Master ArduinoUpload class12/Arduino_i2c_master to Master Arduino

github.com/DeqingSun/Prototyping-Electronic-Devices

46

Page 47: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Code on Slave ArduinoUpload class12/Arduino_i2c_slave to Slave Arduino

github.com/DeqingSun/Prototyping-Electronic-Devices

47

Page 48: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 49: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Signal Processing

49

Page 50: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Signal ProcessingSignal Processing

- Averaging- Hysteresis- Peak detection- Envelope detection

50

Page 51: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 52: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 53: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

When we need it

Pulse sensor:If we know position of each peak, we can calculate heart rate

53

Page 54: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 55: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 56: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

UI explanationGraph of Values View of camera

JS code playground

56

Page 57: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 58: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 59: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 60: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 61: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Algorithm

61

Page 62: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

What if we need a smoother signal?We get a noisy signal, how to clean it?

62

Page 63: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Average Filtering

63

Page 64: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 65: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 66: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 67: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 68: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Live demoTry this code in browser and play with it.

68

Page 69: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 70: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 71: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Try different queue length 5 Mins

71

Page 72: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

What if we need a threshold on a noisy signal

How we void jumping result caused by noise?

72

Page 73: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Hysteresis

73

Page 74: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 75: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 76: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

How to solve the problemUsing 2 different threshold!

76

Page 77: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Live demo

77

Page 78: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 79: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Try bigger and smaller Hysteresis5 Mins

79

Page 80: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

We need heartrate from heartbeat signalHow we know when is heartbeat?

80

Page 81: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Peak detection

81

Page 82: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Peak detectionWhat is a peak:A point higher than previous value and next value.

82

Page 83: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Live demo

83

Page 84: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 85: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Try to modify code to valley detection5 Mins

85

Page 86: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 87: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 88: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 89: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Try “better peak detection”Try the code and change delta.

5 Mins

89

Page 90: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Envelope detection

90

Page 91: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

How we know a person is waving hand?

91

Page 92: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

What is envelopeEnvelope function is a smooth curve outlining its extremes.

92

Page 93: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 94: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 95: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Live demo

95

Page 96: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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

Page 97: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Prototyping Electronic Devices - Class 12 |

Change decrease speed of envelope 5 Mins

97

Page 98: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

Wrap Up

Page 99: Bus & Signal Processing...Bus in electronics Bus is a set of connections shared by multiple hardware components. Signals are dropped off or picked up at every device attached to the

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