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.

[SOLVED] PIC microcontrollers delay time

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
208
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,084
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?
 

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
 

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....
 

can we see precise delay using inbuilt function with example code?
thanks your advices
 

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..
 
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.
 
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..
 
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......
 
i agree....it just happend that was my experience in delay function of mikroC.. but nothing wrong with that delay for me..
 

Thank you all. I am very happy that you shared your views on this topic.Thanks again
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top