chipKIT® Development Platform

Inspired by Arduino™

PicKit3 and oscillator selection.

Created Fri, 20 Jan 2012 20:12:11 +0000 by uscEE


Fri, 20 Jan 2012 20:12:11 +0000

I recently got my Uno 32 and have been playing around with programming the PIC directly with my PicKit3. So far I have been successful in programming (flashing LED's) The problem comes in when I try to configure the oscillator. I would like to use the internal oscillator with the PLL to get the full 80MHz operation. I did a simple speed test by directly toggling an output and measuring the frequency, and the fastest I could get was 900KHz. I would post my current configs, but I'm on a different computer right now. Does anyone have any ideas about what could be wrong?

Also, if I configure it to output the clock on the OSCO pin, I get nothing.

Jacob Christ

Fri, 20 Jan 2012 22:31:10 +0000

When I looked before it didn't seem like you could get 80MHz using the internal oscillator (or maybe you could but USB didn't work correctly if you did, I'm using a PIC32MX440F512).

Also, there are several posts about square wave output and the speed. I would guess that you are getting 80MHz but are using the latest MPIDE and calling the Arduino abstracted calls for setting the pins hi and low based on the clock rate you are getting.



Fri, 20 Jan 2012 23:56:06 +0000

I'm programming directly from the PicKit3 in MPLAB so there is no bootloader present.

I simply have


I would expect this to write a very fast square wave no faster than SYSCLK/2 but I'm getting a 900KHz square wave.


Sat, 21 Jan 2012 04:03:26 +0000


Try using the following configuration bits. I haven't tried using the internal oscillator to achieve 80MHz, but I can try on Monday if you are still seeing the issue.

// Configuration Bit settings // SYSCLK = 80 MHz (8MHz FRC/ FPLLIDIV * FPLLMUL / FPLLODIV) // PBCLK = 10 MHz // Internal Osc w/PLL (FRC+PLL) // Clock out on OSCIO pin // WDT OFF // Other options are don't care // #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF #pragma config POSCMOD = OFF, FNOSC = FRCPLL, FPBDIV = DIV_8, OSCIOFNC = ON

Regards, Josh


Sat, 21 Jan 2012 19:28:33 +0000

I used your configs and had a while loop toggle a pin.


The disassembly looks like each line is two instructions. I then scoped the pin and got the on time to be ~196ns. So each instruction takes 98nS ~ 10MHz. Any ideas? Is it like the 8bit pics where the instruction clock is FOSC/4?


Mon, 23 Jan 2012 17:48:00 +0000


The likely reason your pin was toggling slower than expected is you were not enabling the cache/prefetch using SYSTEMConfigPerformance(). Performance is also effected by compiler optimization.

To determine the oscillator frequency I would recommend enabling CLKO. It can be difficult to determine the clock rate by execution speed since it can vary depending on other settings in the device, the code, and optimization level. Enabling CLKO allows measuring the oscillator directly. Since the UNO32 has an external oscillator connected to this pin, it is not a viable option in this case.

The provided code example is using a timer which is another way of making your timing less sensitive to other factors. The timer is clocked by the selected clock source in a predictable fashion. The timer is set to operate with an 80MHz internal oscillator, with a one second period.

Regards, Josh


Mon, 23 Jan 2012 18:02:48 +0000

I was actually just about to post a reply. In the end it was the optimization settings. I followed this thread and now the pin toggles at ~12MHz. I also did the timer example from another source, and measured the clock CLKO pin and got 80MHz.

So thank you for the info, as you were correct.