Hello everyone!
I need to log 1 byte at 5kHz speed to SD card, it's like 9 bit input, one of them is clock and I use it for interrupt. Here is the code:
#include <SD.h>
#include <SPI.h>
File dataFile;
void setup() {
Serial.begin(250000);
Serial.print("Initializing SD card...");
if (!SD.begin(10, 11, 12, 13)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
attachInterrupt(2, beep, RISING);
if (SD.exists("datalog.txt")) {SD.remove("datalog.txt");}
dataFile = SD.open("log.hex", FILE_WRITE);
DDRF = B00000000;
}
void loop() { }
void beep() { dataFile.write(PINF); }
there is another arduino which generates bytes and I can control the frequency. Here is the code for that too:
int var =0;
bool output = HIGH;
void setup() {
DDRD = DDRD | B10000000;
}
void loop() {
if (output == HIGH) {
PORTD = byte(var);
var=var + 1;
}
PORTD = PORTD ^ B10000000;
output = !output;
delayMicroseconds(1000);
}
I know it is not perfect but at least it implements the device that sends bytes.
The default SD library is too slow, as I need to log each byte for less that 200 microseconds.
I use Arduino Mega with Adafruit data logging shield. So the main question is, how can I improve the logging speed?
I read the fat16lib's topic about logging 40 000 samples per second, but he uses timer for logging and I need to use an interrupt. I could not understand the example he wrote, as you can see, noobie here. A little guidance on what to learn or what to change would help, as it is not the first time i get into algorithms.
Thanks in advance!
Regards,
Javid Yagubali