After some chatting in the forums about slow I/O, I thought it'd be worth capturing...
Here is the test code:
#include "mbed.h"
#include "PortOut.h"
#include "DigitalOut2.h"
BusOut bus(P1_24, P1_25, P1_26, P1_27, P1_28, P1_29, P1_30, P1_31);
PortOut port(PORT1, 0xFF000000);
DigitalOut out(LED1);
DigitalOut2 out2(LED2);
Timer t;
int main() {
t.start();
for(int i=0; i<1000000; i++) {
bus = 0;
bus = 0xFF;
}
printf("BusOut = %8d kHz\n",(int)( 1000.0 / t));
t.reset();
for(int i=0; i<1000000; i++) {
port = 0;
port = 0xFF000000;
}
printf("PortOut = %8d kHz\n", (int)(1000.0 / t));
t.reset();
for(int i=0; i<1000000; i++) {
out = 0;
out = 1;
}
printf("DigitalOut = %8d kHz\n", (int)(1000.0 / t));
t.reset();
for(int i=0; i<1000000; i++) {
out2 = 0;
out2 = 1;
}
printf("DigitalOut2 = %8d kHz\n", (int)(1000.0 / t));
} And here are the results based on an 8-bit BusOut, an initial PortOut and optimised DigitalOut design, maintaining the same API.
BusOut = 132 kHz (8-bit) PortOut = 5052 kHz (approx x38 speedup) DigitalOut = 1246 kHz DigitalOutv2 = 7384 kHz (approx 6x speedup)
These suggest a PortOut gives good results even with a nice clean API, and the DigitalOut can be sped up too. These seem like good potential additions to the API.
As BusOut is constructed from DigitalOut, that would naturally speed up too.
Please log in to post a comment.
Hi
I tried to test the code and have an error:
"Cannot open source input file "PortOut.h": No such file or directory (E5)" in file "/SpeedUpDigitalOut/main.cpp"
It's obvious that portout.h is missing
Where can i find that file? A search did not work. Also is good to have a link to all different xxx.h files. i keep searching for them for any project.
Sorry for asking but i m new to this and keep trying to navigate and test different codes.
Thanks
Thanos