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