SEP600
Embedded System
Module 3: Digital I/O and Analog Ouput
Course Outline
Module 1: Introduction and Review
Module 2: Transistor and Op-Amp
Module 3: Digital I/O and Analog Output
Module 4: Analog Input, Resolution, and Sampling
Module 5: RTOS and Multithreading
Module 6: Serial, SPI, I2C, CAN
2
Digital Input and Output (I/O)
●
most newer micro-controller use 3.3V as
the logic voltage, some older ones use 5V
logic
●
logic HIGH (1) is usually defined as above
70% of Vs
●
logic LOW (0) is usually defined as below
30% of Vs
Source: Toulson Fig 3.1
3
Digital Output
HIGH/LOW signal output from a microcontroller.
Source: Toulson Fig 3.3-3.4
Example: to turn on an LED using digital output, the digital output need to
be HIGH if the LED is connected to ground OR the digital output need to be
LOW if the LED is connected to Vs
4
Digital Input
Signal to be read by a microcontroller as HIGH/LOW.
Source: Toulson Fig 3.5
For digital input, using a single-pole double-throw (A) without a resistor is
not preferred. Use a pull-up (B) or pull-down (C) circuit with a resistor as a
precautionary measure.
5
General Purpose I/O (GPIO)
Configurable pins that can be used to send data into and out
of the microcontroller board
●
Modes of Operation:
– Digital Input (High Impedance)
●
Internal Pull-up/down usually available
– Digital output (Usually ~50mA max)
●
Don’t short it directly to ground
– Analog functions (ie. DAC, ADC)
– Alternate functions (ie. I2C, UART)
6
PWM: Pulse Width Modulation
Is it Digital Output or Analog Output?
●
rectangular pulse wave
●
duty cycle control average
●
very high frequency
●
about 90% efficiency
pulse on time t
D=duty cycle= ∗100 %= on ∗100 %
pulse period T
Source: Toulson Fig 4.6
7
PWM with RC Smoothing
If the PWM frequency is well
above the RC cutoff
frequency (the PWM period
is much smaller then the RC
RC Output
time constant), the RC
output will become a
smooth signal
pulse on time t
D=duty cycle= ∗100 %= on ∗100 %
pulse period T
8
Example
Find tON and VAVG for a VS = 3.3V PWM signal operating at
20kHz and at 25% duty cycle.
9
Example
Find tON and VAVG for a VS = 3.3V PWM signal operating at
20kHz and at 25% duty cycle.
1 1
T= = =50 μ s
f 20 kHz
t ON=T × D=50 μ s×25 %=12.5 μ s
V AVG =V S× D=3.3 V×25 %=0.825 V
10
PWM Applications
Servo Control Buzzer
●
20ms period (50Hz) ●
Note A: 440 Hz, etc.
Source: Toulson Fig 4.12
LED Dimming
Source: Toulson Fig 4.9 Motor Control
11
FRDM-K64K PWM
●
12x PWM
12
Digital-to-Analog Converter (DAC)
Circuitry that convert binary input (0s and 1s) into an analog
voltage output (Vo)
0001
0010
0100
0100
0011
0101
...
Source: Toulson Fig 4.1 Source: Toulson Fig 4.3
13
Digital-to-Analog Converter (DAC)
●
Digital value is stored in a register used for conversion
– During of conversion is called settling time
●
Output of DAC remains the same until the next level is
updated to the register (zero-order hold)
n−1 n−2 1 0 Vr
V o =(b n−1 2 +b n−2 2 +...+b 1 2 +b 0 2 ) n
2
Vr b – bit
D
V o= n V r resolution= n
D – digital value
2 2 Vr – voltage reference
Source: Toulson Fig 4.2
14
String DAC
●
Fast, but requires large number of
resistors and switches (one for
each quantization level)
●
Widely used in simple DAC
●
Requires:
– Accurate reference voltage
– A resistor and switch for every level
15
Weighted Resistor DAC
●
Summing amplifier circuit
●
Fast, but for high bit-count, it
require high precision resistors
across a wide magnitude range
●
Virtual ground at op-amp input
●
Requires:
– Accurate reference voltage
– High precision resistors
16
R/2R Ladder DAC
●
Modified summing amplifier circuit
●
Uses just two resistance values (2R and R)
●
Input switches define a specific resistor divider network
17
To Analyze: Apply Superposition
●
Example: set b3b2b1b0 = 0001 (b0 connected to op-amp, others are grounded)
2 R∥2 R 1
V 0= V 1= V 1
( R +2 R∥2 R) 2
2 R∥( R+2 R∥2 R) 1
V 1= V 2= V 2
( R+2 R∥2 R) 2
2 R∥( R+2 R∥( R+2 R∥2 R)) 1
1 1
⇒ V 0= V 3= V S
8 8
⇒ V out =−
R
2R
V 0 =− ( )
1 1
2 8
1
V S =− V S
16
V 2= V 3= V 3
(R +2 R∥2 R ) 2
18
To Analyze: Apply Superposition
1
(V out )0001 =− V
16 S
1
(V out )0010 =− V S
8
1
(V out )0100 =− V S
4
1
(V out )1000 =− V S
2
The output to any combination of binary numbers is:
V out =b3 (V out )1000 +b 2 (V out )0100 +b 1 (V out )0010 +b 0 (V out )0001
19
R/2R Ladder DAC
●
VS can be set as negative to produce a positive output
voltage range
– Only unipolar (either positive or negative, not both) output can
be achieved
●
Bipolar output can be obtained by replacing all ground
values in the circuit with a reference voltage of opposite
sign to VS
20
Example
If VS is 10V, find the maximum Vout then find Vout if the binary
input is b3b2b1b0 = 1001
21
Example
If VS is 10V, find the maximum Vout, resolution, then find Vout
if the binary input is b3b2b1b0 = 1001
1 1 1 1 15
(V out )1111 =− + + + V S = (10 V )=9.375 V
2 4 8 16 16
1 1 9
(V out )1001 =− + V S = (10 V )=5.625 V
2 16 16
VS 10 V
resolution= n = 4 =0.625 V
2 2
22
Issues with DAC
●
Dependency on the reference voltage
●
Many precision resistors are necessary
– change or inaccuracies in the resistors from manufacturing
error or drifting due to temperature change can affect output
●
Wasted energy dissipated as heat in resistive circuit
23
FRDM-K64K DAC
●
12-bit DAC
24
Course Outline
Module 1: Introduction and Review
Module 2: Transistor and Op-Amp
Module 3: Digital I/O and Analog Output
Module 4: Analog Input, Resolution, and Sampling
Module 5: RTOS and Multithreading
Module 6: Serial, SPI, I2C, CAN
25