GARTHWILSON wrote:
I was just watching a YouTube video last night about a 32-bit 80MHz PIC32 where the man was demonstrating the speed, but he programmed it in C and a loop to flash an LED only got about a million flashes per second.
I think I found the video
here. The guy isn't really making any sense. I tried it myself. The C code is just this:
Code:
while( 1 )
PORTFINV = (1 << 3);
The PORTFINV register is the 'invert' register for PORT F, and writing a '1' inverts the corresponding bit. Despite the man's explanation that this is a C compiler, and writing to the port is translated to "a bunch of code", the C compiler turns this into minimal code:
Code:
9fc00114: da80 sw a0,0(v0)
9fc00116: 17fe b 9fc00114
The reason this executes so slowly is probably because he used the default settings for the chip, which is to run with cache disabled, and 7 wait states on the flash. With cache enabled, speed is about 17M toggles/sec, including the loop overhead.
And if you unroll the loop, and use SET/CLR registers instead of INV, it will run at a full 80M changes/sec.