Time and Use of Accelerometer Data Rate

Hi everyone, so I'm thinking of starting a project with an accelerometer, and pretty much I want to get quite a large amount of data.

The thing is firstly I want to obtain accelerometer data at about 20hz, and I want to be able to save it in say an array and possibly do some adding or something with it. Would the arduino be fast enough to be able to save the INTeger values without slowing down my data rate? Secondly I was hoping to obtain those values by utilizing two things, first off I thought I would use a timer sort of thing to obtain accelerometer values (3 axis) at a twentieth of a second, the other thing is I want to have a real time of the data if possible and by real time I mean like 12:05 sort of thing. So I wondered if there was a real time function I could use that was accurate to the millisecond so that I could take samples at the rate I want without it blocking the system like a delay would in case I want to do something with that data in between while also being able to use it as a sort of clock for the speed I want.

It also might be better if I just use an on board clock, since I really only want the real time every minute or something like that.

If it helps I'm using the ATmega32u4 microcontroller. Thanks!!

I hope you are a good programmer and know electronics. Why do you want timing to the millisecond, and only 20 samples a second ? May the timing drift a little ?

An microSD card can be added to the Arduino, storing is about 4kbyte per second. The MPU-6050 with the i2cdevlib has a default sample rate of 100Hz. So up to 100Hz everything is okay and you can store the data. You can also send the data to the computer via the serial over usb communication.

The RTC ds1307 can be synchronized with the Arduino timing: http://playground.arduino.cc/Code/time Use the link to pcjr.com for the newer version: http://www.pjrc.com/teensy/td_libs_Time.html But I don't know about millisecond accuracy.

Caltoa: I hope you are a good programmer and know electronics. Why do you want timing to the millisecond, and only 20 samples a second ? May the timing drift a little ?

An microSD card can be added to the Arduino, storing is about 4kbyte per second. The MPU-6050 with the i2cdevlib has a default sample rate of 100Hz. So up to 100Hz everything is okay and you can store the data. You can also send the data to the computer via the serial over usb communication.

The RTC ds1307 can be synchronized with the Arduino timing: http://playground.arduino.cc/Code/time Use the link to pcjr.com for the newer version: http://www.pjrc.com/teensy/td_libs_Time.html But I don't know about millisecond accuracy.

haha unfortunately I'm not sure if I'm good at either electronics or programming, but I do have a lot of time, and usually I learn better if I'm in a sink or swim type of position.

Thanks heaps though, well basically I was hoping to get 20 pieces of accelerometer data per second for 60 seconds, do something with all that data and end up with an INT value every minute with a real world time and date connected to it.

My first thought was to use the on board clock and then run an interrupt every 1/20th of a second to obtain accelerometer data, but then I thought if there was a millisecond function that also utilized time, it might help me save flash space and also control the time I obtain data from the accelerometer.

I probably could drift the timing a little if it helps? Thanks heaps for the links as well, I reckon I will definitely use that to get the proper time plus I know its accurate to at least the second.

  int [20] accelDataArray;  //your data
  int accelDataCount = 0; //count number of readings
  int prevTimer;  //get time of last reading
  int interval = 50;  //50ms = 20Hz
  void setup()
{NEWSLETTER

   prevTimer = millis(); //get a starting point for millisecond count
}

void loop()NEWSLETTER

{
  if(prevTimer >= prevTimer + interval) //using >= since it's possible 51 milliseconds can go by before this is reached
   {
     //read accelerometer
     prevTimer = prevTimer + 50;  //increment timer count
     accelDataCount++; //increment the number of readings made
   }
  if(accelDataCount == 20) //we have made 20 readings which means array is full and one minute has passed
  {
    //write your data with time stamp
    accelDataCount = 0;
  }
  //do other stuff
}

Is this kind of what your looking for? The only issue is that you may not get a reading at exactly 50ms intervals, but you should be relatively close. If your looking for super accurate intervals then using an interrupt would be the best way to go. One way you could achieve this would be hooking up an eternal pulse generator to an interrupt capable pin that is running at 20Hz.

int prevTimer;  //get time of last reading
 ...
   prevTimer = millis(); //get a starting point for millisecond count

It is not a good idea to use int variables with millis(), because the time is returned as an unsigned long integer. Use unsigned long integer variables.

Thanks heaps guys, and I really appreciate the sample code as well. I’m not too sure how accurate my data must be, but I’m hoping it won’t need to be too accurate. I think for now I might use your sample code, and see how I go, and then later I can work on adding the clock and interrupts, I’m not sure if I’m adding any extra sensors to my board, so this would probably be the best way to prototype it.

Cheers guys.