Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Delay Calculations on 8051

Status
Not open for further replies.

glenjoy

Banned
Joined
Jan 1, 2004
Messages
962
Helped
72
Reputation
146
Reaction score
20
Trophy points
1,298
Location
Philippines
Activity points
0
delay calculation using timer in 8051

Does anybody here knows how to make exact delays using 8051, say for example 500 ms? But this is without the 8051 delay calculator software help, what I need is the exact calculations of the machine cycle/instruction cycle.

Btw I am using DS89C420, a High Speed one version.
 

th0 tl0 1mc delay calculation

hi,

Why not use an internal timer which produce an interrupt on a know bundary instead counting CPU cycles ?
 

th0 tl0 1mc delay routine

The timer will do but you still need to know the clock frequency because time depends on it, so it's still counting cpu cycles but in a clever way.
 

how to produce a delay in 8051

Most simpliest way is to use internal timers, but you have to be very carefull if you want 500ms exactly.

E.g. Suppose you have 12MHz xtal (1MIPS). You made timer to run 50ms TH0=0x3C TL0=0xAF.

In interrupt routine you decrement one (eg. time) variable (time=10 in beggining). when time=0 500ms is gone.

You have to calculate how many machines cycles are interrupt and you have to calculate how many cycles you need to get in interrupt and to get out of it. These number of cycles you need to subtract of 3CAF and you get exactly 500ms.


Mr.Cube
 

8051 cycles calculator

hi all


a good software to make loop delayd time on 8051 is this :
 

calculate machine cycle 8051

Hi hm_fa_da,

good software, but your program with this routine will stop in that subroutine "TTO" for secified time (e.g. 500ms) so other process will not be proccessed.

Better way is to do delay with interrupts.


Mr.Cube
 
time8051.zip

what u need to know is
oscillator frequency
instruction cycle frequency.
what delay you want
step 1: oscillator frequency/instruction cycle fequency

step 2: 1/step 1 result

step 3: delay u want * result in step 2

step 4: upper value the register can count - result in step 3

the result u need to load to thl and thh register.
 

That so crucial it is the delay that you need to implement???, so
that you can play with the run times of instructions like NOP...
or by this form, or with which they indicate to you above, you need to know to the frequency of clock of your micro and the run times of the instructions.
Good Luck!
 

I am sorry because this step(3) is wrong

"step 3: delay u want * result in step 2 "

FOR THIS STEP WE ARE NOT MULTIPLY BUT WE NEED TO DEVIDED THE VALUE

CORRECTION ON STEP 3

"step 3: delay u want / result in step 2 "
 

Time8051.zip is the best solution, it will teach you how to calculate delay. I am also personally using it and its result is near 100% correct.
regards
 

For a machine cycle of 1.085us (11.085Mhz)

Machine Cycle(MC)
Delay : Mov R2, #200 ( 1MC)
Again: Mov R3, #250 ( 1MC)
Here: NOP ( 1MC)
NOP ( 1MC)
DJNZ R3, Here ( 2MC)
DJNZ R2, Again ( 2MC)
RET ( 1MC)


Calculation:

1)For Here loop, (4x250)1.085us = 1085us
2)The Again loop repeat the Here loop 200times, 200x1085us=217000
3)The Mov R3,#250 & DJNZ R2,Again => (3x200x1.085us)=615us
4) Result total delay=217000+651=217651us=217.651ms

5)Note: u also can add the RET cycle, 1.085us add to the result. So that more accurate! ^_^


So,jz modify a bit to get the delay u want.
Mayb try to use timer is better :)
Note: the Maximum Register value can go is 2^8=256 , so dun set overload.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top