Lecture13 PWM ADC DAC
Lecture13 PWM ADC DAC
Lecture13 PWM ADC DAC
Topics
Pulse Width Modulation
Analog to Digital Converter
Digital to Analog Converter
2
Pulse Width Modulation
• A digital signal can be only 0 volt (logical 0) or 5 volt (logical 1).
• But an analog signal can be any value between 0 and 5 volts.
• Pulse Width Modulation (PWM) is a simulation method for
getting analog output results by using digital output signals.
• PWM can be implemented by hardware (PWM circuit) or by software.
• Digital signals are square waves that are switched between ON and OFF.
• ON/OFF operations can simulate intermediate voltages between
0 volts and 5 volts.
• The PWM program changes (modulates) the portion of the "ON time"
duration and "OFF time" duration in a loop.
• The duration of "ON time" is called the Duty Cycle (Pulse Width).
• To get varying analog output results, the pulse width is changed
repeatedly in a loop.
4
Duty Cycle Duration
• The percentage of the time signal that is HIGH (ON)
as the fraction of Total Time is called the Duty Cycle
Duration (Pulse Width).
Digital Value
Duty Cycle Percentage= x 100
255
6
Example : Duty Cycle Duration
Suppose Duty Cycle is 75%
Total Dura on (One period) = 100 milli seconds
Duty (ON) Dura on = 75 milli seconds (Pulse Width)
OFF Dura on = 25 milli seconds
ON ON
5 volt
0 volt
OFF OFF
10%
50%
90%
8
Application Example: Controlling Speed of
5V DC Motor with PWM
●
Suppose a 5V DC Motor (Direct Current motor) is connected to
Port A of a 8255 peripheral interface chip as shown below.
●
The following port addresses will be used for 8255.
Port C address= 04h, Control Register address= 06h
+5V
Port A
PA0
8255 PA1
PA2
DC Motor
chip
Diode
PA3
PA4 Resistor
PA5
PA6 Transistor
PA7
GND
9
Components
Description
in Circuitry
It is a small DC (Direct Current) motor that rotates continiously.
DC Motor
●
●
It is powered by an external +5V voltage source (battery).
●
The transistor acts like a switch, controlling the power to
the DC motor.
The PA5 pin of Port-A in 8255 chip is used to turn the
Transistor
●
10
Application Program
●
Write an Assembly program that uses PWM method to control
the speed of a DC motor, through the 8255 interface chip.
●
Define the variables below.
●
TOTAL DURATION : 2 bytes
Arbitrary value of Total time (mili seconds) for one period.
Initialize with 30000.
●
DUTY CYCLE : 1 byte
The value (between 0 and 100) will be used to control the speed of motor.
Initialize with 75.
●
ON DURATION : 2 bytes
●
OFF DURATION : 2 bytes
The values will be calculated by percentage formula.
11
Calculation Formulas
12
Program
●
Program uses PWM method to control speed of a DC motor.
●
The 8255 chip is used as peripheral interface.
.model small
.stack
Part1 .data
TOTAL_DURATION DW 30000
;Arbitrary value of Total time (mili seconds) for one period
ON_DURATION DW ?
OFF_DURATION DW ?
DUTY_CYCLE DB 75
;Arbitrary value of Time for Duty (ON)
13
Part2
.code
BASLA PROC
.STARTUP
;Perform calculations.
MOV AX, TOTAL_DURATION ; Copy variable to AX
MUL DUTY_CYCLE ; Multiply AX by the Duty Cycle
MOV BL, 100 ; For percentage calculation
DIV BL ; Divide AX by 100
MOV ON_DURATION, AX ; Copy register to variable
14
Part3
.EXIT
BASLA ENDP
15
Part4
; SUBROUTINES
WAIT_FOR_ON PROC
MOV CX, ON_DURATION ; CX is counter for local loop
LokalDongu1:
NOP
LOOP LokalDongu1 ; Decrements CX implicitly
RET ; Return from procedure
WAIT_FOR_ON ENDP
;=================================================
WAIT_FOR_OFF PROC
MOV CX, OFF_DURATION ; CX is counter for local loop
LokalDongu2:
NOP
LOOP LokalDongu2 ; Decrements CX implicitly
RET ; Return from procedure
WAIT_FOR_OFF ENDP
;=================================================
16
Topics
Pulse Width Modulation
Analog to Digital Converter
Digital to Analog Converter
17
ADC 0808
Analog to Digital Converter
●
The ADC is an input device to a microprocessor.
●
CPU sends an initializing signal to the ADC to start the analog signal
to digital conversion process.
●
The Start of Conversion (SOC) signal is a pulse of a specific duration.
●
Analog to digital conversion is a slow process and the processor has to
wait for the digital data until the conversion is over.
●
After the conversion, the ADC sends the End of Conversion (EOC)
signal to inform the processor, and the result is ready at the output
buffer of ADC.
●
The tasks of issuing SOC pulse to ADC, reading EOC signal from the
ADC and reading the digital output of the ADC are carried out by the
CPU using 8255 peripheral interface chip ports.
18
ADC 0808
Analog to Digital Converter
19
ADC 0808
Analog to Digital Converter
20
Internal Block Diagram of
ADC 0808
21
Interfacing diagram of
8255 and ADC 0808
Vref-
EOC Analog
Input
SOC Voltage
Control signals:
SOC: Start of Conversion
EOC : End of Conversion
Address Lines: A, B, C 22
Interfacing diagram
with 8255 Chip and ADC 0808 chip
●
Pin connections of ADC 0808 :
●
The analog input pin I/P2 is used for analog voltage input.
●
Address pins A, B, C should be 0,1,0 respectively to select
the I/P2 pin.
●
The OE pin and ALE pin are at +5V to select the ADC chip
and enable the outputs.
●
Pin connections of 8255 :
●
PC7 pin acts as the input port to receive the EOC signal.
●
PC0 pin acts as the output port to send SOC to ADC.
●
PA0-PA7 pins act as a 8-bit input data port to receive the
digital data output from the ADC.
23
Interfacing diagram
with 8255 Chip and ADC 0808 chip
24
Analog to Digital Converter
• Input of ADC : Analog input voltage between 0 Volt and +5 Volts.
• Output of ADC : 8-bit digital number between 0 and 255.
• Precision (P) of converted values are calculated approximately (5 − 0)
by the following formula. Precision is also called as resolution. P= =0.02
255
26
Application Program
using 8255 and ADC 0808
●
Write an 8086 Assembly program that reads 8-bit
digital values from 8255 interface chip.
●
Suppose 8255 ports will be used for interfacing
with a ADC 0808 chip.
●
Use the Port A of 8255 chip for transferring digital
data output of ADC to the 8086 CPU.
●
Use the Port C of 8255 for control signals.
●
Suppose that an analog input is present at the I/P2
pin of ADC.
27
28
Defining the Control Word
for 8255 Interface Chip
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 1 1 0 0 0
29
Program
Program reads 8-bit input data thru 8255 interface chip,
from an ADC 0808 chip (Analog to Digital Converter).
.code
BASLA PROC
.STARTUP
mov AL, 02h ;Select the I/P2 pin of ADC chip as analog input
out PortB, AL ;PortB of 8255 is connected to I/P2 pin of ADC chip
mov AL, 00h ;Send SOC pulse to the ADC (Start Of Conversion)
out PortC, AL ;PortC of 8255 is connected to SOC pin of ADC chip
30
BEKLE:
IN AL, PortC ;Check for EOC signal by reading PortC upper of 8255 chip
RCL AL,1 ;Rotate AL trough carry
Part2 JNC BEKLE ;Jump if Not Carry
IN AL, PortA ;If EOC signal exists, then read the 8-bit equivalent data in AL.
.EXIT
BASLA ENDP
END BASLA ;End of file
31
Topics
Pulse Width Modulation
Analog to Digital Converter
Digital to Analog Converter
32
DAC 0830
Digital to Analog Converter
●
DAC 0830 is an 8-bit converter that transforms an 8 bit binary
number into an analog voltage output.
●
There are also other converters that convert from 10, 12, or 16 bit
binary numbers into analog voltages.
●
The number of voltage steps generated by the converter is equal to
the number of binary input combinations:
An 8 bit converter generates 256 voltage levels (28).
A 10 bit converter generates 1024 levels (210).
●
For a 8-bit converter, the analog output step is defined as VREF
(reference), divided by 255.
●
The step voltage is also called the resolution of the DAC converter.
33
DAC 0830
Digital to Analog Converter
34
Example: Controlling Speed of
12 Volt DC Motor with DAC 0830
Analog outputs labeled IOUT1 and IOUT2 are inputs to an external
Operational Amplifier.
DAC
0830
Opamp +12 V
Address
Decoder 35