HP 1630G and C
I obviously had to rewrite the test in C and see what the speed becomes, how fast that goes, how fast one can switch the GPIO ports of a Raspberry Pi from a C program. I expected it would go faster, but I did not think the difference is going to be this much for sure.
First of all, here is the C code that does the same we saw from the BASH script.
#include <gpio.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
time_t start;
if (gpioInitialise() < 0)
{
fprintf(stderr, "pigpio initialisation failed\n");
return 1;
}
gpioSetMode(2, PI_OUTPUT);
gpioSetMode(3, PI_OUTPUT);
gpioSetMode(4, PI_OUTPUT);
gpioSetMode(17, PI_INPUT);
gpioSetMode(27, PI_OUTPUT);
gpioSetMode(22, PI_OUTPUT);
start = time_time();
while ((time_time() - start) < 180)
{
gpioWrite(2, 0);
gpioWrite(2, 1);
gpioWrite(3, 1);
gpioWrite(3, 0);
gpioWrite(3, 1);
gpioWrite(3, 0);
gpioWrite(4, 1);
gpioWrite(4, 0);
gpioWrite(17, 1);
gpioWrite(17, 0);
gpioWrite(27, 1);
gpioWrite(27, 0);
gpioWrite(22, 1);
gpioWrite(22, 0);
}
gpioTerminate();
return 0;
}
And here is how I compiled and run the code:
$ gcc -o pulse pin2.c -lpigpio -lrt -lpthread $ sudo ./pulse
The signal looks kind of similar, but wait, the time-base is completely different! Now we are in the 10ns sampling rate, that is the limit of the HP 1630 analyzers speed. An so the pulse width is now 120ns instead of 80μs. That's about three orders of magnitude, the C program switches the GPIO 1000 times faster than the shell script did!
Well, kids, it worth learning C, right? ;)
Wonder what if I measure the frequency, how stable that would go? Hmmm...