Upload
v85shg
View
21
Download
0
Embed Size (px)
DESCRIPTION
The progress report 2 for Microprocessor System. It is about understanding the principle of potentiometer and how it is used in microprocessor (MCU). The MCU used is basic stamp product.
Citation preview
1
University Brunei Darussalam
PH 2234
MICROPROCESSOR SYSTEM
PROGRESS REPORT 2
MUHAMMAD FAIZ BIN AWG HAJI SULAIMAN
08B2009
Year : 2nd year
Semester: 3rd semester
B. Electrical & Electronics Engineering
Comments:- Marks:-
2
Table of Contents 1) POTENTIOMETER .................................................................................................................................. 4
1.1 TEST WITH DMM ........................................................................................................................... 4
1.2 Using DMM to find the measured resistor value. ......................................................................... 5
1.3 MODEL OF POTENTIOMETER (Ratiometric device) ...................................................................... 5
2) Threshold of Potentiometer ................................................................................................................. 7
3) RC TIME ............................................................................................................................................... 10
3.1 Classic method for transducing analogue to digital .................................................................... 10
3.2 INSIDE OF BS2 ............................................................................................................................. 15
3.3 UNDERSTANDING THE RC TIME INSTRUCTION ........................................................................... 16
3.4 Difference between Analog and Digital in charging and discharging a capacitor. ..................... 17
Capacitor charging equation ............................................................................................................... 19
Discharge circuit .................................................................................................................................. 19
Program 3.1 ......................................................................................................................................... 22
Program 3.2 ......................................................................................................................................... 23
Program 3.3 ......................................................................................................................................... 24
Program 3.4 ......................................................................................................................................... 25
4) POLLED INTERUPT ............................................................................................................................... 26
4.2 PRINCIPLE OF THE MICROPROCESSOR OF THE SERVO ............................................................... 28
5) SX28 microcontroller (used in BS2SX microcontroller) ..................................................... 29
Program 5.1 ........................................................................................................................................ 29
Explanation of the program 5.1 .......................................................................................................... 30
Program 5.2 ......................................................................................................................................... 30
Explanation of the program 5.2 .......................................................................................................... 31
Program 5.3 ......................................................................................................................................... 31
Further about SX-28 ............................................................................................................................ 32
Overview of i/o ports of SX-28 ............................................................................................................ 33
INSIDE SX28 ......................................................................................................................................... 33
More on the SX28 program ................................................................................................................ 34
Program 5.4 ......................................................................................................................................... 34
More explanation on program 5.4 ...................................................................................................... 34
Program 5.5 ......................................................................................................................................... 35
3
Program 5.6 ......................................................................................................................................... 35
Program 5.7 ......................................................................................................................................... 36
Program 5.8 ......................................................................................................................................... 37
CIRCUIT FOR SWITCHING LED ON AND OFF ........................................................................................ 38
Program 5.9 ......................................................................................................................................... 38
Further explanation on the program 5.9 ............................................................................................ 39
SX INTRUCTION SET “rl” ...................................................................................................................... 39
6) 8-BIT ANALOGUE-TO-DIGITAL CONVERTER (ADC) with serial output ............................................ 40
Program 6.1 ............................................................................................................................................. 41
Further on ADC ....................................................................................................................................... 42
How the ADC no. is implemented in the debug .................................................................................. 43
Application of ADC .............................................................................................................................. 45
4
1) POTENTIOMETER
3
1
2
Red (“regulated” 5 V)
yellow
Black (0 V)
Vdd
Vss
POTENTIOMETER
1.1 TEST WITH DMM Point 1 and 3 = Maximum value of the resistor
Point 1 and 2 & point 2 and 3 = can be changed (variable)
Given blue potentiometer:
3 (NC)
1 (Vss)
2 (Vdd)
There are 6 half turns (3 complete turns)
Maximum resistor value: 10kΩ
5
1.2 Using DMM to find the measured resistor value.
Connect Vdd to point 2 (5V) and 1 to Vss (0V)
Anticlockwise 0V
Clockwise 5V
1.3 MODEL OF POTENTIOMETER (Ratiometric device)
5V
Wiper
0V
R2
R1VOut
( ) (
) assmume RTOTAL and V are constant.
Point Measured Resistor value Turning Max/Min
1&3 10.6kΩ Both Maximum
1&2 1.8Ω / 0.02kΩ CCW Minimum
1&2 10.04kΩ CW Maximum
2&3 1.8Ω / 0.02kΩ CW Maximum
2&3 10.04kΩ CCW Maximum
Ratiometric part
6
ALTERNATIVELY:
(
)
For the given 3 turn potentiometer (1080 ⁰)
(
)
For example,
For example,
Finally:
(
)
NOTE: tranducer is a component that can change angle to voltage (trans=across; ducer=to lead)
Fixed constant in
this case
Thus equation means we have a transducer
as known as sensor
R1
7
2) Threshold of Potentiometer Practical 1:
DIR0=0
DIR0=1
out0=1
out0=0
+5V
0V
IN0
Out0
DIR0
Vss 0V
Vdd +5V
V
Program2.1: results: V thresholdp0=1.417 V
Ω
3
2
1 black
( )
DIR=0 Again: DEBUG BIN IN0 PAUSE 500 GOTO again
8
Demonstrate the use RC time instruction to measure resistance of potentiometer connected as a
variable resistor.
2
1
0.1μF
220kΩ
10kΩ
variable resistor
Vdd (+5V)
Vss (0V)
Vdd (+5V)
Vss (0V)
p0
in0
out0
dir0
Inside
microprocessor
Outside
microprocessor
3
12
NC
Program2.2:
chargetime VAR Word DIR0=1 OUT0=1 PAUSE 1 again: RCTIME 0,1,chargetime DIR0=1 PAUSE 1 DEBUG DEC chargetime, CR GOTO again
9
Further explanation of program2.2:
+5V
0V
++++++
++++++0.1μF
220 Ω
+5V+5V
Below pbasic language
means discharge the
0.1μF capacitor through 220Ω resistor:-
DIR0=1
OUT=0
PAUSE 1
Remainder: KE=1/2 mv2 Elight=1/2 LI2
Ecapacitor=1/2 CV2
P.S: Discharging capacitor has two meaning:-
1) Voltage across plates = 0 volts 2) (Be aware): Voltage of the plates can be 0V,1000V,-1000V,any volts
10
3) RC TIME
3.1 Classic method for transducing analogue to digital
Below is the simplified basic circuit
C
R
+
-
5 V
+5V
0V
V0=5v
t=0
Zero internal
resistance
i.e. perfect
power supply
When switch is
closed, the capacitor
C discharges
1) Before time, t=0s, we have this circuit:-
R
+
-
5 V
V0=5v
11
2) So after time, t=0, we have the following circuit:-
iR
+
-
5 V
iC
3) Differentiate wrt time on both sides:-
( )
Assume C is constant
Rearranging,
4) Sum of voltages in circuit = zero
Recall:-
Q=CV
Where D=dt;
Q is the no of coulombs and;
Solution is:-
I(A)
t(s)
5/R
0
12
Differentiating w.r.t. time constant,
Multiply through by C
Set RC=τ (time constant in seconds)
(1)
(2)
(3)
Substitute equation 2 and 3 into 1
When A=0,
Therefore,
5) So far,
(4)
Solve for B using boundary conditions (b.c.)
To get the bc, we need to know about capacitors
a) Capacitors act like a short circuit or low resistance to fast change of current or voltage.
b) Capacitors act like an open circuits or high resistance to slow change of current or voltage.
Capacitive reactance is
(Unit Ω)
For more, the properties of inductor are opposite to the capacitor.
a) Inductors act like an open circuit or high resistance to fast changes of current or voltage.
b) Inductors act like a short circuit or low resistance to slow change of current or voltage.
Inductive reactance is (Unit Ω)
13
Hence at time i=0
When substitute into equation 4
At time, t= , Thus b.c. 1 is of no used. Then try time t=0, therefore there will be fast-changes of current or voltage
The capacitor is short circuit, ,
R
It=0
+
-
5V
Substitute b.c.2 into 4
So
Finally as capacitor charged,
Voltage across capacitor, Vc given by
( )
Where
b.c. 1
b.c. 2
14
Now add the BS2 microcomputer circuit looks like following figure:-
+
-
5V
in0
(Classic method for transducing analogue to digital)
More detail inside the Basic Stamp for RC time instruction
1
V
t
5V
1.4
in0
tcross
0
in0
V threshold =1.4 V
5e-t/RC
At time of RC time is program as
e.g. RCTIME 0,1,chargetime
Pin 0
Measure time from start & instruction from 1 to 0 transmitters of in0
Put measured time
into this variable
2μs
15
Solve for R because given t=tcross, C is given
Take natural loop of both sides
Hence where k is a constant.
3.2 INSIDE OF BS2 500kHz internal clock used for RCTIME, PULSOUT and PULSIN
&In0
Time t=0
1
0
“ Start RC
time”
instructions
2μs
Clock goes through to 16bit counter only
when in0=1 AND “start RCTIME” =1
16 bit counter counts every positive going
edge that it receives
16 bit counter already clever to zero before
RC time instruction implemented
1000 dec
Therefore tcross=0.002s
16
3.3 UNDERSTANDING THE RC TIME INSTRUCTION
+5V
0V
220Ω
10kΩ
VariableVR
BS2
2
1
Program used:
Chargetime VAR word OUT0=1 DIR0=1 PAUSE 1 Again: RCTIME 0,1,chargetime ‘measure chargetime which is debug dec chargetime,CR ‘time for VR to fall from 5V to V threshold (1.45V) DIR0=1 PAUSE 1 goto again
Gives 1ms to discharge C
17
3.4 Difference between Analog and Digital in charging and discharging a
capacitor.
Shorting link
(For discharge)
+5V
0V
RVR
C5V
5V
i=5/R e-t/τ
ANALOG BS2 (DIGITAL)
+5V
0V
5V
0V
id
P0Dir0=0
Out0=1
in0
Shorting link is connected to discharge the capacitor
Shorting link is disconnected to charge the capacitor
To charge or discharge the capacitor the bs2 automatically
charge or discharge the capacitor depends on the
programmer setting.
1
0 t
Small R
large R
+5V
0V t
V
Small R
Large R
C in top R in botom
VR
C in bottom R in top
id
t
Vc
18
Simplify discharge circuit
5V
0V
220Ω
Simplify further discharge circuit
+5V
0V
R
220Ω
+5v
VR |t=0
Simplify still further
+5V
0V
R
220Ω
VR |t=0
19
Capacitor charging equation
Discharge circuit
Discharge equation
220ΩC
+5V
0V
Fully
charge
voltage
Discharge equation:-
Where
Where t=nτ
Not constant
5/220 Fully charge when current falls to
0.1% of starting current
Starting current I
t
20
Where n=number of time constants
So discharge for 7 time constants, i.e. allow to “fully” discharge
Discharge equation:-
220ΩC V220
VR
i
V
5V
0
t 22μ
s
( )
( )
Actual approximation is:
21
Next we used the potentiometer to light up the eight LED with different style of lighting it up:-
Debug of the rctime of potentiometer: 1642
Total LED =8
Therefore, 1 LED = 80
Waveform, VR, charging charge RC time instruction and during discharge procedure
V
t
VR=1.45 V
5 V
0
Discharge of C
Charge
RCtime charged time
Vthreshold
( )
2cm=500μs 2.6cm=650μs
Graph scale
Basic stamp
The value that came
out in the Basic
stamp debug
“rctime”
22
Program 3.1
This program is bar chart of lighting up the LEDs. Here we used 4 LEDs only.
' $STAMP BS2 chargetime VAR Word OUT0=1 DIR0=1 PAUSE 1 DIRD=%1111 '$f or 15 again: RCTIME 0,1,chargetime 'measure chargetime which is DEBUG DEC chargetime,CR 'timefor VR tofall from 5V to threshold 1.45V DIR0=1'allow 1ms to PAUSE 1'discharge C IF chargetime < 76 THEN one IF chargetime < 226 THEN two IF chargetime < 376 THEN three four: OUTD=%1111'all led's on GOTO again one: OUTD=%0001 GOTO again two: OUTD=%0011 GOTO again three: OUTD=%0111 GOTO again
#1
23
Program 3.2
Similar to program 3.1 but using different technique of writing the IF command (see #1 and #2)
' $STAMP BS2 chargetime VAR Word OUT0=1 DIR0=1 PAUSE 1 DIRD=%1111 '$f or 15 again: RCTIME 0,1,chargetime 'measure chargetime which is DEBUG DEC chargetime,CR 'timefor VR tofall from 5V to threshold 1.45V DIR0=1'allow 1ms to PAUSE 1'discharge C IF chargetime > 525 THEN four IF chargetime > 375 THEN three IF chargetime > 225 THEN two IF chargetime > 75 THEN one
off: OUTD=%0000 GOTO again four: OUTD=%1111'all led's on GOTO again
one:OUTD=%0001 GOTO again
two: OUTD=%0011 GOTO again
three:OUTD=%0111 GOTO again
#2
24
Program 3.3
Here we used 8 LEDs
' $STAMP BS2 CT VAR Word DIR0=1 OUT0=1 PAUSE 1 DIRH=%11111111 again: RCTIME 0,1,CT DEBUG DEC CT,CR DIR0=1 PAUSE 1 IF CT < 2 THEN off IF CT < 76 THEN one IF CT < 151 THEN two IF CT < 226 THEN three IF CT < 300 THEN four IF CT < 375 THEN five IF CT < 450 THEN six IF CT < 525 THEN seven IF CT < 601 THEN eight limit: OUTH=%01010101 GOTO again eight: OUTH=%11111111 GOTO again off: OUTH=%00000000 GOTO again one: OUTH=%00000001 GOTO again two: OUTH=%00000011 GOTO again three: OUTH=%00000111 GOTO again four: OUTH=%00001111 GOTO again five: OUTH=%00011111 GOTO again six: OUTH=%00111111 GOTO again seven: OUTH=%01111111 GOTO again
25
Program 3.4
Now we used the potentiometer as Dimmer for the LED
Here are the waveforms that help to understands how the potentiometer can be used as dimmer.
Space=period-mark
Dimmer
10ms 10ms
20ms
15ms 5
15ms 5
50% brightness
75% brightness
15% brightness
space mark
( )
Duty ratio
' $STAMP BS2 CT VAR Word ontime VAR Word DIR0=1 OUT0=1 PAUSE 1 again: RCTIME 0,1,CT DEBUG DEC CT,CR DIR0=1 ontime = CT*100/660*100 PULSOUT 15, ontime PULSOUT 7, 10000-ontime GOTO again
26
4) POLLED INTERUPT In this experiment we used two basic stamp – BS#1 and BS#2
+5V
Vss 0V
BS #2 BS #1
220Ω
P1P11P0
P15
Vss
Servo
220Ω
Following are the program for BS#1 (Transmitter) and BS#2 (receiver)
1mm
This is the waveform where a “spike” send every 20ms approximately from BS#1 to BS#2
' $STAMP BS2 'TX polled interupt program (BS#1) again: PULSOUT 1,1 ‘take about 2μs PAUSE 19 ‘pause for 19000μs GOTO again ‘repeat the again instruction
Just want a spike interrupt
so as not to waste time
27
By chance 180⁰ out of phase to BS#1 clock will lead to a missed count in the programme.
The count positive edge of BS#2 clock is after receipt of positive going edge of pulse.
In each basic stamp, there have different tolerance for example BS#1 – 501kHz and BS#2 – 499kHZ.
' $STAMP BS2 'RX polled interupt program (BS#2) chargetime VAR Word polledinterrupt VAR Nib theta VAR Word OUT0=1 DIR0=1 again: PULSIN 11, 1, polledinterrupt 'DEBUG DEC polledinterrupt, CR ' to check rcv 1 RCTIME 0,1,chargetime DIR0=1 'DEBUG DEC chargetime, CR ' to check the RC time chargetime=chargetime MIN 1 MAX 651 theta =(chargetime-1)*10/13 +500 'x*500/650 +500 'x=(chargetime-1) 'using y=mx+c 'DEBUG DEC theta,CR ' to get correct no. range PULSOUT 15, theta GOTO again
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Pulse of 15 X2μs = 30μs
Free running clock
BS#1
BS#2
Not counted
28
4.2 PRINCIPLE OF THE MICROPROCESSOR OF THE SERVO 1) Servo angle controlled by pulse width,t
2) Angel is not controlled by period
+45⁰
-45⁰
0.5 1.0 1.5 2.0
Pulsewidth, t(ms)
theta
periodtime
Approximately
20ms
(10ms25ms)
t
29
5) SX28 microcontroller (used in BS2SX microcontroller)
SX28 microcontroller is used in BS2SX microcontroller where BS2 use PIC microcontroller
Assembler Language programming short word mnemonic/programming
Assembly is usually used 3 or 4 letter instruction
Also cover machine code programming all numbers for instructions & data….no letters, no english
No symbols e.g. + - X / don’t exist, gosub, pulsout
Rctime, don’t exist
Following are the example of a simple program:-
Program 5.1
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 loop mov w,#%00000000 ; load specified binary number intoworking register,w mov rc,w ; load contents of w into register C jmp loop
30
Explanation of the program 5.1
Mov w,#%00000000
Mov Rc,w; load contents of w into register C Jmp loop
Program 5.2
470Ω
rc7
0V
Immediate instruction
binary
;load specified binary number
intoworking register,w
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov w,#%00000000 ; load specified binary number intoworking register,w mov rc,w ; load contents of w into register C mov w,#%01111111 mov !rc,w loop mov w,#%10000000 mov rc,w mov w,#%00000000 mov rc,w jmp loop
The circuit for the programs below
31
Explanation of the program 5.2
To make the led at C7 to blink…..
loop mov w,#%10000000 ; load specified binary number intoworking register,w
mov rc,w ; load contents of w into register C
mov w,#%01111111
mov !rc,w
Program 5.3
Following show that the SX-28 take last few bit used in state using the whole 8bit as shown in the
program 5.2 above. Also the instruction of “djnz” is used here for delay (like pause instruction in BS2)
P7P0 BS2
outL=%00000000
Outc7 to out.0=%00000000
Zero volts from rc.7, rc.6…..rc.0
Set directions of rc
Exclamation mark means direction
No colon
must be
at the left
corner
No exclamation mark
mean output voltages
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov w,#%0000 mov ra,w mov w,#%1110 mov !ra,w loop mov w,#%0000 mov ra,w call delay1 mov w,#%0001 mov ra,w call delay1 jmp loop
32
The time taken in the delay is:
255X255X255X80E-9=1.3 sec (speed)
Further about SX-28
The usual
Odd ball
The i/o direction of SX28 and BS2 (there are opposite)
i/o direction for SX28
1=input
0=output
i/o direction for BS2
1=output
0=input
The time taken for for each SX-28 instruction
50 000 000 Hz per sec 20 nano sec
1ms 1000μs 1 000 000 ns
delay1 mov $0A,#$FF ‘255 skip2 mov $0B,#$FF ‘255 skip1 mov $0C,#$FF ‘255 skip0 djnz $0C,skip0 djnz $0B,skip1 ‘decriment of not zero djnz $0A,skip2 ret
33
Overview of i/o ports of SX-28
INSIDE SX28
RC0 port is used for example.
5V Vdd
0V Vss
rc.0bit
rc.0=1
rc.0=0
RC0
dir! switch
!rc.0=1
!rc.0=0
SX28 i/O ports
Ra.0 Ra.1 Ra.2 Ra.3
Rb.0 Rb.1 Rb.2 Rb.3
Rc.7 Rc.6 Rc.5 Rc.4 Rc.3 Rc.2 Rc.1 Rc.0
Rb.7 Rb.6 Rb.5 Rb.4
Register a
Register b
Register c
Register b
34
More on the SX28 program
Frequency of SX28 is 50 MHz
1/50 μs = 0.020μs = 20ns
Program 5.4
More explanation on program 5.4
Jmp 0.3 ms in BStamp
Jmp 20ns in SX28
Gosub in BS call in SX28
Return in BS ret in SX28
Djnz takes four clock pulse to implement djnz time = 4 X 20ns = 80 ns
1000,000,000ns = 1 sec
12.5 million djnz’s
delay mov $0C,#$ff
0A,0B,$ 0C
are each 8.bit
registers
loop setb rc.7 ;setb=setbit=,ale equal to"1" ;only effect one bit call delay clrb rc.7 ;clrb=clearbit=make equal to "0" ;only affects rc.7 call delay jmp loop delay mov $0C,#$ff ;ff in dec is 255 ;load register C with 255 skip2 mov $0B,#$ff ;load register C with 255 skip1 mov $0A,#$ff ;load register C with 255 skip0 djnz $0A,skip0 ;decrement by 1 registerA and if result is not equal to zero then jump to skip0 djnz $0B,skip1 ;decrement by 1 registerB and if result is not equal to zero then jump to skip1 djnz $0C,skip2 ;decrement by 1 registerC and if result is not equal to zero then jump to skip2
35
Program 5.5
To ensure the hardware (LED) is working
Program 5.6
Use 2 as the delay for output A, B and C.
mov !rc,#%01111111 main setb rc.7 clrb rc.7 jmp main
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov !rc,#%01111111 main setb rc.7 call delay clrb rc.7 call delay jmp main delay mov $0C,#2 skip3 mov $0B,#2 skip2 mov $0A,#2 skip1 djnz $0A,skip1 djnz $0B,skip2 djnz $0C,skip3 ret
36
Program 5.7
In order to get one second delay
Set the outputs to 255,255 and 192
Since 255 X 255 X 255 X 80ns =1.33s
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov !rc,#%01111111 main setb rc.7 call delay clrb rc.7 call delay jmp main delay mov $0C,#255 skip3 mov $0B,#255 skip2 mov $0A,#192 skip1 djnz $0A,skip1 djnz $0B,skip2 djnz $0C,skip3 ret
37
Program 5.8
The following circuit is used for the program. The program will control the opening of the switches
digitally.
Vdd(+5V)
10k
270
Vss (0V)
470
0V
rc3
rc7
Not-pressed/
unpressed
pressed
Not-pressed/
unpressed
pressed
The four type of switches
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov !rc, #%01111111 main mov $0D,rc rl $0D rl $0D rl $0D rl $0D rl $0D jnc onlight clrb rc.7 jmp main onlight setb rc.7 jmp main
38
CIRCUIT FOR SWITCHING LED ON AND OFF
The Figure below is the complete circuit of the switching LED On and off.
SX28
Vdd +5V
Vss 0V
10kΩ
RC3
Vss 0V
When V=+5V OFF light
V=0V ON light
This the program used where “rl” is used here
Program 5.9
Device sx28L,oschs3 Device Turbo, StackX, optionX IRC_cal IRC_4MHz Freq 50_000_000 Reset 0 mov !rc,#%01111111 mov rc,#00000000 loop ;mov $0D, #0 ;move literally value of 0 inyo register D clc ; clear the C flag to zero mov $0D,rc rl $0D rl $0D rl $0D rl $0D rl $0D jc offlight onlight setb rc.7 jmp loop offlight clrb rc.7 jmp loop
39
Further explanation on the program 5.9
SX INTRUCTION SET “rl”
For “rl” which means rotate left as shown in the diagram below.
It rotate left (rl), $0D register sequence as follows:
Start $ØD
0
0 0 0 0 1 0 0 0
rl $ØD
0
0 0 0 1 0 0 0 0
rl $ØD
0
0 0 1 0 0 0 0 0
rl $ØD
0
0 1 0 0 0 0 0 0
rl $ØD
0
1 0 0 0 0 0 0 0
rl $ØD
1
0 0 0 0 0 0 0 0
rl
Bit7
Bit6
Bit5
Bit4 Bit3
Bit2
Bit1
Carry bit
rc.3 Carry bit
40
6) 8-BIT ANALOGUE-TO-DIGITAL CONVERTER (ADC) with serial output Using ADC 0831 chip
BS2
“Brain”
P9
P10
P11CLK
DO
Vcc (+5V)
VrefGND
Vin(-)
Vin(+)
CSADC
0831
Vss (0V) Vdd (+5V)
Variable voltage
between 0 to 5V
Program 6.1 is used for this
Measuring -temp. -acceleration -velocity -pressure
-microprocessor -microcontroller -microcomputer (only no. here)
sensors brain actuators
ADC DAC
OVERVIEW OF THE USE OF ADC
(muscles)
Converter to change physical
quantities into number
Converter to change number
into physical quantities
Digital to analogue converter
Specifically variable voltage
variable quantity
41
Program 6.1
' $STAMP BS2 dvolts VAR Byte DIR11=1 DIR10=0 DIR9=1 HIGH 9 LOW 11 loop: LOW 9 HIGH 11 LOW 11 HIGH 11 LOW 11 HIGH 11 dvolts.BIT7=IN10 LOW 11 HIGH 11 dvolts.BIT6=IN10 LOW 11 HIGH 11 dvolts.BIT5=IN10 LOW 11 HIGH 11 dvolts.BIT4=IN10 LOW 11 HIGH 11 dvolts.BIT3=IN10 LOW 11 HIGH 11 dvolts.BIT2=IN10 LOW 11 HIGH 11 dvolts.BIT1=IN10 LOW 11 HIGH 11 dvolts.BIT0=IN10 LOW 11 HIGH 9 DEBUG DEC dvolts,CR GOTO loop
42
Further on ADC We used three power supplies to conduct this experiment. Following are the circuit used:
BS2
“Brain”
P9
P10
P11CLK
DO
Vcc (+5V)
VrefGND
Vin(-)
Vin(+)
CSADC
0831
Vss (0V)
Power supply 1
Power supply 2Power supply 3
We still used program 6.1 to do this experiment.
Following data are observed on the debug screen of “dvolts”
Vin (-) [power supply 2]
0 V 1 V 1 V
Vref [power supply 3]
5 V 4 V 3 V
Vin + (V) ADC.no. ADC.no. ADC.no.
0 0 0 0
1 51 0 0
2 103 62 83
3 154 126 167
4 205 190 252
5 255 253 255
43
Below is the graph of the data above:-
This graph show that the higher the different of Vin(+), the gradient is less steeper. On the other hand
the lower the different of Vin(-), the gradient is steeper. The gradient means the resolution of the ADC
no. Therefore the lower the potential difference, the higher the resolution.
How the ADC no. is implemented in the debug
For Vin(-)=0V and Vref=5V, following are extra data collected.
0
50
100
150
200
250
300
1 2 3 4 5 6
Vin(-)=0, Vref=5V
Vin(-)=1V, Vref=5V
Vin(-)=1, Vref=3V AD
C N
O.
Vin +(V)
Vin + (V) ADC.no.
0 mV 0
10 mV 1/0
20 mV 1
30 mV 1
40 mV 2
50 mV 2/3
Vin + (V) ADC.no.
15 mV 0
25 mV 1
35 mV 1
45 mV 2
44
These data are used to find the smallest increment of Vin in terms of ADC number.
The graph of ADC no. against Vin (mv) is plot from the data above.
3
2
1
0
10 20 30 40 50
ADC
no.
Vin (mV)
From the graph above show that:-
This can be proved by calculation:-
Therefore
( ) ( )
When calculating the ADC no., always used the round down value of integer.
( )
( )
45
Application of ADC
It can be used for temperature sensor
Where
To convert degree ( ) to Fahrenheit ( )
( ) ( ( )
)
To convert Fahrenheit ( )to degree ( )
( ) ( ( ) )
Therefore using the formula above, following data can be determined:-
0
1
2
3
4
5
0 100 200 300 400 500
vo
ltag
e O
/P (
V)
temperature ( ⁰F)
46
Thus below is the graph for temperature in degree against temperature in Fahrenheit.
Therefore, in order to fully utilize the range of the ADC for greater accuracy to make a temperature
sensor especially for usage in Brunei.
Let say is the temperature of Brunei throughout the year ( )
This means the Vin(-) should be 0.7 and Vref=0.3
0
20
40
60
80
100
0 15 30 45 60 75 90 105 120 135 150 165 180 195 210
temperature ( ⁰F)
tem
per
atu
re (
⁰C
)
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
0 20 40 60 80 100 120 140 160 180 200 220 240 260
temperature ( ⁰C)
vo
ltag
e O
/P (
V)
Vin (-) 0.7
Vref 0.3
Vin + (V) ADC.no.
0.3 0
0.4 34
0.5 71
0.6 109
0.7 143
0.8 180
0.9 218
1 255
2 255
3 255
4 255
5 255