Hi pepe,
I've made a lot of tests that I think it could be of your interest. What I saw is that there is a big difference using Atmel library for setting the pin output versus using a direct assignment to the register.
If you use GCC, you will see also that Optimizations Levels and Parameters play a big role in the toggle frequency. I've made the measurements with an Agilent Logic Analyzer. My board is an AT91SAM7S-EK.
- Using Atmel library
- Code:
Code:
#define PINO {1 << 3, AT91C_BASE_PIOA, AT91C_ID_PIOA, PIO_OUTPUT_1, PIO_DEFAULT}
const Pin pino[] = { PINO };
while(1){
PIO_Clear(pino);
PIO_Set(pino);
}
- Results:
No Compiler Optimization
Period: 1860ns (538kHz)
Duty Cycle: 960/1860 = 52%
- Writing straight to register
- Highly optimized
- Writing straight to register
- compiler parameters: -O1 -funroll-all-loops -fomit-frame-pointer
- Results:
Period: 125ns (8.00MHz)
Duty Cycle: 65/125 = 52%
In this test, for each 8 cycles, one had 187ns period. That give us an average of 7.67MHz.
Running from flash drops toggle frequency to 6MHz (5.68MHz average).
I think results still can be optimized a lot, if you write code in assembly and if you use other compiler parameters (assembler parameters in this case).
A good reference:
Optimization in GCC.
Regards,
Furuya