[PIC] MPLAB Instruction Frequency vs RC Oscillator Frequency

Discussion in 'Embedded Systems and Microcontrollers' started by noble_soul, Feb 25, 2016.

  1. noble_soul

    Thread Starter New Member

    Feb 10, 2016
    6
    0
    Hello,
    I am working on a project on the PIC16F687 and I need to do some timing analysis on it (to figure out how long critical functions are taking to execute).
    I looked around and saw that the MPLAB IDE has a simulator with a stopwatch function that can be used to do just that; but I am confused about setting up the simulator options. In particular, the oscillator options for the simulator has two fields: "Instruction frequency (Fcyc)" and "RC Oscillator Frequency" (shown in attached picture).

    I am running the PIC at 8MHz:
    In my init() I set: OSCCON = 0b01111000; //8MHz clock speed
    I set the config bits: #pragma config FOSC = EXTRCCLK

    I am using MPLAB IDE V3.20

    my question is: What is the difference between the "Instruction Frequency" and "RC Oscillator Frequency" in the MPLAB simulator options menu, and what values should I have there to correctly simulate the core running at 8MHz.

    Thank you very much in advance
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,142
    1,790
    On the midrange PIC's, of which the 16F is an example, each instruction takes 4 oscillator clocks. So if the internal oscillator is running at 8 MHz, then you get two instructions every microsecond.
     
  3. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,692
    901
    With PIC's, the difference is a factor of 4. That is, instruction frequency = oscillator frequency /4

    If you look in the documentation, you will see that it takes 4 clicks of the oscillator for a typical instruction to execute. Any instruction that resets the PC, requires two instruction cycles. Thus, with instructions such as btfss, you will see one instruction cycle if there is no skip and 2 instruction cycles (Fosc/8) if there is a skip.

    John
     
  4. noble_soul

    Thread Starter New Member

    Feb 10, 2016
    6
    0
    Thanks a lot for your quick replies.
    I had read that instruction frequency = oscillator frequency/4 somewhere.... but I was confused as to why MPLAB asks for both those values as input (if they are always a scalar multiple of each other). Now I think I know why: different families of products have a different scalar multipliers?
     
  5. Papabravo

    Expert

    Feb 24, 2006
    10,142
    1,790
    I think you meant: "the instruction frequency is an integer multiple of the oscillator frequency". A scalar multiple could be 2.718281828..., or √2 -- right?
     
  6. NorthGuy

    Active Member

    Jun 28, 2014
    604
    121
    Yes. x2 on most PIC24/33, and x1 on PIC32. Of course, the simulator could've figured that out, so I would guess it's something else.
     
  7. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,692
    901
    On a mid-range device, TMR1 can also use the oscillator frequency rather than the instruction "clock." If you plan to run TMR1 off the oscillator frequency, be sure to read the caveat in the datasheet.

    John
     
Loading...