Sample time of different sensor readings

Hi, I have just started using Arduino Uno and ehealth shield. Getting serial data from sensors was easy but there is a naive question that is bothering me.

AtMega328P has a single CPU core and as I am getting sensor readings from two sensors, how can I get accurate time(millis) when the sample is taken. In simple words, how can I be sure that at a certain time, corresponding reading came from a specific (lets say first) sensor. There ought to be some delay in getting accurate time measurements.

What kind of sensors? How accurately must the time measurements coincide? A link to the ehealth shield please?

Espresso_Unleashed: There ought to be some delay in getting accurate time measurements.

Why? You call millis() and it tells you how long it has been since the board last reset. Why should there be any delay?

Have you read this

IMPORTANT: The e-Health Sensor Platform has been designed by Cooking Hacks (the open hardware division of Libelium) in order to help researchers, developers and artists to measure biometric sensor data for experimentation, fun and test purposes. Cooking Hacks provides a cheap and open alternative compared with the proprietary and price prohibitive medical market solutions. However, as the platform does not have medical certifications it can not be used to monitor critical patients who need accurate medical monitoring or those whose conditions must be accurately measured for an ulterior professional diagnosis.

@aarg: pulse oximetry and breath sensors. The exact time measurement when the data is received by the uC, from the two sensors. Link is below: (In case its not displayed properly, please go to cooking-hacks.com.

@Delta_G: According to millis description: Quote: Returns the number of milliseconds since the Arduino board began running the current program. As I am receiving data from two different sensors, in one program (two analogue ports), there can be a delay due to single thread. (not sure on this 100% though). Or can I be certain that at a particular time, the reading was taken from breath sensor and at the other instance it was taken from pulse oximetry. Pseudo-code below

var alpha = millis();
var dat1 = getDataPulseOxi();
var beta = millis();
var dat2 = getDataBreath();

Now the delay I am talking about is between the execution of 1st instruction and 2nd instruction. Plus the delay which I am in doubt is, getData functions are sending the data to uC continuously. So can I be certain that var aplha will store the time a value is received from Pulse Oximetre and beta will store the time when uC receives a value from breath sensor. Just to finalize, talking about two delays here. Please let me know, if it makes sense or not.

@BillHo: Yes its purely for research purpose.

"So can I be certain that var aplha will store the time a value is received from Pulse Oximetre and beta will store the time when uC receives a value from breath sensor. "

If you don't over right the variables with new data, then the answer is YES. They will have the value of the milli() at the time each of the readings were started. It is likely that the two times (milli()) could be the same, since the arduino can loop over 100 times in one millisecond.

We do not know how long each of the functions will take tho.

@jack_wp: Exactly my thought. I get that when millis() is executed, it will store time unless over-written. But I need to get the precise time a uC receives a reading from pulse oximetry sensor and the precise time it receives a reading from breath sensor. Could there be any workaround? not two uC please :slight_smile:

Do you mean you need the time (like year/month/day/hour/minute/second ) ? That can be done if it is your need.

I am puzzled. Breath and heartbeat need to be measured to an accuracy of millionths of a second? Are you building a bionic man?

aarg: I am puzzled. Breath and heartbeat need to be measured to an accuracy of millionths of a second? Are you building a bionic man?

Millisecond does not mean millionths of a second (even tho it does sorta sound like it). It is one thousandths of a second.

[quote author=jack wp link=msg=2394688 date=1442109028] Millisecond does not mean millionths of a second (even tho it does sorta sound like it). It is one thousandths of a second. [/quote] I know. I was addressing reply #6.