Discussion in "8051 Discussion Forum" started by    Khadka_Bishal    Mar 16, 2018.
Fri Mar 16 2018, 11:34 AM
#1
I want to have a delay of 15 microsecond in 8051 using a crystal oscillator of 11.0592 MHz. .

To test the delay, i toggle port pin 1.0 for every execution of delay.
The code and its calculations are shown in code's comment section below

====================================================================
ORG 00h
MOV TMOD,#01 ;TIMER0 -> MODE1
;No. of machine cycle = 480uS/1.0850693us = 14
; 2^16 - 14 = 65522
; ( 65522 ) dec = ( FFF2 )hex
; The required value to generate 15us is (FFF2)16
; BUT, there is extra delay of 17 us due to execution of
;other codes except the delay loop
; To Compensate this,
; i add (17)dec =(11)hex to FFF2 = 1 0003 which exceed
; the max value FFFF.
; but i loaded the maximum value i.e. FFFF to timer reg
; and still i got a delay of 17 uS

LOOP:
CPL P1.0
ACALL DELAY15
SJMP LOOP


DELAY15:
MOV TH0,#0FFH
MOV TL0,#0FFH
SETB TR0
HERE: JNB TF0,HERE
CLR TR0
CLR TF0
RET
END
===================================================================

Even assigning the timer register its maximum value i am not getting delay of 15 uS (microsecond) . I have checked for the code optimization as well but i didn't see ta single step that could be either eliminated or optimized.

Please help on it !
Sat Mar 17 2018, 09:26 PM
#2
CPL P1.0 3
ACALL DELAY15 6
SJMP LOOP 3

DELAY15:
MOV TH0,#0FFH 2
MOV TL0,#0FFH 2
SETB TR0 3
HERE: JNB TF0,HERE 4
CLR TR0 3
CLR TF0 3
RET 4

total 33 = 17.9 uS

Instructions need different numbers of machine cycles.
I have noted the number needed for each instruction in your loop.
I get a total of 33.
You must be using a version of the 8051 that has
6 clock cycles per machine cycle.
Older types use 12 clock cycles per machine cycle.
33 machine cycles take around 17 uS as you found.

One obvious way to speed up the loop is to
not use a subroutine.
Put the delay "inline".
This saves the ACALL and RET.
You don't need Timer0 at all, you could just
just use a software loop.

LOOP:
CPL P1.0 3
// DELAY15:
MOV TH0,#0FFH 2
MOV TL0,#0FFH 2
SETB TR0 3
HERE: JNB TF0,HERE 4
CLR TR0 3
CLR TF0 3
SJMP LOOP 3

total 23 = 12.4 uS

Get Social

Information

Powered by e107 Forum System

Conversation

Sun May 20 2018, 01:16 PM
justinb
how to write and execute a program that read the keypad button and display the number on 7 segment on intel8051 at89s52 in assembly language?
Thu May 17 2018, 09:51 AM
HAMZA TAJ
sir iwant to ask about controller of three phase supply by using back to back thyristor instead of triac....will u give me some guideline?
Sat Apr 28 2018, 04:09 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Fri Apr 27 2018, 11:24 PM
@kaiserslautern Post in forum
Wed Apr 25 2018, 10:24 AM
kaiserslautern
Hello everyone, using software uart is a very good idea for a second serial port. Thank you so much. I would kindly like to know how to connect this port to the PC?
ExperimenterUK
Sat Apr 21 2018, 11:05 PM
This is a community site. Feel free to help anyone needing advice
hareeshchamiyar
Thu Mar 29 2018, 02:02 PM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 02:00 PM
can any one using dspic30f2010.
Thu Mar 29 2018, 09:18 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]
ExperimenterUK
Mon Mar 19 2018, 10:48 PM
sorry bedo.. maybe next time

Downloads

Comments

bdmehta
Tue May 22 2018, 02:30 AM
kmag1953
Sun Apr 29 2018, 07:09 PM
udiwonder
Sat Apr 28 2018, 12:41 PM
pirpiri
Sat Apr 21 2018, 03:35 PM
Pater
Fri Apr 20 2018, 02:38 PM
jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM

Online

Guests: 60, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37998
Newest member: bdmehta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 12 2018, 08:27 PM
I'm glad we got there in the end :)>whats differen...
LAMBO Avatar
Posted By LAMBO
Thu Jul 12 2018, 06:51 AM
hi sir as u mentioned above to change crystal and ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 10 2018, 07:20 PM
I assume you meant a AT89S52.It seems to me that...
LAMBO Avatar
Posted By LAMBO
Tue Jul 10 2018, 06:06 AM
hi sir i have checked now much of the distortion ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 09 2018, 06:55 PM
Okay that is very interesting.I have attached two ...
LAMBO Avatar
Posted By LAMBO
Mon Jul 09 2018, 08:14 AM
hi sir as u mentioned above program i have tried ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jul 06 2018, 11:58 PM
Okay..That motor creates a lot of sparks which mig...
LAMBO Avatar
Posted By LAMBO
Fri Jul 06 2018, 01:33 PM
hi sir as u told >Try the original code againi hav...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 02 2018, 06:20 PM
>is it ok to work on 12.10 v Yes, that is ok.>now...
LAMBO Avatar
Posted By LAMBO
Mon Jul 02 2018, 08:22 AM
hi sir as u mentioned in the program i have checke...