Sampling Rate Timecode Problem Arduino-ECG

Hi. I use Arduino UNO Rev.3 and MySignals HW (eHealth Medical Development Shield for Arduino) to measure heart rate. I have a problem with the sampling rate: I have a sampling frequency of 500 Hz, which means data should come at the rate of 2 milliseconds (ms). But this is not the case I see in csv. file, the difference between one sample to the next upcoming sampling is not always 2 ms and also it keeps changing throughout my log (sometimes the time stamp is identical but nevertheless the voltage changes, sometimes the time value duplicated and triplicated).
E.g.
time (hh:mm:ss.ffffff), voltage,
13:14:16.341084;1.92;
13:14:16.341585;1.94;
13:14:16.341585;1.86;
13:14:16.341585;1.76;
13:14:16.342087;1.72;
13:14:16.342087;1.77;
13:14:16.342588;1.87;
13:14:16.342588;1.94;
13:14:16.343090;1.92;
13:14:16.343090;1.82;
13:14:16.343591;1.74;
13:14:16.343591;1.74;
13:14:16.343591;1.73;

#include <MySignals.h>
#include “Wire.h”
#include “SPI.h”
void setup()
{
Serial.begin(115200);
MySignals.begin();
}
void loop()
{
float ECG = MySignals.getECG(VOLTAGE);
//Serial.print(“ECG value : “);
Serial.println(ECG, 2);
//Serial.println(” V”);
// wait for a millisecond
delay(1);
}

This will cause problems as I will try to have trigger points in data, to measure the time difference between the trigger point and one previous R peak. When there is more than one time stamp, it is not possible to measure.

My question is:
How can I get one sample in every millisecond (1000Hz) ? What I eventually need to see is something like this:
time (hh:mm:ss.ffffff), voltage
13:14:16.341585; 1.94;
13:14:16.342087; 1.72;
13:14:16.343090; 1.92;

Thank you very much in advance!

Try printing millis or probably better, micros to get your timestamp. I’m not convinced (from the look of your data) that you can rely on the serial monitor for the timing accuracy you’re looking for.

Use delayMicroseconds (900) instead of delay (1).
delay (1) varies between 0.x ms (!) and 1.x ms, so it is too inaccurate for your purposes.

You can then adjust the value for delayMicroseconds (...) until exactly 1.0 ms delay is reached.

wildbill:
Try printing millis or probably better, micros to get your timestamp. I'm not convinced (from the look of your data) that you can rely on the serial monitor for the timing accuracy you're looking for.

Thank you, we solved it with millis!

RudolfAtRTC:
Use delayMicroseconds (900) instead of delay (1).
delay (1) varies between 0.x ms (!) and 1.x ms, so it is too inaccurate for your purposes.

You can then adjust the value for delayMicroseconds (...) until exactly 1.0 ms delay is reached.

Thank you!