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.

How this delay subroutine has 2764795 cycles????Couldn't get it:(:(

Status
Not open for further replies.

ashwini jayaraman

Member level 2
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
This is the program:
Delay = 1 seconds
; Clock frequency = 11.0592 MHz

; Actual delay = 1 seconds = 2764800 cycles
; Error = 0 %

Code:
cblock
d1
d2
d3
endc

Delay
;2764795 cycles
movlw 0xDA
movwf d1
movlw 0x07
movwf d2
movlw 0x07
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0

;1 cycle
nop

;4 cycles (including call)
return[CODE]
[/CODE]

I doesn't understand how this is happening...when I calculated theoretically, I got just 11161 instruction cycles...but in a website it is given as 2764795 cycles. also, I want to know how the no of instruction cycles vary with respect to delay... Plz do explain somebody..or suggest me some websites so that I will learn from that..I did google for this..But couldn't find the relevant explanation at all..am badly stuck up with this for the past few days...
 

This is a repeat of another thread by the same poster.

Each instruction takes a set number of clock cycles to complete. The delay is simply the total of all the times each instruction takes before returning back to the program that called it. Basically it wastes time by running loops of instructions until a condition is met that makes it return. The number of clock cycles and hence the time to complete each instruction is clearly stated in the data sheet.

Copy the code into MPLAB or MPLABX and set the watch window to show the values in d1, d2 and d3. Step through the program taking particular note of maximum values each of them reaches and PLEASE get rid of those '$+' instructions. They will come back to haunt you, I promise!

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top