So I have a 16MHz resonator attached to the PIC (built-in capacitors on the resonator). I verified the oscillating frequency with a scope - it's a solid 16 MHz. I want to run the PIC at 48 MHz (16 MHz instruction cycle) using the internal PLL. So this is how I have it configured:
As it is now, the clock should be divided by 4 to get the 4MHz base frequency PLL input. Then the PLL will multiply to 96MHz and finally it will get divided by 2 (CPUDIV). So I should end up with 48MHz (16MHz instruction cycle). Now, how do I test the operating frequency of the PIC? I can write a simple while loop to toggle a pin on and off constantly like this:
But because of the instructions that get executed in the loop, it won't show up as the true operating frequency on a scope. Right now I only see a frequency of 3 MHz. Even with the extra instructions it executes to evaluate the loop condition, it seems like 3 MHz is rather low. I should be seeing > 10 MHz if the PIC is running at 16MHz. So it seems to me like something is wrong with my oscillator configuration, because 3MHz pin toggling is too slow. Is there anything I can write in assembly that will constantly toggle a pin on and off at the operating frequency of the PIC? How do I verify the operating speed? Is there anything wrong with my oscillator configuration?
Rich (BB code):
#pragma config PLLDIV = 4, CPUDIV = OSC1_PLL2, FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF, PWRT = OFF, BOR = ON, BORV = 3, WDT = OFF, WDTPS = 32768
#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = ON, CCP2MX = ON, STVREN = ON, LVP = OFF, XINST = OFF, VREGEN = OFF, ICPRT = OFF, DEBUG = ON
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF, CPB = OFF, CPD = OFF, WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF, EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF, EBTRB = OFF
Rich (BB code):
while(1) {
PORTDbits.RD0 = 1;
PORTDbits.RD0 = 0;
}