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

hareeshchamiyar
Thu Mar 29 2018, 10:47 AM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 10:45 AM
can any one using dspic30f2010.
Thu Mar 29 2018, 06:03 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]
ExperimenterUK
Mon Mar 19 2018, 07:33 PM
sorry bedo.. maybe next time
Sun Mar 18 2018, 07:48 AM
Mourya Manojkumar
Please send me circuit diagram and PCB diagram
Thu Mar 01 2018, 05:49 AM
Felixc
May you please help me with a code for programmable load shedding controlling 4 loads
Sun Feb 25 2018, 08:29 PM
ezeoke.charles
i need of it
Sat Feb 24 2018, 03:35 AM
Aaquib
I want help for digital ic tester
ExperimenterUK
Tue Feb 20 2018, 04:01 PM
Join up.. and post your problem
Mon Feb 19 2018, 11:17 AM
ashishkumar
i needs help for my project

Downloads

Comments

jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM
rana2056
Sat Mar 31 2018, 02:11 PM
Darshanparabbnb
Mon Mar 26 2018, 07:17 AM
marttinsmarcio
Sat Mar 24 2018, 12:31 PM
LAMBO
Tue Mar 20 2018, 09:51 AM
bedo123
Mon Mar 19 2018, 07:48 AM

Online

Guests: 46, Members: 0 ...

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

Members: 37993
Newest member: jamiel
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Apr 16 2018, 08:49 PM
On the diagram, a diode feeds a rectified sine wav...
LAMBO Avatar
Posted By LAMBO
Mon Apr 16 2018, 06:39 AM
Hi sir i haven't connected any serial connec...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Apr 13 2018, 02:09 AM
I assume you are doing this project.http://www.805...
LAMBO Avatar
Posted By LAMBO
Thu Apr 12 2018, 06:51 PM
hii sir,I am working on ac motor controller .I hav...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Apr 10 2018, 06:12 PM
The lpc214x has a 32-bit prescaler , so I would ...
Praneeth1299 Avatar
Posted By Praneeth1299
Tue Apr 10 2018, 09:16 AM
Hi,I'm generating constant frequency of 1hz and va...
akrepkral76 Avatar
Posted By akrepkral76
Sat Apr 07 2018, 01:57 PM
I have used diptrace.I think ı have recevied from ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Apr 07 2018, 01:45 AM
You will need to say which software you are using,...
akrepkral76 Avatar
Posted By akrepkral76
Fri Apr 06 2018, 12:22 PM
I have drawed many PCB board. But it is still not ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Apr 04 2018, 10:49 PM
Do you have a working HM2007 board as shown in the...