Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[SOLVED] PIC microcontrollers delay time

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
202
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Location
Germany
Activity points
3,032
The delay function given is MikroC is delay_ms(250). I want to know is it real time or approximated.If a want a counter with 1 second delay what should I use the delay_ms() or should I use delay from timers.Which is the accurate and real time delay between these two funtions?
 

dayanpad

Advanced Member level 4
Joined
Mar 23, 2009
Messages
114
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,298
Location
Colombo
Activity points
1,921
The delay function given is MikroC is delay_ms(250). I want to know is it real time or approximated.If a want a counter with 1 second delay what should I use the delay_ms() or should I use delay from timers.Which is the accurate and real time delay between these two funtions?
If you want very precise delay, better way use RTC
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
No not the RTC, it makes more complex the project.... RTC is not used for delay generation.....you can go for these inbuilt functions, they are accurate and dont pose any problem....
 

dayanpad

Advanced Member level 4
Joined
Mar 23, 2009
Messages
114
Helped
17
Reputation
34
Reaction score
17
Trophy points
1,298
Location
Colombo
Activity points
1,921
can we see precise delay using inbuilt function with example code?
thanks your advices
 

romel_emperado

Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,068
hi tahir4awan, you can use the inbuilt delay function of mikcroC but they are not 100% accurate... I remember before I create a delay of 6sec but it give me only 4sec delay..
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,797
Helped
4,832
Reputation
9,682
Reaction score
4,617
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
125,978
If you wanted 6 seconds but got 4 there was something else seriously wrong. You can make delays in three ways:

1. a software loop. Knowing the clock speed and how many cycles each instruction takes you can 'waste' as many instructions as necessary to make any delay. Note that the processor is wholly tied up making the delay so it cannot do other things while waiting. If interupts occur, the delay might be longer because of the extra instructions it has to execute.

2. a built-in timer if there is one. This is accurate, especially if you use an interrupt to signal the end of the delay. It leaves the processor free to do other things and works like an alarm clock. After being started it sits in the background then alerts you when time is up.

3. use an external timing reference, this might be a counter circuit or an RTC. Bear in mind that any external timing system will have to be periodically checked by the program so even if the delay itself is accurate, there may be an extra delay before it gets noticed.

All of these methods rely on the clock source being accurate of course but normally it would be. I'm not sure what method mikroC uses but it should be accurate to within 1% of the requested time.

Brian.
 

romel_emperado

Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,068
If you wanted 6 seconds but got 4 there was something else seriously wrong. You can make delays in three ways:

1. a software loop. Knowing the clock speed and how many cycles each instruction takes you can 'waste' as many instructions as necessary to make any delay. Note that the processor is wholly tied up making the delay so it cannot do other things while waiting. If interupts occur, the delay might be longer because of the extra instructions it has to execute.

2. a built-in timer if there is one. This is accurate, especially if you use an interrupt to signal the end of the delay. It leaves the processor free to do other things and works like an alarm clock. After being started it sits in the background then alerts you when time is up.

3. use an external timing reference, this might be a counter circuit or an RTC. Bear in mind that any external timing system will have to be periodically checked by the program so even if the delay itself is accurate, there may be an extra delay before it gets noticed.

All of these methods rely on the clock source being accurate of course but normally it would be. I'm not sure what method mikroC uses but it should be accurate to within 1% of the requested time.

Brian.
I dont think something was seriously wrong since i just did blinking LED program.. :)

void main()
{
while(1)
{
// condition here

}
}
better to use timer interrupt if you want some accuracy of delay..
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
all the software libraries are tested before giving to external world and cannot be simply challenged..... i never got any problem if i use inbuilt libraries......
 

romel_emperado

Advanced Member level 2
Joined
Jul 23, 2009
Messages
606
Helped
45
Reputation
132
Reaction score
65
Trophy points
1,318
Location
philippines
Activity points
6,068
i agree....it just happend that was my experience in delay function of mikroC.. but nothing wrong with that delay for me..
 

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
202
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Location
Germany
Activity points
3,032
Thank you all. I am very happy that you shared your views on this topic.Thanks again
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top