Analog And Digital Interfacing
-
Upload
daniel-sampson -
Category
Documents
-
view
42 -
download
0
description
Transcript of Analog And Digital Interfacing
![Page 1: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/1.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
![Page 2: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/2.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Big Picture
Physical world
MSP430
Analog
Interfaci
ng
Other Systems or
ICs
Digital
Communicatio
n
![Page 3: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/3.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
SensorsA device that converts a physical
phenomenon into an electrical signalPhysical phenomenon
light, temperature, humidity, pressure, and etc.Electrical signal
resistance, capacitance, current, voltage, and etc.
Maps a physical phenomenon change to a electrical signal change
![Page 4: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/4.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Signal Path
Sensors Signal Conditioning
(if necessary)
Convert to voltage
• Amplification• Filtering
• Light• Temperature• Acceleration• Humidity• Pressure• etc.
• Resistance• Capacitance• Current• Voltage• etc.
Analog to Digital
Conversion
(ADC)
10011101
Produce a proper output
voltage level
Converts voltage to
digital number
![Page 5: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/5.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sensors We HaveRaw sensors
Produce raw electrical signal
Signal conditioned sensorsHave some signal conditioning circuitProduce analog output
Mostly Voltage Sometime Current
![Page 6: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/6.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sensors We HaveDigitalized sensors
Have some signal conditioning circuitConvert analog to digital internallyProvide digital output
![Page 7: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/7.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Our Focus
Sensors Signal Conditioning
(if necessary)
Convert to voltage
• Amplification• Filtering
• Light• Temperature• Acceleration• Humidity• Pressure• etc.
• Resistance• Capacitance• Current• Voltage• etc.
Analog to Digital
Conversion
10011101
Produce a proper output
voltage level
Converts voltage to
digital number
Sensors
• We are not going to talk about signal conditioning • You can find many sensors that are signal conditioned and provide a proper analog output, or even digitalized•We will focus on how to understand these signal conditioned sensors and get the output we want
![Page 8: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/8.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Some Raw SensorsTemperature Sensors
Thermistors Temperature-sensitive resistor
RTDs (resistive temperature devices) Temperature-sensitive resistor
Thermocouples Temperature => voltage (mV)
Pressure sensorsPiezoresistive
Resistance change with applied pressure
![Page 9: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/9.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
PhotodiodesLight => current
Generate current proportional to light density
![Page 10: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/10.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
PhotodiodesTwo on Taroko
S1087: for visible rangeS1087-01: for visible to IR(infrared) range
![Page 11: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/11.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Signal Conditioned Analog OutputProximity sensor
Sharp GP2D120XJ00FAnalog voltage output
AccelerometerADXL330 3-axis accelerometerAnalog voltage output
Industry standard analog outputFlow sensors, pressure sensors, gas sensors,
etc.4~20 mA, 0~5 V, 0~10 V
![Page 12: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/12.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Proximity SensorSharp GP2D120XJ00FOutput voltage
proportional to the reflection distance
Measure range: 30 cm
![Page 13: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/13.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
AccelerometerAnalog Device Inc. ADXL330
Output voltage proportional to the acceleration
Measurement range: +/- 3.6 g
![Page 14: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/14.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
GyroInvensense ISZ-500
Z axis gyro, ±500 °/sec2.0 mV/°/sec
Invensense IDG-500X/Y axis gyro, ±500 °/sec2.0 mV/°/sec
Invensense IMU-30003-axis gyro, (±250, ±500, ±1000, ±2000) °/secI2C interface
![Page 15: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/15.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Industry standard analog outputsMany industrial instruments provide analog
outputs4~20 mA current loop
Most commonly usedThe instrument produce a current, range from 4
mA to 20 mAPhysical measured quantity linearly maps to this
current rangeOthers
0 ~ 5 V0 ~ 10 V
![Page 16: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/16.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
4~20 mA current loop Examples
Measure temperature: 0 ~ 100 oC
Measure flow speed: 0 ~ 50 m3/h
Measurements0 oC50 oC100 oC
Current Output4 mA12 mA20 mA
Measurements0 m3/h25 m3/h50 m3/h
Current Output4 mA12 mA20 mA
Usually this range
is user configurab
le
![Page 17: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/17.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
How to Convert to VoltageAdd a resistor
![Page 18: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/18.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Digitalized SensorsUltrasound sensors
SRF10Interface: I2C
Temperature and Humidity SensorSHT11Interface : manufacturer defined
![Page 19: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/19.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Digitalized SensorsMagnetometer
SFE MicroMag 3-AxisInterface : SPIApplications: detecting vehicles
Digital compassHitachi HM55BInterface : UART
![Page 20: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/20.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Digitalized SensorsGPS
Garmin GPS18Interface : UART
Image sensorST VS6451Interface: I2C
![Page 21: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/21.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Understand The Analog SensorsMost important goal
Obtain the relationship between voltage and the physical phenomenon quantity you want to measure Transfer function
Understand the characteristics and limitation of the sensors
![Page 22: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/22.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sensor Characteristics DefinitionsTransfer Function
Relationship between physical quantity and output voltageSensitivity
Ratio of change between physical quantity and output voltage
Accuracy Largest expected error
Linearity How linear the transfer function is
Noise In real world, signal are usually coupled with noise
Resolution minimum detectable signal fluctuation
Bandwidth response times to an instantaneous change in physical
signal
![Page 23: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/23.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Transfer FunctionRatiometric?
Output voltage is a ratio of supply
voltage
Ratiometric?Output voltage is a
ratio of supply voltageADXL330 accelerometer
From ADXL330 datasheet
It means when supply voltage Vs is 3 V, if the acceleration is 0 g, the output voltage will be 1.5 V (typical)
It means when supply voltage Vs is 3 V, if the acceleration increase by 1 g, the output voltage will increase 330 mV (typical)
Transfer function: Voltage (V) = 1.5 + (0.3 * acceleration (g) )
![Page 24: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/24.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Transfer FunctionProximity sensor: Sharp GP2D120XJ00F
Transfer functionVoltage (V) = f(Distance (cm))Not a linear function• Check datasheet
• if the manufacturer has provided
• Table mapping• Approximations
• By a few straight lines• Curve fitting
![Page 25: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/25.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Transfer FunctionPhotodiode: S1087, S1087-01
From Taroko Schematic
Step 1: find the relationship
between light level and current
Step 2: find the relationship
between current and the voltage at
ADC4(V = IR)
Transfer functionVoltage (V) = f(light level(lx))Calculate by yourself
![Page 26: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/26.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
SensitivityADXL330 accelerometer
Sharp GP2D120XJ00FNot a constanst
Photodiode: S1087, S1087-01(Current)/(light level)
![Page 27: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/27.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
LinearityPhotodiode: S1087, S1087-01
ADXL330 accelerometer
Sharp GP2D120XJ00F
GOOD
GOOD
BAD
![Page 28: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/28.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
BandwidthHow fast the next valid output ready
Proximity sensor: Sharp GP2D120XJ00F
ADXL330 accelerometer
When power up, you have to wait for 52.9ms to get a first valid output. You have to wait another 47.9ms to get the second one.
For the module we will use, the filter capacitor is 0.1 uF. It means the accelerometer module can have at most 50 different read-outs in one second
![Page 29: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/29.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Analog to Digital Conversion
Periodically read the voltage of the signalConvert to a digital number
Represent the voltage of the signalAt the sampling time
T
![Page 30: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/30.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Analog to Digital Conversion
![Page 31: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/31.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC takes two inputsVoltage reference (dynamic range)
Range of voltage that it can measure It has a limited range
Sensor signalResolution
How many bits the ADC can outputSample Rate
How many sample it can takes in one secondFor MSP430F1611, it is about 200 ksps
That’s why we need signal conditioning to produce a proper
voltage output
Analog to Digital Converter (ADC)
![Page 32: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/32.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ResolutionYou heard 10-bit ADC, 12-bit ADC, 16-bit
ADCWhat are they?Number of bits the ADC can output
• This is a 4-bit ADC [0,0.1) V -> 0000 [0.1,0.2) V -> 0001 [0.2,0.3) V -> 0010 [1.5,1.6) V -> 1111
• If it is a 6-bit ADC [0,0.025) V -> 000000 [0.025,0.05) V -> 000001 [0.05,0.075) V -> 000010 [1.575,1.6) V -> 111111
![Page 33: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/33.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
1 bit 2 possible values 2 bits 4 possible values 8 bits 256 possible values 12 bits 4096 possible values 16 bits 65356 possible values : : N bits 2N possible values
Discretization
} Quantization error
![Page 34: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/34.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Dynamic RangeRange of signal amplitudes which the ADC
can resolve
Max possible value
Min possible value
![Page 35: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/35.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Voltage reference Input voltage compares to the voltage reference
Ratio of (input voltage)/(voltage reference) determines the output number
Two voltage references Positive voltage reference (Vref+) Negative voltage reference (Vref-)
• In this figure, Vref+ = 1.6V; Vref- = 0 V [0,0.1) V -> 0000 [0.8,0.9) V -> 1000 [1.5,1.6) V -> 1111
• If we change the Vref+ = 3.2V; Vref- remains 0 V, then [0,0.2) V -> 0000 [1.6,1.8) V -> 1000 [3.0,3.2) V -> 1111
![Page 36: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/36.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
About Voltage ReferenceVoltage reference can by internal or external
Many ADCs have internal voltage reference integrated
Unstable Voltage reference will affect the accuracy of the ADC
Minimum, MaximumIf input voltage > Vref+, always output 1111If input voltage < Vref-, always output 0000
Voltage Reference cannot exceed power supply voltage
![Page 37: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/37.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Dynamic RangeToo low
Good resolutionSaturation
Too highPoor resolutionNo saturation
![Page 38: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/38.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Detectable Voltage ChangeVoltage reference + Resolution
Define the detectable voltage changeDetectable voltage change = ((Vref+) –
(Vref-))/(2^resolution)
ExamplesVref = 1.6V, Resolution = 4-bit
Vref = 3.2V, Resolution = 4-bit
Vref = 1.6V, Resolution = 6-bit
1.6/(2^4) = 0.1 V
3.2/(2^4) = 0.2 V
1.6/(2^6) = 0.025 V
![Page 39: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/39.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Sample And Hold
There is a sample-and-hold circuit before A/D conversion
Mostly integrated in the ADC chip When no conversion, switch S1 is open When a conversion start
S1 closed Input signal charge C1 S1 open, C1 holds the value of input
signal A/D conversion
Sample-and-hold time Time between S1 close and re-open If it is too short
C1 will not fully charged (error)
![Page 40: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/40.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC ClockADC needs a clock
For sample-and-hold and the A/D conversion
![Page 41: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/41.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ADC on Taroko12-bit on-chip ADC in MSP430Voltage reference
Internal Vref: 1.5V, 2.5VNo external Vref on TarokoUser configurable combination for Vref+ and
Vref-Sample rate
Approximate 200 kspsUser configurable sample-and-hold timeUser configurable clock sources
![Page 42: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/42.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: ADXL330ADXL330 3-axis accelerometer
Transfer function: V = 1.5 + (0.3 * g)
![Page 43: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/43.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: ADXL330Taroko ADC setting
Resolution: 12-bitVoltage reference
Vref+ = 2.5 V Vref- = 0 V
Conversion formula NADC is the output number
For our setting
refref
refbitnADC VV
VVinN )12(
5.2
)4095(05.2
0)4095(
VinVinN ADC
![Page 44: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/44.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: ADXL330Transfer function: V = 1.5 + (0.3 * g)Conversion formula
When the acceleration is 0 gV = 1.5NADC = 2457When the acceleration is 1.5 gV = 1.95NADC = 3194When NADC = 1784, what is the acceleration?
When NADC = 2635, what is the acceleration?
5.2
)4095(05.2
0)4095(
VinVinN ADC
![Page 45: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/45.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Real World DesignIn practical design, there are always errors
Noises Power supply noise Digital circuit noise RF noise Devices noise
Devices Tolerances 5% resistor, 1% resistor 10% capacitor etc.
Temperature drift Devices characteristics change when temperature change
Two very simple methods to deal with two very common errors
![Page 46: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/46.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
First Type of ErrorsNoise
DynamicADXL330 at 0 g (1.5V)
Sample at S1 -> ok Sample at S2 -> it is 0.333 g Sample at S3 -> it is -0.333 g
SolutionAverage
(S1 + S2 + S3)/3 = (1.5+1.6+1.4)/3 = 1.5
1.5V1.4V
1.6V
S1
S2
S3
![Page 47: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/47.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
How Many SamplesHow many samples needed to average
Depends on your requirementSuggestion: factor of 2 (2N)
Take 10 samples and average
Take 16 samples and average
Total += Si; //(i=1,…,10)Result = Total/10;
Total += Si; //(i=1,…,16)Result = (Total>>4);
Division => slow
Bit shift => fast
![Page 48: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/48.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Cautions! Is the Total large enough to hold the summation
Max possible Total = 4096*16 = 65536 Total should be at least 16-bit unsigned int
IMPORTANT!! int in IAR for MSP430 is 16-bit long
Total += Si; //(i=1,…,16)Result = (Total>>4);
![Page 49: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/49.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Second Type of ErrorsOffset
Static For example: ADXL330
For A accelerometer, 0 g output maybe 1.5V For B accelerometer, 0 g output maybe 1.54V
From ADXL330 datasheet
30% of ADXL330, 0 g output is
1.53V
4% of ADXL330, 0 g output is 1.5V
![Page 50: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/50.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
CalibrationMaintain a calibration constant, adjust the offset
errorADXL330 with calibration
Transfer function: V = (1.5 + Ccal) + (0.3 * g) Ccal is calibration constant
For A accelerometer, 0 g output is 1.5V Ccal = 0
If NADC = 2879, acceleration should be 0.859 g
For B accelerometer, 0 g output is 1.54V Ccal = 0.04
If NADC = 2879, acceleration should be ?? G
![Page 51: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/51.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Calibration ReferenceCalibration needs a reference
Precision of the reference decide the precision of the calibration
How do you calibrate the accelerometer ADXL330??
How do you calibrate a temperature sensor?
Acceleration => voltage
To calibrate, you want to know the voltage output at 0 g. But how to
make 0 g?
You must produce a precise 0 g (or 1 g) acceleration
Temperature => voltage
To calibrate, you want to know the voltage output at
certain temperature (25
oC).
You must produce a precise temperature
![Page 52: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/52.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Digital CommunicationsSending bits between each other
Serial communicationSending bits one by oneUART, SPI, I2C, USB, etc.
Parallel communicationSending multiple bits at one timeEthernet
A B10011101
A B1 0 0 1 1 1 0 1
A B
1
111
1
00
0
Our focus
![Page 53: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/53.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
AgreementsIn order to communicate, two parties must at
least agree on:Logic level
MSP430 RS232 (COM port)
Output data Start, stop Output data valid time (clock)
0V -> logic low (0)
3.3V -> logic high (1)-12V -> logic high
(1)12V -> logic low
(0)
What number it represent?
1 1 1 10 0 0 0Read 1 11 100 00
2x Read
A B
For digital, wired
communication
![Page 54: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/54.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ProtocolsChips to Chips
SPI: Serial Peripheral Interface I2C: Inter Integrated CircuitManufacturer definedUART: Universal Asynchronous Receiver Transmitter
Systems to systems (usually)Define logic level
RS-232: old traditional RS-485: popular in industrial control system
Define output data UART: Universal Asynchronous Receiver Transmitter
Define both USB
A BUAR
TUAR
TRS232
or RS485
RS232 or
RS485
![Page 55: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/55.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
SPIMaster–Slave modeSynchronous protocolAll transmissions are referenced to a common clockClock generated by the master (MCU)Four main signalsMaster Out Slave In (MOSI): data from master to slaveMaster In Slave Out (MISO): data from slave to masterSerial CLocK (SCLK or SCK): clockChip Select (CS): select particular peripheral when
multiple peripherals are connected to master
![Page 56: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/56.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Read data at clock edge
Data Register Exchange Master transfer a byte to slave, push slave to transfer a byte
back to master Master Read and Write
Simultaneously Master write only
Ignore the byte it receive Master read only
Master must transfer a dummy byte in order to initiate a slave transmission
SPI TransmissionMOSI
CLK
Slave read
1 1 1
1
0 0 0 0
MISO
CLK
Master read
1 0 0
0
1 1 0 1
CSCS
![Page 57: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/57.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
I2CTwo wires, multiple devices
SDA (serial data)SCL (serial clock)
I2C transmissionSTART: SDA is pulled low while SCL stays highTransfer:
SDA sets the transferred bit while SCL is low (blue) data is read when SCL rises (green)
STOP: SDA is pulled high while SCL stays high
Pull-up resisto
r
![Page 58: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/58.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
I2CAcknowledge (ACK) and Not Acknowledge
(NACK)Upon the transmission of the eighth data bitTransmitter releases the SDAMaster then generates an additional clock
pulse on SCLTriggers the receiver to acknowledge the byte
by pulling SDA low
![Page 59: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/59.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
I2CAddressing
7-bit addressDirection bit
If 0: master write to slave If 1: master read from slave
10-bit address
Clock stretchingA slave may hold the clock line (SCL) low after
receiving (or sending) a bit, indicating that it is not yet ready to process more data
10-bit address
7-bit address
![Page 60: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/60.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ComparisonSPI I2C
Four wires Two wires
Full duplex Half duplex
Higher throughput (then I2C) Lower throughput
Synchronous protocol Synchronous protocol
No slave acknowledgment Acknowledgment
Simple Complicated
![Page 61: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/61.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Manufacturer Defined ProtocolsThe ideals are similar
Feed a clockStart, stopRead/write the data
Read datasheetMany timesGet use to those timing diagrams
We will use the temperature/humidity sensor SHT11 on Taroko as an example
![Page 62: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/62.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
ImplementationsHow to implement these protocols?
Hardware There are SPI, I2C peripherals on MSP430F1611 You need to properly configure (setting registers) the
modulesSoftware
Use GPIO Generate clock Read data: set the pin to input Write data: set the pin to output
Things to considerTiming: some devices cannot operate too fastCheck devices datasheet
// use P1.0 as clock pinP1SEL &= ~(0x01); // GPIOP1DIR |= 0x01; // output
// clock P1OUT |= 0x01; // high P1OUT &= ~(0x01); // low
// add some delay between clock P1OUT |= 0x01; // high (delay some time) P1OUT &= ~(0x01); // low
![Page 63: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/63.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
In GeneralYou want to interface some digital ICs to MSP430
CC2420 radio chip (SPI)8 Mbit flash memory (SPI)SHT11 sensor (manufacturer defined, similar to
I2C)Typical process
1.How to interface? Connections: two wires, three wires, four wires, etc.
2.How to communicate? Available commands Timing diagram: start, transfer, (ack), stop
3.How to configure the IC Setting the registers on the IC
4.Start reading/writing data from/to the IC
![Page 64: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/64.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: SHT11The temperature/humidity sensor on TarokoHow to Interface
two wires bi-direction
SHT11 datasheet
1. Use a GPIO pin as clock (SCK), it is always output direction
2. Use another GPIO as DATA, dynamic setting it to input(read) or output(write) direction
![Page 65: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/65.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: SHT11How to start
What are the commands available
![Page 66: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/66.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: SHT11Timing diagram
Pull-up
Data pin in output
direction
Set data pin to input direction,
then SHT11 controls the DATA
line
![Page 67: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/67.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
An Example: SHT11Configure device
If you don’t understand what is the meaning, check datasheet
![Page 68: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/68.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
TimingCheck the timing
requirement carefullyThe device won’t
work at all if you exceed the limit
![Page 69: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/69.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
UARTUART: Universal Asynchronous Receiver Transmitter
Two wires: Rx, TxFull duplexAsynchronous
No common clock required
Without common clockHow do they communicate??
ARx
Tx
BTx
Rx
![Page 70: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/70.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Universal data ratesTwo devices agree on same data rate
Baudrate: 1200, 2400, 4800, 9600, …, (bits per second)
A(1 MHz system
clock)
B(8 MHz system
clock)UART
UART
Baudrate
generator
Baudrate
generator
96009600
Baudrate: 9600 bps
Length of a bit = 1/9600 (seconds)
![Page 71: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/71.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
UART DataSend one byte at a timeData
One start bit Pull-down the line
7 or 8 bits data One or two stop bit
Pull-up the line for one or two slotsSimple error checking: parity (optional)
Even parity: If the data has odd number of 1, parity bit = 1 (make it even); else parity bit = 0
Odd parity: If the data has even number of 1, parity bit = 1 (make it odd); else parity bit = 0
Four parameters for UART communication Baudrate, data-bit, parity, stop-bit We wrote: 9600 8N1,
Means: baudrate=9600, 8-bit data, no parity, 1 stop bit
This bit became parity bit when parity checking
is enabled
![Page 72: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/72.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
RS232Since the 1960sCable lengths of up to 25 metersSignal level
logic high -> -5 to -15V (typically -12V)logic low -> +15 and +1V (typically +12V)
Interface Signal Function 25-pin 9-pin Direction
Tx Transmitted data 2 3 From DTE to DCE
Rx Received data 3 2 To DTE from DCE
RTS Request to send 4 7 From DTE to DCE
CTS Clear to send 5 8 To DTE from DCE
DTR Data terminal ready 20 4 From DTE to DCE
DSR Data set ready 6 6 To DTE from DCE
DCD Data carrier detect 8 1 To DTE from DCE
RI Ring indicator 22 9 To DTE from DCE
FGFrame ground (chassis)
1 - Common
SG Signal ground 7 5 Common
![Page 73: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/73.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
RS485Two-wire, half-duplex
Multipoint serial connection
Signal levelDifference between the wires’ voltages
A – B > 0.2V => logic high (0) A – B < -0.2V => logic low (1)
Why it is popular in industrial applicationsOnly two wire35 Mbit/s up to 10 m and 100 kbit/s at 1200 m
![Page 74: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/74.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
USB Serial ICThat’s what we have on Taroko
FT232BL (www.ftdichip.com)To communicate with PCIt simulate a serial communication on PC
through USB interface Virtual com port
![Page 75: Analog And Digital Interfacing](https://reader038.fdocuments.in/reader038/viewer/2022110101/56812fee550346895d956530/html5/thumbnails/75.jpg)
Network and Systems Laboratorynslab.ee.ntu.edu.tw
Applications
MSP430 U
AR
T USB serial
IC (FT232
)
PC or other
systems
RS232 IC
RS485 IC
RS485 IC
Other systems
CO
M
PO
RT
US
B
All you need to do is properly configure UART for both sides
(baudrate, data-bit, parity, stop-bit), and start sending/receiving
data