Time between samples

Hey all,

I want to store a sample every 5ms. I'm using extra RAM to buffer and the buffer is going to be overwritten by the new samples when it reached to end of the RAM capacity. However, I also want to do other stuff besides taking samples. How can I be sure that the time between two sensor values is approximately 5ms? I've got an RTC connected to my Arduino unit.

Thanks!

something like:
unsigned long time = micros()

void setup() {
}

void loop() {
if(micros()-time > 5000) {
time = micros();
//get samples
//do other stuff
}
// do some stuff here but be careful no to take to long (< 5mS)
}

every time through the loop it checks if 5mS elapsed if so zero time and get data and store

You may search for TimerOne library, or MsTimer 2

groundfungus:
// do some stuff here but be careful no to take to long (< 5mS)

That's the problem :slight_smile:

Magician:
You may search for TimerOne library, or MsTimer 2

Thx! That's exactly what I need!