2009/02/18 02:45:50

I'm new to the PIC32MX-Family, so here is my problem:
I have tried to write some data to an external ADC via the I/O pins, but the SCLK-frequency was way beyond my expected value. So i tried the following code to check the fastest speed to toggle an Output, but it results only in 1.25 Mhz...

-EC with PLL (I use an oscillator with 4 MHz)
-PLL-Input-Divider 1x
-PLL-Output-Divider 1x
-PLL-Multiplier 20x
-PBDIV 1x  

Therefore the SYSCLK should be 80 MHz. I have already checked that on the CLKO-Pin. The PBCLK also works correct, i have checked that via the UART.
So here is my code:

int main (void){
_CP0_SET_STATUS(0x0000000); //disable all interrupts... just to be sure.
while (1){

Why toggles it so slow??? I cant imagine that the controller needs 64 operation cycles for a simple branch and an atomic(!) operation.
I'm pretty sure I made a stupid mistake, but so far i cant find a hint in the manuals.

Best Regards,


2009/02/18 02:54:01
Sorry, i have forgotten the initialisation of the PORTE. Naturally the TRISE is set correctly, for example: TRISE=0xFFFE;

Thanks in Advance!
2009/02/18 04:26:58
  This one keeps coming up (or variations on it! Smile).
When you start up PIC32 regardless of the oscillator fuse settings that you have specified it starts with
NO Caching turned on
NO Prefetch buffer enabled
7 FLASH wait states
1 SRAM wait states.
All of these items will affect the performance of your code and cause it to run significantly slower than you would expect.
So as a rule put in the very first line of your main function the following:
where the number in brackets is your chosen final instruction clock rate. This function will correctly set up the performance features of the PIC32 with the correct number of FLASH and RAM wait states for the chosen speed and will also enable caching and prefetch.
Set this up first and see what speed you get. You should find it much faster. You will then need to tinker with the compiler optimization settings to improve the performance some more.
2009/02/18 06:01:16
Hi DaytonaFiend!

Wow, this works! At the moment I'm curios where the definition of SYSTEMConfigPerformance() is, but nevertheless, it increased the speed significant.
I wasn't aware that i have to set the BMXCON and CHECON registers...  as a user of the 16bit-uC's it is sometimes very hard to get into the 32MX-Family, because everything is different and more complex, the manual is very huge and the time to get your project running is getting less. I'm sure you're familar to that.
You were really a great help, thanks!


2010/07/13 03:42:56
Hi Bodo, the code for SYSTEMConfigPerformance is:

extern inline unsigned int __attribute__((always_inline)) SYSTEMConfigPerformance(unsigned int sys_clock)
    // set up the wait states
    unsigned int pb_clk;
#ifdef _PCACHE
    unsigned int cache_status;
    unsigned int int_status;

    pb_clk = SYSTEMConfigWaitStatesAndPB(sys_clock);



#ifdef _PCACHE
    cache_status = mCheGetCon();
    cache_status |= CHE_CONF_PF_ALL;


    return pb_clk;


It is defined in system.h in \Microchip\MPLAB C32 Suite\pic32-libs\include\peripheral.

I hope that helps,
2010/10/22 01:19:54
i try this code with a PIC32MX460F512L and 4MHz external quartz with C32 V1,11b:
#include <p32xxxx.h>
#include <plib.h> 
#pragma config FPLLODIV=DIV_1
#pragma config FPLLMUL=MUL_20
#pragma config FPLLIDIV=DIV_1
#pragma config FWDTEN=OFF
#pragma config FPBDIV = DIV_1
#pragma config OSCIOFNC = ON   
#pragma config POSCMOD=XT
#pragma config FSOSCEN = OFF
#pragma config FNOSC=PRIPLL
#pragma config CP = OFF   
#pragma config BWP = OFF
#pragma config PWP = OFF   

#define SYS_FREQ    (80000000L)

    AD1PCFG = 0xFFFF;

    DDPCONbits.JTAGEN = 0;
    TRISA = 0xff00;

    while (1)
       PORTAINV = 0x34;

i mesure on RA2 a clock signal 8MHz, 125ns by clock cycle.
if i replace the line PORTAINV by two lines: LATASET and LATACLR, i mesure a 10MHz clock signal, 100ns.
if i remove the line SYSTEMConfigPerformance i mesure 1,25MHZ clock signal so i understand that SYSTEMConfigPerformance improve performance on the PIC32 but it is again very slow.
whith this PIC32 RA2 is up since 65ns and when i do the same test with a dsPic30 the result is 37ns.
i'm sure i forget or i do something wrong, it is the reason i post in your forum to obtain some explanations from PIC32 specialists.
thank you for you help ;-)
2010/11/30 10:47:47
I am using a PIC32MX695

It seems the magic SYSTEMConfigPerformance(80000000L);
doesn't work at all. To Check it I toggle a Port Pin and I see the result on the scope. For the same settings (pragma's) the PIC32MX360 runs 5 times faster.

Any clue ?

2010/12/23 04:46:36

I am using a PIC32MX695

It seems the magic SYSTEMConfigPerformance(80000000L);
doesn't work at all. To Check it I toggle a Port Pin and I see the result on the scope. For the same settings (pragma's) the PIC32MX360 runs 5 times faster.

Any clue ?


I found out the reason, the 24 Mhz signal was input into a CPLD . The CPLD pull up input was on, sufficient to crash the 24 Mhz clock.
The PIC uses then its proper clock which is much slower....
My fault, no excuse.

2011/01/24 19:36:53
2011/07/15 15:26:54
I've run into the same problem as above, however I have come to no solution. No matter what settings I put for the clock, it always toggles the port at 1.5MHz (output from a scope). Any help on this matter would be appreciated. Below is my code
// -----------------------------------------------------------------------------
// Section: Includes
// -----------------------------------------------------------------------------

#include <p32xxxx.h>
#include <plib.h>

// -----------------------------------------------------------------------------
// Section: PIC32MX795F512L Configuration bits
// -----------------------------------------------------------------------------

#pragma config FPLLODIV = DIV_1  // Default Postscaler for PLL bits
#pragma config FPLLMUL = MUL_20  // PLL Multiplier bits
#pragma config FPLLIDIV = DIV_1  // PLL Input Divider bits
#pragma config FPBDIV = DIV_2    // Peripheral Bus Clock Divisor Default Value bits
#pragma config FNOSC = PRIPLL    // Oscillator Selection bits
#pragma config OSCIOFNC = OFF    // CLKO Enable Configuration bit
#pragma config POSCMOD = XT      // Primary Oscillator Configuration bits
#pragma config FSOSCEN = OFF     // Secondary Oscillator Enable bit
#pragma config FCKSM = CSDCMD    // Clock Switching and Monitor Selection Configuration bits
#pragma config FWDTEN = OFF      // Watchdog Timer Enable bit
#pragma config CP = OFF          // Code-Protect bit
#pragma config BWP = OFF         // Boot Flash Write-Protect bit
#pragma config PWP = OFF         // Program Flash Write-Protect bits
#pragma config DEBUG = ON        // Enable Debugger
#pragma config ICESEL = ICS_PGx2 // Programmer/Debugger Channel

// -----------------------------------------------------------------------------
// Section: System Macros
// -----------------------------------------------------------------------------

#define FYC       (80000000ul)
#define GetPeripheralClock()  (FYC/(1 << OSCCONbits.PBDIV))
#define GetInstructionClock()  (FYC)

int main()
 // Configure the system

 DDPCONbits.JTAGEN = 0;  // Disable JTAG port, free up PORTA
 TRISAbits.TRISA0 = 0;  // Set RA0 to output
 while (1)
  LATAINV = 0x0001;  // Invert RA0
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account