How fast is the LinkIt?
The answer is 312 ns +/- 5 ns or about 3.2 MHz. I coded this simple toggle program:
#include <stdio.h>
#include <string.h>
#include "mraa/gpio.h"
#include "mraa/common.h"
#include <stdbool.h>
int main(int argc, char** argv)
{
mraa_gpio_context gpio = NULL;
const char* board_name = mraa_get_platform_name();
int pinstate = 0;
gpio = mraa_gpio_init(0);
fprintf(stdout, "Welcome to libmraa\n Version: %s\n Running on %s (Ctrl+C to exit)\n", mraa_get_version(), board_name);
if (gpio == NULL) {
fprintf(stdout, "Could not initilaize gpio\n");
return 1;
}
mraa_gpio_dir(gpio, MRAA_GPIO_OUT);
pinstate = 0;
while (true) {
mraa_gpio_write(gpio, pinstate);
pinstate = !pinstate;
}
return 0;
}
By comparison using the PINX command for an Arduino (Nano) was 375 ns +/-33ns:
void setup() {
// initialize the digital pin as an output.
pinMode(2, OUTPUT);
}
void loop() {
while (true) {
PIND=B00000100;
}
}
Not using PINX, it is still 375 ns but the duty cycle is about 33%:
void setup() {
// initialize the digital pin as an output.
pinMode(2, OUTPUT);
}
void loop() {
while (true) {
PORTD|=B00000100;
PORTD&=B11111011;
}
}
If your wondering what straight Arduino code would look like (i.e. less the direct port manipulations):
void setup() {
// initialize the digital pin as an output.
pinMode(2, OUTPUT);
}
int state=0;
void loop() {
while(true) {
digitalWrite(2,state);
state=!state;
}
}
But now it takes 11.12 us!
Now there is upside for the LinkIt with direct port manipulations as well but this is a project for another day!
AlanX
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.