[PIC] MPLAB Instruction Frequency vs RC Oscillator Frequency

Thread Starter

noble_soul

Joined Feb 10, 2016
7
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
 

Attachments

Papabravo

Joined Feb 24, 2006
21,225
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.
 

jpanhalt

Joined Jan 18, 2008
11,087
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.
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
 

Thread Starter

noble_soul

Joined Feb 10, 2016
7
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?
 

Papabravo

Joined Feb 24, 2006
21,225
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?
 

jpanhalt

Joined Jan 18, 2008
11,087
TS said:
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
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
 
Top