Sensor Interfacing and data rates

Hi,

I am using UNO. I got four sensors that I need to sample using on board ADC. I want to sample six sensors after every 20 minutes.

I am a beginner so, I do not have good idea to go about this issue. Should I go with interrupt based software? if yes, then can anyone give me some examples or guidelines to follow. Can I read every pin of the ADC individually?

The sensors are really slow analog devices and their output does not exceed 10 Hz.

The on board ADC is 10 bits with sampling frequency of 10k Samples / second. I read about UNO's sampling rate at the following link

I tried to do some data rate calculations

Data rate : Sampling rate x Number of channels x ADC resolution = 10k x 6 x 10 = 600kbits/sec.

I do not know what will be ADC switching speed at which the ADC will go through the six channels. Any suggestions here. I meant how much time the microcontroller will take to move from one channel to another. Does the UNO microcontroller has the ability to handle 600kbits? Where would it store it? etc. Any more suggestions and ideas are welcome!

erica

Should I go with interrupt based software?

To sample 6 sensors over 20 minutes? No!

Can I read every pin of the ADC individually?

Yes.

Data rate : Sampling rate x Number of channels x ADC resolution = 10k x 6 x 10 = 600kbits/sec.

You can't sample all the pins at that rate. You can sample ONE pin at that rate. When you switch pins, the ADC needs time to deal with the new input. Typically, one would read the new pin twice, and throw away the first value. That will cut the sample rate by a factor of 12 if you are reading all 6 pins.

Does the UNO microcontroller has the ability to handle 600kbits? Where would it store it?

It can't store that much data anywhere. The only way to get the sample rate quoted is to read one pin and do nothing with the data.

PaulS:
To sample 6 sensors over 20 minutes? No!
Yes.
You can't sample all the pins at that rate. You can sample ONE pin at that rate. When you switch pins, the ADC needs time to deal with the new input. Typically, one would read the new pin twice, and throw away the first value. That will cut the sample rate by a factor of 12 if you are reading all 6 pins.
It can't store that much data anywhere. The only way to get the sample rate quoted is to read one pin and do nothing with the data.

I do want to sample one pin at one time using 10kSamples/ sec then I want to move to the next ADC channel and then next. What is that switching time from one channel to another?

I need to collect the data from all the available channels and send it out every hour. I am confused how should I do this kind of calculations. I know that I am collecting 600kbits / sec but how can I stretch this calculation for every hour mathematically.

I guess I need a microcontroller with bigger RAM. How much bigger RAM should I go with? Should I go with microcontroller available on the MEGA 5650 board?

Should I use a Timer to generate an interrupt every hour to collect the data from each of the six pins> Can you advise how will that work or how should I design it?

erica

No need for an interrupt for something that slow. Just look at millis. Use the technique from the Blink Without Delay example to see when an hour has passed.

Delta_G:
No need for an interrupt for something that slow. Just look at millis. Use the technique from the Blink Without Delay example to see when an hour has passed.

I was hoping to do the interrupt to learn more about microcontroller programming.

Then choose some project that actually needs one. Thing number one to learn about interrupts is to use them when necessary and don’t use them otherwise.

@Erica1989, please explain what you are trying to achieve without reference to how that might be done.

I cannot conceive of why you mention "10k Samples / second" when you only need to read something every 20 minutes.

...R

" I got four sensors that I need to sample using on board ADC. I want to sample six sensors after every 20 minutes."

I am not clear.

  1. Do you have four or six sensors to sample (ever 20 minutes)?
  2. Do you need to sample all them within the same second, or can you sample them throughout the 20 minutes?

Robin2:
@Erica1989, please explain what you are trying to achieve without reference to how that might be done.

I cannot conceive of why you mention "10k Samples / second" when you only need to read something every 20 minutes.

...R

As I said in first post that I am a beginner and do not know much about embedded programming. So, 600kbits is a good number if I read all the sensors in one second. But I want to read the sensors every 20 minutes. So. 20 minutes is equal to 1200 seconds

so, now the data rate will be equal to 6 x 10,000 x 1200 = 72Mbits /sec. That can not be right!

  1. I want to sample six sensors ( every 20 minutes) , four temperature sensors and two light sensors.
  2. I want to sample all of them within same second.

I am sorry for asking such basic questions. I will appreciate help.

Erica1989:

  1. I want to sample six sensors ( every 20 minutes) , four temperature sensors and two light sensors.
  2. I want to sample all of them within same second.

I am sorry for asking such basic questions. I will appreciate help.

This is what I am thinking. I need to sample six sensors after every 20 minutes.

So, what does it mean that 10bits + 10bits + 10bits + 10bits + 10bits + 10bits = 60 bits every 20 minutes.

Is it good idea to program the timer to trigger the interrupt every 20 minutes?

So, the data rate would be 0.05 bits /sec. I am so confused. I am also confused about taking into account the switching time of the ADC among all six sensors. Please help!

erica

Anyone!

Erica1989:
This is what I am thinking. I need to sample six sensors after every 20 minutes.

So, what does it mean that 10bits + 10bits + 10bits + 10bits + 10bits + 10bits = 60 bits every 20 minutes.

That makes a lot more sense than thinking that reading once every 20 minutes would equal the maximum sample rate. Since Arduino doesn't have a 10bit type the analogRead values are going to come in as ints with the top 6 bits 0s. So really you're getting 12 bytes every 20 minutes.

Erica1989:
Is it good idea to program the timer to trigger the interrupt every 20 minutes?

That's already been answered at least once.

Erica1989:
So, the data rate would be 0.05 bits /sec. I am so confused. I am also confused about taking into account the switching time of the ADC among all six sensors. Please help!

Why are you so worried about the sample rate? The arduino can take 10,000 analog readings in one second. If you're only taking 6 every 20 minutes I don't think the switching time is going to have much effect on you will it? You'll be able to get your 6 readings in under a millisecond or maybe 2 and then do nothing for 20 minutes. Is that not fast enough?

PS: Don't bump your own thread without adding some extra information of some kind. That's pretty frowned on around here. If folks aren't responding fast enough for you then maybe it's because your question really isn't making much sense.

Delta_G:
That makes a lot more sense than thinking that reading once every 20 minutes would equal the maximum sample rate. Since Arduino doesn't have a 10bit type the analogRead values are going to come in as ints with the top 6 bits 0s. So really you're getting 12 bytes every 20 minutes.

That's already been answered at least once.

Why are you so worried about the sample rate? The arduino can take 10,000 analog readings in one second. If you're only taking 6 every 20 minutes I don't think the switching time is going to have much effect on you will it? You'll be able to get your 6 readings in under a millisecond or maybe 2 and then do nothing for 20 minutes. Is that not fast enough?

PS: Don't bump your own thread without adding some extra information of some kind. That's pretty frowned on around here. If folks aren't responding fast enough for you then maybe it's because your question really isn't making much sense.

The issue is not about whether the microcontroller is fast or not. Its about my understanding. I can not understand how to calculate the data rate. I am very new to embedded world. how much is the data rate if I sample six sensor individually after every 20 minutes? Can you help me to calculate it? Its simple math but I can not do it.

The data is coming in at 10kbits / second. You are reading for 600 millionths of a second.

It's simple math, not a programming exercise.

I don't really understand what you want to know.

You're actually sampling each sensor once per every 20 minutes. So the sampling rate of your sensors is 5 / hour. Divide by 60 to get 0.0833 samples / minute. Divide by 60 again and that's 0.0013889 samples per second.

When you say sampling rate you have to say what you mean. Do you mean how fast the uc is producing bits of data? That's one rate. How often you read the sensor? That's another rate.

Either way, you calculate it as samples (of whatever you want the rate of) divided by time.

  1. Do you have your arduino running this now?
  2. What results are you getting?
  3. If it is not what you expect, then how can we help?

Delta_G:
You're actually sampling each sensor once per every 20 minutes. So the sampling rate of your sensors is 5 / hour. Divide by 60 to get 0.0833 samples / minute. Divide by 60 again and that's 0.0013889 samples per second.

When you say sampling rate you have to say what you mean. Do you mean how fast the uc is producing bits of data? That's one rate. How often you read the sensor? That's another rate.

Either way, you calculate it as samples (of whatever you want the rate of) divided by time.

I am interested in both rates

a) how fast the microcontroller is producing bits of data and
b) how often the data is read from the sensor.

Am I correct to say that for case a) number of channels x resolution x sampling rate

6 x 10 x 10k = 600kbits /sec

Am I correct to say that for case b) number of channels x resolution x sampling rate

(6 x 10) / 3600 secs = 0.016 samples secs

So, now what data rate should I consider to design the software.

I am confused that If I choose case a then ATMEAG328P might not support it because it does not have big enough RAM. It has 512 KBytes of RAM and 256KBytes of EEPROM.

But then when I look at the problem from the case b perspective then it looks like the RAM can support this data rate and this ATMEAG328P can pull it off. I do not know what is correct way to go.

Erica

Erica1989:
I am interested in both rates

a) how fast the microcontroller is producing bits of data and
b) how often the data is read from the sensor.

STOP worrying about how fast the Arduino is - just forget it altogether for now.

Write a short program to take your six readings once every 1200 000 millisecs (I hope that is 20 minutes' worth) and see if it meets your requirement.

The Arduino is a great system for learning-by-doing.

...R

Erica1989:
I am confused that If I choose case a then ATMEAG328P might not support it because it does not have big enough RAM. It has 512 KBytes of RAM and 256KBytes of EEPROM.

You are very confused. If you want to know how many bytes of RAM you need then that has NOTHING to do with the sampling rate. It has to do with the number of samples you take. If you call analogRead six times in a row and each one returns an int then that's 12 bytes. It doesn't matter how fast you take those readings, six readings is 12 bytes. If you slow the sample rate down, 6 readings is 12 bytes. If you speed the sample rate up 6 readings is 12 bytes. The sample rate has absolutely nothing to do with how much RAM you need.

The only thing sample rate has anything to do with is how long it will take to get your six readings. If the sampling rate of the ADC is 10000kbit/sec then it will take 600microseconds to take 6 readings. But it only takes 12 bytes of RAM to store the results.