Thank you Mr. Ashley Roll. It surely is of great help to me. Thanks again. UbaidUllah, Ashley Roll cc: Sent by: pic Subject: Re: [PIC] Delay Routine problem (a microcontrolle newbie) r discussion list 05/20/2002 12:12 PM Please respond to pic microcontrolle r discussion list Hi UbaidUllah, > Problem no 1: Mentioned is Actual delay = 0.5 seconds = 500000 cycles > What I do not understand is that the clock speed is 4000,000 CPS. > With this speed, the cycles for 0.5 seconds delay should > have been = > 4000,000/2=2000,000 Cycles. The PIC "instruction" cycle takes 4 clock cycles to happen. Therefore the PIC with a 4MHz Clock, instructions are executed at a rate of 1MHz. However be aware that some instructions (CALL, GOTO, RETURN etc) that modify the instruction pointer take 2 instruction cycles to execute. Therefore when counting instruction cycles, you are actually counting 4 clock cycles per instruction cycle so the delay works out at 0.5 seconds. > Problem no 2: What is cblock? CBlock is a way to "declare" your variables. It allows you to name and reserve RAM locations. > Problem no 3: What is $+1? This is a shorthand way to say "Current Program Location" + 1 (the next instruction). This is sometimes used instead of declaring a head of labels. In this case it is using a GOTO instruction to jump to the next instruction. This is done because a GOTO actually takes 2 instruction cycles to execute so for the cost of one ROM instruction you effectively get 2 instruction delays so your delay routine is smaller. > Problem no 3: How is it mentioned 2 cycles & 4 cycles? To get the exact number of instructions executed to give you the precise delay you requested, some extra is needed on the end of the loop. Thus the last goto $+1 add a further 2 instruction cycles. You also need to take into account the CALL and RETURN instructions. Each adds another 2 instruction cycles resulting in a total of 4 instruction cycles to get into and out of the delay routine. Does that help? Cheers, Ash. --- Ashley Roll Digital Nemesis Pty Ltd www.digitalnemesis.com Mobile: +61 (0)417 705 718 -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body