VoCore Maximum Blink Frequency

Today I did some testing on the maximum blink frequency I could get out of the VoCore using the „sysfs„ GPIO interface. I used four different candidates:

  • A shell script
  • A Python 2.7 program, basically the one described here (gist)
  • A Micropython program, more or less the same as the above, but using native libc file IO trough FFI as described here (gist)
  • And finally a C program

To summarize up the code used here the relevant snippets:

Shell Test Code

while true                           
do                                   
  echo 1 > /sys/class/gpio/gpio12/value
  echo 0 > /sys/class/gpio/gpio12/value
done

Python/Micropython Test Code

pin = DigitalIO.get_output(GPIO12)

while True:
  pin.set()
  pin.clear()

Full source:

C Test Code

#include <sys/types.h<
#include <sys/stat.h<
#include <fcntl.h<

#define SYSFS_ENTRY     "/sys/class/gpio/gpio22/value"

static int f;

void gpio_init()
{
        f = open(SYSFS_ENTRY, O_WRONLY | O_SYNC);
}

void gpio_term()
{
        close(f);
}

void gpio_set(void)
{
        write(f, "1", 1);
}

void gpio_clear(void)
{
        write(f, "0", 1);
}

int main()
{
        gpio_init();

        for(;;)
        {
                gpio_set();
                gpio_clear();
        }

        gpio_term();

        return 0;
}

Results

The results measured through OpenBench Logic Sniffer:

Code Freq
Shell 1.2kHz
Micropython 1.6kHz
Python 2.7 0.7kHz
C 13kHz

Addition: I also tried the same from within a Kernel module. By doing so, I was able to get about 14kHz.

The clear winner is C (note, that it is essential for the performance to NOT open/close the FD each time, but keep it open), followed by Micropython and the shell script. At the end is Python with very poor performance (which I could not explain up to now).

Leave a Reply

You must be logged in to post a comment.