instruction cycles

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi all!

I've written my code and created an asm file...
I build it successfully and could read the program size in words

BUT I also need to read the instruction cycles!!???
But I have no idea where to read it!

Can anybody please help?

Regards,
 

DerStrom8

Joined Feb 20, 2011
2,390
Hi Eric.

If you are using PIC in MPLAB, you can read the instruction cycles by putting a breakpoint at the very end of the program. Then open up the debugger (we'll use MPLAB sim for this example). Then go to Debugger->Stopwatch. Make sure the stopwatch is set to the correct clock frequency for your chip (you can change it by going to Debugger->Settings). Then just run the simulation. It will stop at the breakpoint and the stopwatch will tell you how many instruction cycles and how many seconds it took for your code to be completed.
Depending on your code, you may have to set the breakpoint elsewhere. Just set it where you want to check the number of instruction cycles.
I hope this helps!
Der Strom
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Ok thanks but how do I know the correct frequency for pic16f684

I read some manual n tried doing what u said but I was getting a very huge number of insteruction cycle...I set the frequency to 4Mhz...maybe that not the correct one?
 

ErnieM

Joined Apr 24, 2011
8,377
The frequency should be set to the same frequency as you intend to use in your hardware. You can use an external crystal up to 20 MHz, the internal oscillator at 8 MHz or some other source.

As this is hardware, your software is not aware of this frequency unless you tell it. MPLAB has a setting. In some code libraries you also need to include something in your code to let it know what frequency is intended.

I would suggest using the internal 8MHz oscillator when just starting out. It will work quite nicely when your code is correct. An external crystal can be troublesome to get working, and can make good code "brick" (just do nothing).
 

DerStrom8

Joined Feb 20, 2011
2,390
Eric, what are you using for a clock? An internal oscillator, an external crystal oscillator, or an external RC oscillator?
You need this information before you can really do anything else.
 

debjit625

Joined Apr 17, 2010
790
Eric007 said:
BUT I also need to read the instruction cycles!!???
If you are using Microchip's PIC range,then know this simple thing ,the oscillator's frequency i.e.. system clock is divided by 4 inside the PIC to get one instruction cycle.It means that 4 clock is 1 instruction cycle.For example if you use 4Mhz oscillator as your clock source then your instruction cycle will be 4Mhz/4 = 1Mhz,so each instruction will take about 1000000Mhz/1000000us = 1us i.e.. 1 micro second.

Note not all instruction takes 1 instruction cycle to execute,like GOTO or CALL takes more than 1 instruction cycle to execute.For more details check the datasheet for "Instruction Set"

Good Luck
 
Last edited:

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Thanks all for your help...
i really appreciated although i ran out of time and had to submit my design project...
But it not a problem i have learnt at least...
hope will work again with you guys....

thankx again errbody!
 
Top