You are on page 1of 46

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:-

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

5)

PRINCIPLE OF THE MICROPROCESSOR OF THE SERVO ............................................................... 28


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
2

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

1) POTENTIOMETER
Vdd

Red (regulated 5 V)
3

yellow
2

Vss

Black (0 V)

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:

There are 6 half turns (3 complete turns)


Maximum resistor value: 10k

3 (NC)

1 (Vss)
2 (Vdd)

1.2

Using DMM to find the measured resistor value.

Point
1&3
1&2
1&2
2&3
2&3

Measured Resistor value


10.6k
1.8 / 0.02k
10.04k
1.8 / 0.02k
10.04k

Turning
Both
CCW
CW
CW
CCW

Max/Min
Maximum
Minimum
Maximum
Maximum
Maximum

Connect Vdd to point 2 (5V) and 1 to Vss (0V)


Anticlockwise

0V

Clockwise

5V

1.3

MODEL OF POTENTIOMETER (Ratiometric device)


5V

R2

Wiper

R1

VOut

0V

assmume RTOTAL and V are constant.

Ratiometric part

ALTERNATIVELY:
(

Fixed constant in
this case
For the given 3 turn potentiometer (1080 )
(

R1

For example,

For example,

Finally:

( )
Thus equation means we have a transducer
as known as sensor

NOTE: tranducer is a component that can change angle to voltage (trans=across; ducer=to lead)

2) Threshold of Potentiometer
Practical 1:

Vdd

+5V

+5V

IN0
DIR0=0

DIR0

out0=1
Out0

DIR0=1
Vss

out0=0

0V

Program2.1:

0V

DIR=0
Again: DEBUG BIN IN0
PAUSE 500
GOTO again

results:

V thresholdp0=1.417 V

3
2

black

Demonstrate the use RC time instruction to measure resistance of potentiometer connected as a


variable resistor.
Vdd (+5V)

Vdd (+5V)
Outside
microprocessor

Inside
microprocessor

0.1F

in0
p0

NC

dir0

220k

out0
2

10k
variable resistor

Vss (0V)

Vss (0V)

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

Further explanation of program2.2:

Remainder:
KE=1/2 mv2
Elight=1/2 LI2
Ecapacitor=1/2 CV2

+5V

++++++
0.1F

++++++

+5V

+5V
220

Below pbasic language


means discharge the
0.1F capacitor through
220 resistor:DIR0=1
OUT=0
PAUSE 1

0V

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

3) RC TIME
3.1

Classic method for transducing analogue to digital


Below is the simplified basic circuit
+5V

When switch is
closed, the capacitor
C discharges

t=0

Zero internal
resistance
i.e. perfect
power supply

5V

V0=5v

0V

1) Before time, t=0s, we have this circuit:-

+
5V

V0=5v

10

2) So after time, t=0, we have the following circuit:-

Recall:Q=CV

iC
+

Where D=dt;
Q is the no of coulombs and;

5V

iR

3) Differentiate wrt time on both sides:( )

Assume C is constant

Rearranging,

Solution is:4) Sum of voltages in circuit = zero

I(A)
5/R

t(s)

11

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,
Solve for B using boundary conditions (b.c.)

(4)

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 )

12

Hence at time

i=0

When substitute into equation 4


At time, t= ,
Thus b.c. 1 is of no used.

b.c. 1

Then try time t=0, therefore there will be fast-changes of current or voltage
The capacitor is short circuit,

b.c. 2

It=0

+
5V

Substitute b.c.2 into 4

So

Finally as capacitor charged,

Voltage across capacitor, Vc given by

Where

13

Now add the BS2 microcomputer circuit looks like following figure:-

At time of RC time is program as

in0

+
5V

e.g.

Measure time from start


& instruction from 1 to 0
transmitters of in0
RCTIME 0,1,chargetime
Pin 0

Put measured time


into this variable

(Classic method for transducing analogue to digital)


More detail inside the Basic Stamp for RC time instruction

2s
V
5V

5e-t/RC

1.4
t
in0
1
in0
V threshold =1.4 V
0

tcross

14

Solve for R because given t=tcross, C is given

Take natural loop of both sides

Hence

3.2

where k is a constant.

INSIDE OF BS2

500kHz internal clock used for RCTIME, PULSOUT and PULSIN


Clock goes through to 16bit counter only
when in0=1 AND start RCTIME =1
2s

In0
Start RC
time
instructions

&

1000 dec

16 bit counter counts every positive going


edge that it receives

1
0

Time t=0

16 bit counter already clever to zero before


RC time instruction implemented

Therefore tcross=0.002s

15

3.3

UNDERSTANDING THE RC TIME INSTRUCTION

+5V

BS2
220

2
10k
Variable

VR
1
0V

Program used:
Chargetime VAR word
OUT0=1
Gives 1ms to discharge C
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

16

3.4 Difference between Analog and Digital in charging and discharging a


capacitor.
ANALOG

BS2 (DIGITAL)
+5V

i=5/R e

+5V

-t/

id
Shorting link
(For discharge)
5V

5V

0V
5V

P0

Dir0=0
in0
Out0=1

VR

0V

0V
To charge or discharge the capacitor the bs2 automatically
charge or discharge the capacitor depends on the
programmer setting.

Shorting link is connected to discharge the capacitor


Shorting link is disconnected to charge the capacitor

large R

C in top
R in botom

VR
C in bottom
R in top

+5V

Large R

0V

Small R
t

id

t
Vc

Small R

17

Simplify discharge circuit


5V

220

0V

Simplify further discharge circuit


+5V
+5v
220

VR |t=0

0V

Simplify still further


+5V

220

VR |t=0

0V

18

Capacitor charging equation

Not constant
Discharge circuit
Discharge equation

Fully
charge
0V voltage

+5V
C

220

Starting current
Fully charge when current falls to
0.1% of starting current

5/220

Discharge equation:-

Where

Where t=n
19

Where n=number of time constants

So discharge for 7 time constants, i.e. allow

to fully discharge

Discharge equation:-

220

220

V
5V

Actual approximation is:


(
0

22
s

20

5V
Discharge of C
Charge
VR=1.45 V

Vthreshold
0

t
RCtime charged time

Waveform, VR, charging charge RC time instruction and during discharge procedure

2cm=500s
2.6cm=650s

Graph scale
Basic stamp

The value that came


out in the Basic
stamp debug
rctime

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

21

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
#1
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

22

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
#2
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

23

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

24

Program 3.4
Now we used the potentiometer as Dimmer for the LED
' {$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

Here are the waveforms that help to understands how the potentiometer can be used as dimmer.

Dimmer

50% brightness

mark

space

10ms 10ms

Space=period-mark

20ms
Duty ratio
75% brightness

15ms

5
(

15% brightness

5 15ms

25

4) POLLED INTERUPT
In this experiment we used two basic stamp BS#1 and BS#2
+5V

220

220
P0

P11

P1

BS #2

BS #1
P15
Vss

Vss

0V
Servo

1mm

This is the waveform where a spike send every 20ms approximately from BS#1 to BS#2
Following are the program for BS#1 (Transmitter) and BS#2 (receiver)
' {$STAMP BS2} 'TX polled interupt program (BS#1)
again:

PULSOUT 1,1
PAUSE 19
GOTO again

take about 2s
pause for 19000s
repeat the again instruction

Just want a spike interrupt


so as not to waste time

26

' {$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

Free running clock


BS#1
0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Pulse of 15 X2s = 30s

BS#2
0

1 2 3 4 5 6 7 8 9 10 11 12 13 14
Not counted

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.

27

4.2

PRINCIPLE OF THE MICROPROCESSOR OF THE SERVO

1) Servo angle controlled by pulse width,t


2) Angel is not controlled by period
theta

+45
t

Pulsewidth, t(ms)
0.5
-45

1.0

1.5

2.0
periodtime
Approximately
20ms
(10ms25ms)

28

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 / dont exist, gosub, pulsout
Rctime, dont 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
mov
jmp

w,#%00000000 ; load specified binary number intoworking register,w


rc,w
; load contents of w into register C
loop

29

Explanation of the program 5.1


Immediate instruction

Mov w,#%00000000

;load specified binary number


intoworking register,w

binary

Mov Rc,w; load contents of w into register C


Jmp loop
Program 5.2
rc7

470

0V

The circuit for the programs below


Device sx28L,oschs3
Device Turbo, StackX, optionX
IRC_cal IRC_4MHz
Freq 50_000_000
Reset 0

loop

mov
mov
mov
mov

w,#%00000000 ; load specified binary number intoworking register,w


rc,w
; load contents of w into register C
w,#%01111111
!rc,w

mov
mov
mov
mov
jmp

w,#%10000000
rc,w
w,#%00000000
rc,w
loop

30

No exclamation mark
mean output voltages

Explanation of the program 5.2


To make the led at C7 to blink..
loop

No colon
must be
at the left
corner

mov

w,#%10000000 ; load specified binary number intoworking register,w

mov

rc,w

mov

w,#%01111111

mov

!rc,w

; load contents of w into register C


Set directions of rc

Exclamation mark means direction


P7P0

BS2

outL=%00000000

Outc7 to out.0=%00000000
Zero volts from rc.7, rc.6..rc.0

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)
Device sx28L,oschs3
Device Turbo, StackX, optionX
IRC_cal IRC_4MHz
Freq 50_000_000
Reset 0

loop

mov
mov
mov
mov

w,#%0000
ra,w
w,#%1110
!ra,w

mov
mov
call
mov
mov
call
jmp

w,#%0000
ra,w
delay1
w,#%0001
ra,w
delay1
loop

31

delay1
skip2
skip1
skip0

mov
mov
mov
djnz
djnz
djnz
ret

$0A,#$FF
$0B,#$FF
$0C,#$FF
$0C,skip0
$0B,skip1
$0A,skip2

255
255
255
decriment of not zero

The time taken in the delay is:


255X255X255X80E-9=1.3 sec

(speed)

Further about SX-28


The time taken for for each SX-28 instruction
50 000 000 Hz per sec 20 nano sec
1ms 1000s 1 000 000 ns

The i/o direction of SX28 and BS2 (there are opposite)


i/o direction for SX28
1=input

The usual

0=output
i/o direction for BS2

Odd ball

1=output
0=input

32

Overview of i/o ports of SX-28


SX28 i/O ports

Register c

Rc.7
Rc.6
Rc.5
Rc.4
Rc.3
Rc.2
Rc.1
Rc.0

Register b

Register b

Rb.0
Rb.1
Rb.2
Rb.3

Register a

Ra.0
Ra.1
Ra.2
Ra.3

Rb.7
Rb.6
Rb.5
Rb.4

INSIDE SX28
RC0 port is used for example.
5V

Vdd

dir! switch

rc.0bit

!rc.0=1
RC0
rc.0=1
!rc.0=0
rc.0=0

0V

Vss

33

More on the SX28 program


Frequency of SX28 is 50 MHz
1/50 s = 0.020s = 20ns
Program 5.4
loop

setb rc.7
call delay
clrb rc.7
call delay
jmp loop

;setb=setbit=,ale equal to"1"

;only effect one bit

;clrb=clearbit=make equal to "0"

;only affects rc.7

delay
skip2
skip1

mov $0C,#$ff
mov $0B,#$ff
mov $0A,#$ff

;ff in dec is 255 ;load register C with 255


;load register C with 255
;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

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 djnzs
delay

mov $0C,#$ff

0A,0B,$ 0C
are each 8.bit
registers

34

Program 5.5
To ensure the hardware (LED) is working
mov !rc,#%01111111
main

setb rc.7
clrb rc.7
jmp main

Program 5.6
Use 2 as the delay for output A, B and C.
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
skip3
skip2
skip1

mov $0C,#2
mov $0B,#2
mov $0A,#2
djnz $0A,skip1
djnz $0B,skip2
djnz $0C,skip3
ret

35

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
skip3
skip2
skip1

mov $0C,#255
mov $0B,#255
mov $0A,#192
djnz $0A,skip1
djnz $0B,skip2
djnz $0C,skip3
ret

36

Program 5.8
The following circuit is used for the program. The program will control the opening of the switches
digitally.
Vdd(+5V)

The four type of switches

10k

rc3
Not-pressed/
unpressed

270

pressed

Vss (0V)
rc7
470

Not-pressed/
unpressed

pressed

0V

Device sx28L,oschs3
Device Turbo, StackX, optionX
IRC_cal IRC_4MHz
Freq 50_000_000
Reset 0
mov

!rc, #%01111111

main
rl
rl
rl
rl
rl
jnc
clrb
jmp
onlight

mov $0D,rc
$0D
$0D
$0D
$0D
$0D
onlight
rc.7
main
setb
rc.7
jmp
main

37

CIRCUIT FOR SWITCHING LED ON AND OFF


The Figure below is the complete circuit of the switching LED On and off.
Vdd

+5V

SX28
10k

RC3

When V=+5V OFF light


V=0V ON light

Vss

0V

Vss

0V

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
mov
loop

!rc,#%01111111
rc,#00000000

;mov $0D, #0
clc
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

;move literally value of 0 inyo register D


; clear the C flag to zero

38

Further explanation on the program 5.9

SX INTRUCTION SET rl
For rl which means rotate left as shown in the diagram below.

Carry bit

Bit7

Bit1

Bit6

Bit2

Bit5
Bit3

rl

Bit4

It rotate left (rl), $0D register sequence as follows:


Carry bit

rc.3

Start $D

rl $D

rl $D

rl $D

rl $D

rl $D

39

6) 8-BIT ANALOGUE-TO-DIGITAL CONVERTER (ADC) with serial output


Using ADC 0831 chip

BS2
Brain
CS

P9
P10
P11
Variable voltage
between 0 to 5V

ADC
0831

Vcc (+5V)

Vin(+)

CLK

Vin(-)

DO

GND

Vref

Vss (0V)

Vdd (+5V)

Program 6.1 is used for this

OVERVIEW OF THE USE OF ADC

Specifically variable voltage


variable quantity
sensors
Measuring
-temp.
-acceleration
-velocity
-pressure

Digital to analogue converter

brain
ADC

-microprocessor
-microcontroller
-microcomputer
(only no. here)

Converter to change physical


quantities into number

actuators
DAC

(muscles)

Converter to change number


into physical quantities

40

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

41

Further on ADC
We used three power supplies to conduct this experiment. Following are the circuit used:

BS2
Brain
CS

P9
P10
P11

Vcc (+5V)

ADC
0831

Vin(+)

CLK

Power supply 1

Vin(-)

DO

Power supply 2

GND

Vref
Power supply 3

Vss (0V)

We still used program 6.1 to do this experiment.


Following data are observed on the debug screen of dvolts
Vin (-)
[power supply 2]
Vref
[power supply 3]

0V

1V

1V

5V

4V

3V

Vin + (V)

ADC.no.

ADC.no.

ADC.no.

51

103

62

83

154

126

167

205

190

252

255

253

255

42

Below is the graph of the data above:300


250

ADC NO.

200
Vin(-)=0, Vref=5V

150

Vin(-)=1V, Vref=5V

100

Vin(-)=1, Vref=3V

50
0
1

Vin +(V)
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.


Vin + (V)

ADC.no.

0 mV

10 mV

1/0

20 mV

30 mV

40 mV

50 mV

2/3

Vin + (V)

ADC.no.

15 mV

25 mV

35 mV

45 mV

43

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.

ADC
no.
3
(

( )

1
0
10

20

30

40

50

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.

44

Application of ADC
It can be used for temperature sensor
Where

voltage O/P (V)

4
3
2
1
0
0

100

200

300

400

500

temperature ( F)

To convert degree ( ) to Fahrenheit ( )


( )

( )

( )

To convert Fahrenheit ( )to degree ( )


( )

Therefore using the formula above, following data can be determined:-

45

Thus below is the graph for temperature in degree against temperature in Fahrenheit.
100

temperature ( C)

80
60
40
20
0
0

15 30 45 60 75 90 105 120 135 150 165 180 195 210

temperature ( F)

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 (

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

voltage O/P (V)

This means the Vin(-) should be 0.7 and Vref=0.3


5
4.5
4
3.5
3
2.5
2
1.5
1
0.5
0
0

20

40

60

80 100 120 140 160 180 200 220 240 260

temperature ( C)

46

You might also like