Consistant sampling time for data logging?

04 May 2010 . Edited: 04 May 2010

Hi all.
I am having some problem with real time data logging. Currently, I want to sample analog accelerometer at 300s/sec. However, I am having some difficulty because mbed  takes 20ms to write a chunk of 512byte buffer to flash, and I cannot sample during this writing process. This happens every 70 samples or so.

I am thinking maybe base my sampling interval on a timer interrupt. I hope this interrupt can somehow interrupt the writing process, thereby avoiding the sampling gap. For example, if my buffer is full and I have to write to flash, I want to be able to still record new sample during this writing process by using a interrupt vector.  My question is: will that work? And what happens to the interrupted writing process when im directed to interrupt vector? Also, should I have two buffers so that I dont currupt the them by using the interrupt?

Thanks for your help

04 May 2010

Hmm, how about first loading the chunk into a "online" buffer on the mbed, and then loading it to the flash afterwards?

Not sure when you can find the time to do it, but I wouldn't interrupt a write process to the flash.

11 May 2010 . Edited: 11 May 2010

Definitely a good idea to link the sample period to a timer interrupt - otherwise sampling jitter can do all sorts of nasty stuff to you data unless you know exactly what you're doing.

If you have enough RAM to spare I would definitely recommend double buffering the analogue data: at any given moment one buffer is being written to with data from the ADCs and the other buffer is for sending data to the flash. Buffer size is chosen such that the process of writing a full buffer to flash is completed in less time than filling a buffer with ADC readings. When the ADC read buffer is full start writing it to flash while pointing the data output of the ADCs to the other buffer.

Based on 2 assumptions I think it should be fine to interrupt while the LPC is writing to flash. First assumption is that you are referring to the LocalFileSystem flash device which is an Atmel AT45DB161. Second assumption is that the LocalFileSystem code uses the AT45's internal 512byte buffer when writing to the flash - this is what allows you to interrupt the LPC's write to the flash safely. I don't know what the overheads of the LocalFileSystem are, but I'd recommend writing data in blocks of much less that the 512B buffer size (e.g. 256 bytes).

Hope this helps more than confuses.

Good luck.

13 May 2010

Thanks

I will try it out!

14 May 2010

Jim Patterson wrote:

Definitely a good idea to link the sample period to a timer interrupt - otherwise sampling jitter can do all sorts of nasty stuff to you data unless you know exactly what you're doing.

If you have enough RAM to spare I would definitely recommend double buffering the analogue data: at any given moment one buffer is being written to with data from the ADCs and the other buffer is for sending data to the flash. Buffer size is chosen such that the process of writing a full buffer to flash is completed in less time than filling a buffer with ADC readings. When the ADC read buffer is full start writing it to flash while pointing the data output of the ADCs to the other buffer.

Based on 2 assumptions I think it should be fine to interrupt while the LPC is writing to flash. First assumption is that you are referring to the LocalFileSystem flash device which is an Atmel AT45DB161. Second assumption is that the LocalFileSystem code uses the AT45's internal 512byte buffer when writing to the flash - this is what allows you to interrupt the LPC's write to the flash safely. I don't know what the overheads of the LocalFileSystem are, but I'd recommend writing data in blocks of much less that the 512B buffer size (e.g. 256 bytes).

Hope this helps more than confuses.

Good luck.

Keeping to the flash page size helps, anything less and you end up having to supply a 3rd buffer and waste processor time tranferring the data about. Too big and you may not get it written in time and overflow your buffer.

14 May 2010

Jim Patterson wrote:

Definitely a good idea to link the sample period to a timer interrupt - otherwise sampling jitter can do all sorts of nasty stuff to you data unless you know exactly what you're doing.

If you have enough RAM to spare I would definitely recommend double buffering the analogue data: at any given moment one buffer is being written to with data from the ADCs and the other buffer is for sending data to the flash. Buffer size is chosen such that the process of writing a full buffer to flash is completed in less time than filling a buffer with ADC readings. When the ADC read buffer is full start writing it to flash while pointing the data output of the ADCs to the other buffer.

Based on 2 assumptions I think it should be fine to interrupt while the LPC is writing to flash. First assumption is that you are referring to the LocalFileSystem flash device which is an Atmel AT45DB161. Second assumption is that the LocalFileSystem code uses the AT45's internal 512byte buffer when writing to the flash - this is what allows you to interrupt the LPC's write to the flash safely. I don't know what the overheads of the LocalFileSystem are, but I'd recommend writing data in blocks of much less that the 512B buffer size (e.g. 256 bytes).

Hope this helps more than confuses.

Good luck.

Keeping to the flash page size helps, anything less and you end up having to supply a 3rd buffer and waste processor time tranferring the data about. Too big and you may not get it written in time and overflow your buffer.