Determining no of cycles for delay in PIC

Status
Not open for further replies.

ashwini jayaraman

Member level 2
Joined
Jan 17, 2013
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,601
Hello members,

Can anyone explain me how to determine number of cycles, provided the required delay, clock frequency????

very confusing!!!!!!!!

I doesn't know if the cycles they determined are clock cycles or instruction cycles?????

I have seen this in www.piclist.com
 

they are instruction cycles since the delay functions are made using various instructions and not using timer module, if you need an accurate delay with certain timing you can use the timer module of the pic.
 
in PIC, one instruction cycle is 4 clock cycles for PIC 8 bit microcontrollers except some high end PIC18 series MCU's.
For delay routines, i suggest to use timers for accurate timing, otherwise using delays in softwares u need to find how many instruction a loop will eat, then
Fosc/(no. of instructions in one run of loop * 4) = single delay time, then u can keep count in loop to run it for that time,
so required delay = single delay time * loop count

hope that helps.
 
There is a website I use to generate assembly language delay routines. Give it a try and examine the code it generates. It will help you understand how it works.
 
There is also an application note by microchip - I remember reading something about not using NOP's for some reason. (worth checking)
I think the mikro IDE also can do this for you (download the free version if you dont have it - it is fully functional in this respect)
 
As others have said, if you want to have accurate delays then you will need to use a timer. Using a loop with NOPs or some other instruction is not only blocking (i.e. no other code can execute during the delay), but it also will be inaccurate. Technically, if you do the tedious math correctly, you could get a precise delay this way, but it would only be accurate if compiled with the same compiler as yours (and the same version and edition) and can easily become inaccurate if things in your program are changed.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…