Discussion in "8051 Discussion Forum" started by    gaurav    Jan 22, 2011.
Sat Jan 22 2011, 11:23 pm
#1
hai can any one tell me how to operate the software to calculate the 1sec dalay
Sun Jan 23 2011, 12:31 am
#2
; INPUT CLOCK VALUE IN MEGAHERTZ...: 11.0592
; WANTED TIME DELAY IN MICROSECONDS: 1000000
; CLOCK CYCLE TIME................ : 90 ns
; PROCESSOR CYCLE TIME (12)....... : 1085 ns
; TOTAL REQUIRED CYCLES........... : 921600
; TOTAL TIME (INCLUDING CALL)..... : 1000.00 mS
; USE THE FOLLOWING CODE:


Del_1_Sec:  MOV   R3,#8
      MOV   R2,#8
      MOV   R1,#236
Del_1_Sec0:
      DJNZ  R1,Del_1_Sec0
      DJNZ  R2,Del_1_Sec0
      DJNZ  R3,Del_1_Sec0
      RET
Sun Jan 23 2011, 11:59 am
#3
i have understand the working of delay
then too will u explain me the delay in short

but how to calculate the delay time


[ Edited Sun Jan 23 2011, 12:16 pm ]
Sun Jan 23 2011, 08:23 pm
#4
hi gaurav.k
let say ur using 12 MHz crystal oscillator then machine cycle is
MC=12Mhz/12= 1Mhz=1us
now u want to generate a delay of 50ms then
(65536-xx)*MC=delay
now
(65536-xx)*1us=50ms
65536-xx=50000
xx=15536 =3CB0
THx=3C
TLx=B0
now after 50ms flag will be high if it high it mean 50ms delay is occur now count this flag 20 times it mean 20*50ms=1000ms=1sec
Sun Jan 23 2011, 10:51 pm
#5
hi i like to know how to calculate the delay in loop method also
Sun Jan 23 2011, 11:30 pm
#6
make delay using calculation provided by Majoka after that call the function in loop... for example.... you make a delay function delay_ms(); when you call this delay of 1 sec is generated.....

now if you call this like like this....

 for (i=0;i<=60; i++){
delay_ms();
}


it means call delay function 60 times by this you will get delay of 60 seconds mean 1 minute....
Mon Jan 24 2011, 10:42 am
#7
delay of 1 sec in loop method in asm
var1 equ r0
delay equ r1

org 00h
call delay_1sec
jmp $

delay_1sec:
	mov delay,#250
	acall delayms
	mov delay,#250
	acall delayms
	mov delay,#250
	acall delayms
	mov delay,#250
	acall delayms
	ret

delayms:
	mov var1,#230
d:
	nop
	nop
	djnz var1,d
	djnz delay,delayms
	ret
end


calculation:
@11.0592 MHZ MC(machine cycle is 1.085 us)
mov need 1 instruction cycle
djnz need 2 instruction cycle
nop need 1 instrction cycle
ret need 2 machine cycles
now


mov var1,#230 ; 2 MC
d:
nop ; 1 MC
nop ; 1MC
djnz var1,d ;2 MC
djnz delay,delayms ; 2MC
ret ; 2MC


in inner loop total MC
4*230=920 MC
250*920=230000
delay is =230000*1.085us=0.24955
it is almost 250 ms call it 4 times means 1sec

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Danielnof
Sat May 04 2024, 11:12 pm
oriminna
Sat May 04 2024, 08:28 pm
scaneraNom
Sat May 04 2024, 02:21 am
gtaletrzua
Fri May 03 2024, 10:55 am
Clydehet
Wed May 01 2024, 06:44 pm
Davidoried
Wed May 01 2024, 06:11 pm
KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am