• AVR Freaks

Helpful ReplyHot![FAQ]Why does my PIC32 run slower than expected?

Page: 12 > Showing page 1 of 2
Author
bodo
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2009/02/18 02:23:37
  • Location: Mainz, Germany
  • Status: offline
2009/02/18 02:45:50 (permalink)
0

Why does my PIC32 run slower than expected?

Hi!

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...

Device-Configuration:
-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){
     PORTEINV=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,

Bodo



post edited by JasonK - 2010/10/21 14:37:59
#1
bodo
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2009/02/18 02:23:37
  • Location: Mainz, Germany
  • Status: offline
RE: PIC32MX440FH toggles Ports very slow 2009/02/18 02:54:01 (permalink)
0
Sorry, i have forgotten the initialisation of the PORTE. Naturally the TRISE is set correctly, for example: TRISE=0xFFFE;

Thanks in Advance!
#2
DaytonaFiend
Administrator
  • Total Posts : 138
  • Reward points : 0
  • Joined: 2007/11/10 10:54:30
  • Location: Microchip Technology
  • Status: offline
RE: PIC32MX440FH toggles Ports very slow 2009/02/18 04:26:58 (permalink) ☄ Helpful
5 (6)
Hi,
  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:
 
SYSTEMConfigPerformance(80000000);
 
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.
 
..DF
 
#3
bodo
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2009/02/18 02:23:37
  • Location: Mainz, Germany
  • Status: offline
RE: PIC32MX440FH toggles Ports very slow 2009/02/18 06:01:16 (permalink)
0
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!

Bodo

#4
A.N.Other
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2010/07/08 06:24:55
  • Location: 0
  • Status: offline
RE: PIC32MX440FH toggles Ports very slow 2010/07/13 03:42:56 (permalink)
0
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;
#endif
    unsigned int int_status;

    pb_clk = SYSTEMConfigWaitStatesAndPB(sys_clock);

    int_status=INTDisableInterrupts();

    mBMXDisableDRMWaitState();

#ifdef _PCACHE
    cache_status = mCheGetCon();
    cache_status |= CHE_CONF_PF_ALL;
    mCheConfigure(cache_status);
    CheKseg0CacheOn();
#endif

    INTRestoreInterrupts(int_status);

    return pb_clk;

}

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

I hope that helps,
Andy
#5
capturator
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2010/10/22 00:20:00
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2010/10/22 01:19:54 (permalink)
0
Hi,
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)

main()
{
    SYSTEMConfigPerformance(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 ;-)
#6
flatbush
Senior Member
  • Total Posts : 124
  • Reward points : 0
  • Joined: 2009/01/30 07:51:14
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2010/11/30 10:47:47 (permalink)
0
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 ?

THX
#7
flatbush
Senior Member
  • Total Posts : 124
  • Reward points : 0
  • Joined: 2009/01/30 07:51:14
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2010/12/23 04:46:36 (permalink)
0
flatbush

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 ?

THX


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.


#8
Davis
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2011/01/24 18:28:40
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/01/24 19:36:53 (permalink)
0
post edited by Davis - 2011/01/24 19:40:28
#9
IES
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2011/07/05 16:08:53
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/07/15 15:26:54 (permalink)
0
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
 
[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
 SYSTEMConfig(FYC, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

 DDPCONbits.JTAGEN = 0;  // Disable JTAG port, free up PORTA
 TRISAbits.TRISA0 = 0;  // Set RA0 to output
 
 while (1)
 {
  LATAINV = 0x0001;  // Invert RA0
 }
}
[/CODE
]
 
#10
Kiwi Mike AZ
Super Member
  • Total Posts : 2044
  • Reward points : 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/07/15 15:34:49 (permalink) ☄ Helpfulby Maddy_me 2019/05/15 13:47:01
0
Instead of manually setting the wait states etc try: SYSTEMConfigPerformance(FCY);

It sets everything up for optimal operation at the freq you specify.

Also what optimization level is the compiler AND linker set to?

Mike


#11
forseeus
Starting Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2011/07/12 19:03:01
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/07/15 20:33:40 (permalink) ☄ Helpfulby Maddy_me 2019/05/15 08:15:21
0
I noticed that your code was running from flash memory.  You should know that the flash memory hardware on the PIC32 requires at least 2 wait states when running at over 60MHz.  See The PIC32MX5XX/6XX/7XX Family Data Sheet, Table 31-12 (page 192).

http://ww1.microchip.com/downloads/en/DeviceDoc/61156G.pdf

If your code was running from RAM you would not have any wait states.  I have personally measured 3X or more performance gains by running functions from RAM.  An example of how to do this is as follows...

void __attribute((section(.ramfunc))) myFunction(void){
   ...some code here...
}

Please note that running main() or ISRs from from RAM requires extra steps not showin in my example.

You can probably get the toggle rate up near 20MHz that way.
#12
Doctor_J
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2011/07/08 13:33:15
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/09/09 10:50:33 (permalink)
0
This is similar to what I have noticed in my own experiments. That is, my loop is running about 10x slower than expected.
I don't have an answer, but I will point out that I'm not sure the CPU can toggle an output pin at the maximum clock rate. I tried it myself, but I only had a multimeter, not an oscilloscope handy, but it wasn't displaying a measured frequency.
 
bodo

Hi!

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...

Device-Configuration:
-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){
    PORTEINV=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,

Bodo


#13
Kiwi Mike AZ
Super Member
  • Total Posts : 2044
  • Reward points : 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/09/09 10:53:26 (permalink)
0
Try adding SYSTEMConfigPerformance(80000000L); before your while(1)
#14
leduardocl
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2011/09/26 18:14:58
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/09/26 19:31:36 (permalink)
0

Have you tried this?:

#include <plib.h>

#define GetSystemClock() 80000000
int main()
{
     SYSTEMConfigPerformance(GetSystemClock());
}
#15
joshh
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2008/05/10 23:04:40
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/10/04 22:07:18 (permalink)
4 (1)
Out of curiosity is...

SYSTEMConfig(80000000, SYS_CFG_ALL) == SYSTEMConfigPerformance(80000000);

It looks like it is, but unsure.
#16
viewgsm
Starting Member
  • Total Posts : 78
  • Reward points : 0
  • Joined: 2007/02/28 15:27:10
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2011/12/31 05:42:45 (permalink)
0
well, I have to say I came across this post and I thought to give it a try, 
without the SYSTEMConfigPerformance(80000000);  the scope shows 1 MHz on RD1
with the SYSTEMConfigPerformance(80000000);  I get 8 MHz on RD1 !!!!!
amazing... however I don't get extra performance on the TCP tasks

regards



post edited by viewgsm - 2012/01/01 02:47:27
#17
seccoxiru
Junior Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2011/10/27 13:42:59
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2012/03/08 05:18:31 (permalink)
0
Hi.

What do this function do with the CPU (not the peripheral bus) clock?

SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

I set both CPU and peripheral clock to 80MHz in the Config Bits. 

The peripherals were running at 80MHz correctly, but the CPU not (It was running slower than expected). When I put this command line im my FW [  SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);  ] the CPU began to run at 80MHz too.

I was using this define in both situations (when the CPU clock was wrong and correct): 
#define SYS_FREQ (80000000)

OBS: The peripheral clock was running correctly at 80Mhz in both situations
post edited by seccoxiru - 2012/03/08 05:24:18
#18
mikemarz
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2012/11/24 17:23:02
  • Location: California
  • Status: offline
RE: PIC32MX440FH toggles Ports very slow - A Solution 2012/12/13 18:40:58 (permalink)
0
The PIC32 will toggle pins at an 80 MHz rate (every 12.5 nSec) on the PIC32 starter kit.  Here’s how…
 
Use MPLAB v8.88
Use the MPLAB PIC32 C compiler (NOT the XC32 C Compiler)
Use the original port_io.c code.  It configures the PIC32 for max speed.
 
In Project->Build Options-> Project
            Select the C Compiler->Optimization and set it to Level 3.
            The optimization string becomes:
            -g -DPIC32_STARTER_KIT -O3
 
During a build it will say:
port_io.c:1:0: warning: Compiler option (Optimization level) ignored due to lite-mode limitations
This is NOT true.  The optimization works and things run slower if the –O3 is missing.
 
Modify the code in port_io.c to the following and use a ‘scope to watch Port D bit 1 toggle.
Notice that the “while” is slow and causes a gap in the bit toggling.
 
If you were to use the original bit set & bit clear instructions:
            PORTSetBits(IOPORT_D, BIT_1);
            PORTClearBits(IOPORT_D, BIT_1);
The pin toggles at a 200 nSec rate or 16X slower.  I dunno why.  Just use the fast version.

This morning I got concerned that the compiler might be fast for some period of time and then the optimization quit.  Without the -O3 the pins toggle at 37.5 nSec, 3X slower.  

Mike
 
            while(1)
   {
                        mPORTDSetBits(BIT_1);
                        mPORTDClearBits(BIT_1);
                        mPORTDSetBits(BIT_1);
                        mPORTDClearBits(BIT_1);
                        mPORTDSetBits(BIT_1);
                        mPORTDClearBits(BIT_1);
 /*           if(PORTDbits.RD6 == 0)                                                          // 0 = switch is pressed
              {
                        PORTSetBits(IOPORT_D, BIT_0);                                   // RED LED = on (same as LATDSET = 0x0001)
                        if(last_sw_state == 1)                                                    // display a message only when switch changes state
                        {  
                            DBPRINTF("Switch SW1 has been pressed. \n");
                            last_sw_state = 0;
                        }   
              }
              else                                                                                                                // 1 = switch is not pressed
              {
                        PORTClearBits(IOPORT_D, BIT_0);                                 // RED LED = off (same as LATDCLR = 0x0001)
                        if(last_sw_state == 0)                 // display a message only when switch changes state
                        {
                            DBPRINTF("Switch SW1 has been released. \n");
                            last_sw_state = 1;
        }
              }         */
 
 
post edited by mikemarz - 2012/12/14 08:24:00
#19
Aladin
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2012/12/15 15:58:57
  • Location: 0
  • Status: offline
Re:Why does my PIC32 run slower than expected? 2012/12/15 16:25:55 (permalink)
0
Hello please advice where I can find a table for ...
pic32mx795 tables to... void __ISR( _TIMER2_VECTOR, ip14){.... ip17=? ip??=? ip??=? ip??=?
????????????????? ip14 ??????????????????
????????????????? ip17 ??????????????????
Thank you Regards Aladin
Czech Land
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5