Instruction Cycles

Status
Not open for further replies.

wuchy143

Member
Hello,

For any given Micro is there a standard/simple way to figure out how long(in time) each instruction cycle takes?
 
Hello,

For any given Micro is there a standard/simple way to figure out how long(in time) each instruction cycle takes?

Read the datasheets, they list them - but PIC's (16F and lower) are dead simple, almost all instructions take one cycle, a few take two, and a few take one or two (depending on true or false). As it's a RISC device there are also very few instructions to check.
 
nice that's what I got. Thanks.

odd though. I'm using microchips C18 compiler and when I do:

Delay10TCYx(20) I get a delay which I expect ----> 20 * 10 * .5uS = 100uS delay. I verified this on my scope by toggling a port pin.

Then when I only want to delay 1 instruction cycle I do:

Delay1TCY(); I get a delay of about 2us though the signal isn't a perfect square wave. How come I'm not seeing a full .5ns delay? I wonder if it has to do with the fact that I banging a port pin before and after I do the delay. That may be messing it up. Meaning that It's actually doing the delay but in doing the port toggles that makes it take longer? If that's true I'm still missing about .5ns??
 
Last edited:
For precise timings you need to use inline assembler on your compiler.Otherwise for function calling & returning stuff it will waste some few cycles.
 
Last edited:
Thanks!! Too bad I spent about 2 hours this AM trying to figure out why my instruction time was too long. It was fine the whole time
 
Thanks!! Too bad I spent about 2 hours this AM trying to figure out why my instruction time was too long. It was fine the whole time

Obviously you can't use instruction timings with C code, as you've no idea what instructions it might generate.
 
Obviously you can't use instruction timings with C code, as you've no idea what instructions it might generate.

That's why MPLAB has a Stopwatch built into the simulator--so you can set a couple of breakpoints and check the number of instruction cycles the code between them takes. I use it all the time, and it's very helpful!
Good luck!
Der Strom
 
I used MPLAB at my last job and that version of the IDE actually had the stopwatch. I agree. Very useful tool and you don't have to play games like banging a port pin to see what's going on under the hood.

For some reason I don't have the stop watch(at least haven't found it) on my current version. Version 8.70.00.00. Let me paw around more as I didn't search very long.


Now that I think about it I'm pretty sure I only ever used the stop watch in "simulator" mode.(still usefull as a first order approximation of what's going on) I don't think you can use it in debug. Anyone know?
 
Last edited:

If you're using MPLAB SIM, just go under the debugger menu and select "stopwatch". Not sure how to do it with the PK2 at this point--that's why MPLAB has a simulator built in
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…