Time delay using a Register Pair
How this code works?
Delay calculation
LOOP: DCX D (6 T states)
MOV A,E (4 T states)
ORA D (4 T states)
JNZ LOOP (10/7 T states)
For example if the clock frequency is 1 Mhz( then T=1) then the
maximum delay will be calculated as
Total delay = 10T +( 24x65535)T -3T microsecond
=10 +( 24x65535) -3 microsecond (
since T=1)
= 1.572847 second
This is maximum delay at system clock frequency 1 Mhz.
Time Delay using loop within loop
A multiple loop is used to create a large delay. Here we are using
loop within a loop
Code :
loop1: dcr c 4t-states loop1
jnz loop1 10/7 t –states loop2
dcr b 4t-states
jnz loop2 10/7 t -states
if the clock frequency of the system f = 2MHZ
clock period (T) = 1/f = 1/2*10 power-6 = 0.5 microsecond
for loop1:
total delay( tl1) = 7t+(4t+10t) x 255-3t = 4t + (14t x 255)= 4x0.5
+(14 x 0.5 x 255) = 1787 microsecond
for loop2:
total delay (td) =
= 7t+( tl1 + 4t + 10t) x count – 3t
= 4t + ( tl1
+ 14t) x count
= 4 x 0.5 + (
1787 + 14 x 0.5) x count
Td = 2 + 1,794 x
count
Suppose you need to create
a delay for 100ms , then
100000 microsecond = 2 + 1,794 x count
Count = (100000-2)/ 1794 = 55.7402 = 56 decimal value = 38 H (
hexadecimal value)
The maximum delay ( at count= ff H) is 2 + 1794 x 255 = 457,472 microsecond = 457.472
milli second = 0.45 second.
When the system frequency is operating at 2 Mhz.
Let’s have a delay program using two register pairs used in nested loop
LXI B, FFFF H (10 T states)
//inner loop start
LOOP2:
LXI D, FFFF H (10 T states)
LOOP1: DCX D (6 T states)
MOV A,E (4 T states)
ORA D (4 T states)
JNZ LOOP1 (10/7 T states)
//inner loop ends
DCX B (6 T states)
MOV A,C (4 T states)
ORA B (4 T states)
JNZ LOOP2 (10/7 T states)
Delay calculation
Since given crystal frequency is 4Mhz , them T= 1/f = 1/(4 x 106) second = 0.25x10-6 second
T = 0.25 micro second
For inner loop
Delay = 10T +( 24 x FFFFh )T -3T second
= 10T +( 24 x 65535)T -3T second ( here FFFFh = 65535 decimal value)
Delay = 10T +( 24x65535)T -3T
= 7 x (0.25) +(24 x 65535 ) x 0.25 microsecond = 393211.75 Microsecond
= 0.39321175 second
Now total delay calculation ( including inner and outer loop)
= 10T + ( 0.39321175 + 24T) x FFFFh – 3T second
= 10T + (
0.39321175 + 24T) x 65535 – 3T second
=7T +(
0.39321175 + 24T) x 65535 second
=(7 x 0.25 x 10-6)
+ (0.39321175 + 24 x 0.25 x 10-6) X 65535 second
= 25769.525248 second
This is maximum delay at system clock frequency 4 Mhz using two register pairs used in nested loop
2 comments:
what will be the maximum delay using two register pairs used in nested loop, if the crystal frequency is 4 MHz?
Help me out !!!!!
The loops shown lastly is not really nested. Otherwise great job, well done!
Post a Comment