PaulS:
Lots of possible reasons. Without seeing your code, we’d only be guessing.
What I’m guessing, though, is that periodically, the output buffer fills up, and needs to be written to the card, and that takes time, during which your interrupt doesn’t fire on time.
dear Paul,
here is a simple code. It supposed to write some values every 50ms. The counter will show the number of each loop(or number of lines). it should reach to 12000 after 10min, but when the loop is finished i havesomething around 11920.
#include <SD.h>
#include<SPI.h>
#include<TimerOne.h>
#include<Wire.h>
File New;
int chipSelect=4;
float a=0.3456;
float b=0.5642;
float c=0.3467;
float d=0.0005;
float e=0.4512;
float f=0.1203;
float g=0.3222;
float h=0.5987;
float i=0.3402;
float j=0.6321;
unsigned long lastTime=0;
int flag=0;
long int counter=1;
int A=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(10,OUTPUT);
SD.begin(chipSelect);
Timer1.initialize(50000);
Timer1.attachInterrupt(intrpt);
while(!SD.begin(chipSelect)) { // Checking the availability of the SD card
Serial.println(“SD Card Error!”);
}
New=SD.open(“BBB.txt”,FILE_WRITE);
}
void intrpt(){
flag=1;
A++;
}
void loop() {
// put your main code here, to run repeatedly:
if(A>=200 && A<=12200){
if(flag==1){
counter++;
Serial.print(counter);Serial.print(" “);
Serial.print(a);Serial.print(” “);
Serial.print(b);Serial.print(” “);
Serial.print(c);Serial.print(” “);
Serial.print(d);Serial.print(” “);
Serial.print(e);Serial.print(” “);
Serial.print(f);Serial.print(” “);
Serial.print(g);Serial.print(” “);
Serial.print(h);Serial.print(” “);
Serial.print(i);Serial.print(” “);
Serial.print(j);Serial.println(” “);
New.print(counter);New.print(” “);
New.print(a);New.print(” “);
New.print(b);New.print(” “);
New.print(c);New.print(” “);
New.print(d);New.print(” “);
New.print(e);New.print(” “);
New.print(f);New.print(” “);
New.print(g);New.print(” “);
New.print(h);New.print(” “);
New.print(i);New.print(” “);
New.print(j);New.println(” ");
New.flush();
flag=0;
}
}
}