instruction cycles

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Aug 10, 2011.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    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,
     
  2. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Which platform i.e.. which microcontroller or microprocessor you are using...
     
  3. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    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
     
  4. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    I'm using pic16f6684 I'm just simulating it I'm using MPLab v7
     
  5. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    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?
     
  6. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    post removed
     
    Last edited: Aug 10, 2011
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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).
     
  8. DerStrom8

    Well-Known Member

    Feb 20, 2011
    2,428
    1,328
    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.
     
  9. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    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: Aug 10, 2011
  10. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    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!
     
Loading...