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 in 8051 embedded c

Status
Not open for further replies.

vinothksr08

Member level 3
Joined
Jun 18, 2013
Messages
66
Helped
7
Reputation
14
Reaction score
7
Trophy points
8
Location
Tamilnadu, India
Activity points
367
dear friends,

i have doubt in delay... i have to give the 1 ms delay without using timer.. how can i???

And also to know what is delay time of this for loop??
am using 8051 with 12MHz crystal frequency...

for(i=0;i<1275;i++);
 

vicky001.iith

Advanced Member level 4
Joined
Aug 5, 2013
Messages
113
Helped
37
Reputation
74
Reaction score
31
Trophy points
48
Location
INDIA
Activity points
723
This will give the approximate delay of (1÷12M)×(prescale value)×(no.of cycles)×(your "for" loop length) ...check wether you have assigned prescale value or not .. and what is the no. of cycles ? But again you won't get exact delay without timers.
USE TIMERS because Embedded have to be exact,ALWAYS !! :smile:
 

errakeshpillai

Full Member level 5
Joined
Oct 17, 2011
Messages
256
Helped
64
Reputation
128
Reaction score
59
Trophy points
1,328
Location
Chennai, India
Activity points
2,738
i have doubt in delay... i have to give the 1 ms delay without using timer.. how can i???

You will need to use the polling method for this, i.e. looping for some time.
like the same "for" loop example you gave.

for(i=0;i<1275;i++);

According to some examples in the book on 8051 by Mazidi, it will give a delay of 1ms. But you can check the exact delay of this loop by using breakpoints in Keil cross compiler. The delay may vary from compiler to compiler because of the way how the C code is converted into Assembly instructions. It will not take more time in verifying in Keil or any such compiler.
 

vinothksr08

Member level 3
Joined
Jun 18, 2013
Messages
66
Helped
7
Reputation
14
Reaction score
7
Trophy points
8
Location
Tamilnadu, India
Activity points
367
You will need to use the polling method for this, i.e. looping for some time.
like the same "for" loop example you gave.



According to some examples in the book on 8051 by Mazidi, it will give a delay of 1ms. But you can check the exact delay of this loop by using breakpoints in Keil cross compiler. The delay may vary from compiler to compiler because of the way how the C code is converted into Assembly instructions. It will not take more time in verifying in Keil or any such compiler.


how to use the polling method can u explain???

thank you
 

amayilsamy

Advanced Member level 1
Joined
Feb 5, 2013
Messages
422
Helped
38
Reputation
76
Reaction score
35
Trophy points
1,308
Location
Chennai,India
Activity points
3,369
how to use the polling method can u explain???

thank you

Debug that code using keil debugger . That is a easy way to find the time for execute the loop.

delay.JPG
 

errakeshpillai

Full Member level 5
Joined
Oct 17, 2011
Messages
256
Helped
64
Reputation
128
Reaction score
59
Trophy points
1,328
Location
Chennai, India
Activity points
2,738
The looping method can be used to simply make CPU do some dummy steps, so that it will provide a necessary delay.

Suppose if we use for(i=0;i<1275;i++);
This will make the CPU to just increment the value of ' i ' and check if it is less than 1275. This checking will make the CPU revolve there itself to produce some finite delay.

Which compiler are you using..?
 

vinothksr08

Member level 3
Joined
Jun 18, 2013
Messages
66
Helped
7
Reputation
14
Reaction score
7
Trophy points
8
Location
Tamilnadu, India
Activity points
367
hai

s, i can understand that but i would like to know the time of that delay.. am using keil c compiler
 

errakeshpillai

Full Member level 5
Joined
Oct 17, 2011
Messages
256
Helped
64
Reputation
128
Reaction score
59
Trophy points
1,328
Location
Chennai, India
Activity points
2,738
If you want to know the delay of this loop just use "Debug" mode in Keil.

> Set a Break point at the loop.
> Start the execution in debug mode.
> In debug mode, on the left-hand you will find a window showing the register contents. There will be a field showing the time also. Note the time from there.
> Now put a break point on the next statement after the loop, and start execution.
> It will stop at that break point. Here too note the time.
> The difference between those two noted time is the delay that the loop will give.
 

#MAAM#

Full Member level 2
Joined
Nov 21, 2009
Messages
131
Helped
29
Reputation
58
Reaction score
27
Trophy points
1,308
Location
Egypt
Activity points
1,920
there is accurate and easier method by using assembly and this simple program. Use this method and make mix between c and assembly
 

Attachments

  • delay.rar
    33.3 KB · Views: 9

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top