Professional Documents
Culture Documents
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
1.2
1.3
2)
3)
RC TIME ............................................................................................................................................... 10
3.1
3.2
3.3
3.4
Difference between Analog and Digital in charging and discharging a capacitor. ..................... 17
5)
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)
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
3 (NC)
1 (Vss)
2 (Vdd)
1.2
Point
1&3
1&2
1&2
2&3
2&3
Turning
Both
CCW
CW
CW
CCW
Max/Min
Maximum
Minimum
Maximum
Maximum
Maximum
0V
Clockwise
5V
1.3
R2
Wiper
R1
VOut
0V
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
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
Remainder:
KE=1/2 mv2
Elight=1/2 LI2
Ecapacitor=1/2 CV2
+5V
++++++
0.1F
++++++
+5V
+5V
220
0V
P.S:
3) RC TIME
3.1
When switch is
closed, the capacitor
C discharges
t=0
Zero internal
resistance
i.e. perfect
power supply
5V
V0=5v
0V
+
5V
V0=5v
10
Recall:Q=CV
iC
+
Where D=dt;
Q is the no of coulombs and;
5V
iR
Assume C is constant
Rearranging,
I(A)
5/R
t(s)
11
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)
(Unit )
(Unit )
12
Hence at time
i=0
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
So
Where
13
Now add the BS2 microcomputer circuit looks like following figure:-
in0
+
5V
e.g.
2s
V
5V
5e-t/RC
1.4
t
in0
1
in0
V threshold =1.4 V
0
tcross
14
Hence
3.2
where k is a constant.
INSIDE OF BS2
In0
Start RC
time
instructions
&
1000 dec
1
0
Time t=0
Therefore tcross=0.002s
15
3.3
+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
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.
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
220
0V
VR |t=0
0V
220
VR |t=0
0V
18
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
to fully discharge
Discharge equation:-
220
220
V
5V
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
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
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
26
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
+45
t
Pulsewidth, t(ms)
0.5
-45
1.0
1.5
2.0
periodtime
Approximately
20ms
(10ms25ms)
28
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
29
Mov w,#%00000000
binary
470
0V
loop
mov
mov
mov
mov
mov
mov
mov
mov
jmp
w,#%10000000
rc,w
w,#%00000000
rc,w
loop
30
No exclamation mark
mean output voltages
No colon
must be
at the left
corner
mov
mov
rc,w
mov
w,#%01111111
mov
!rc,w
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
(speed)
The usual
0=output
i/o direction for BS2
Odd ball
1=output
0=input
32
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
setb rc.7
call delay
clrb rc.7
call delay
jmp loop
delay
skip2
skip1
mov $0C,#$ff
mov $0B,#$ff
mov $0A,#$ff
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
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)
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
+5V
SX28
10k
RC3
Vss
0V
Vss
0V
!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
38
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
rc.3
Start $D
rl $D
rl $D
rl $D
rl $D
rl $D
39
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)
brain
ADC
-microprocessor
-microcontroller
-microcomputer
(only no. here)
actuators
DAC
(muscles)
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)
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
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
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)
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
4
3
2
1
0
0
100
200
300
400
500
temperature ( F)
( )
( )
45
Thus below is the graph for temperature in degree against temperature in Fahrenheit.
100
temperature ( C)
80
60
40
20
0
0
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
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
20
40
60
temperature ( C)
46