Datalogger with memory stick
Mike87
Posts: 9
Hi,
I'm trying to do a simple datalogger for an accelerometer and I want to log X, Y and Z data on my usb key at 20 Hz. I'm using the Memory Stick Datalogger v1.1 object by Paul via uart at 9600 bps. I'm able to write my data to my usb key, but only at lower speed (4 hz). As you can see below, my code is really simple. Will it be faster if I used the SPI protocol instead of uart? And what about an SD card? Could it be faster then a memory stick? Thanks!
I'm trying to do a simple datalogger for an accelerometer and I want to log X, Y and Z data on my usb key at 20 Hz. I'm using the Memory Stick Datalogger v1.1 object by Paul via uart at 9600 bps. I'm able to write my data to my usb key, but only at lower speed (4 hz). As you can see below, my code is really simple. Will it be faster if I used the SPI protocol instead of uart? And what about an SD card? Could it be faster then a memory stick? Thanks!
Time := cnt Duration := clkfreq/1000 * 50 repeat USB.WriteLine(NUMBER.ToStr(~XYZData,%1010)) waitcnt(Time += Duration)
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
Also, a quick glance at your code: my first guess is that your delay is too small, since 9600 bps is fairly slow you're probably running over the 50ms delay while you're still recording your numbers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
You *do* need to buffer samples since the SD card can take some time to do its stuff (but the same is true for the flash datalogger).
So your acquisition cog needs to be decoupled from the cog that is writing the data to the SD card, with buffering between the two.
See fsrw2.6 from the obex.
problem is occasionally the flash card needs some time to shuffle things around. By spec, this should never be more than 500ms, but let's
call it a second (since we actually have metadata to write too). So your buffering should be sufficient for one second of data. If you are
willing to use 16K of the prop's memory for that buffering, that means 16K *bytes* per second. So if your samples have a 4-byte clock
and 4 bytes of data, that's 2K samples/sec (in binary).
If you are willing to tolerate rare (but occasional) dropouts in the data, then your rate can be substantially increased, since we can indeed
write to the card pretty close to 2MB/sec.
If you need a higher sampling rate and cannot tolerate dropouts, the use of external buffering memory is recommended; there are a number
of such products for the propeller. To use this, your data acquisition code will store the samples in the external RAM, and the writing COG
will read them from that external RAM and store them on the SD card. Even SPI memory will work just fine; you don't need to get crazy
bandwidth. Your sample rate will then be proportional to the size of your external memory (until you start hitting the limits of SD card write
speed).
Using external memory can also lower the average power consumption of the datalogger, since the SD card itself *can* take a fair amount
of power when writing. By bursting the writes, the SD card will spend more time in a very low power state.
@rokicki
Thanks for the information. I'm considering making a similar object for an SD card, and you've just saved me a bunch of time for when I get big gaps in the data. Interesting to note the much higher sampling rate. I went with the datalogger since I prefer flash drives, but an SD card may be another good solution.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm
(possibly significantly) the supported data rate. Since fsrw26 supports FAT32, you can use virtually any size SD
card. Even adding an external SPI memory chip for buffering, I think the SD card solution is a clear win.
You were right. I now put my data on a temp variable, and copy it in one shot and no more weird data. Thanks a lot!
And one more thing, when I use the "stop" function of your autodatalogger, should I be able to restart by only calling the "start" function? Right now, the first acquisition is working well, but when I recall the "USB.start" function, I got stuck at that command.
Anyway, as it stands when the Stop function is called the cog is stopped, but the file on the datalogger is left open and more importantly the baud is left high. The hardware fix would be to just add a transistor to the power line of the datalogger (or reset line, if it has one) and toggle that whenever you want to restart the logging. Software would be better, of course. If there is a demand for it (you), I can do some work on it this weekend and make a nicer fix for that. I've started on the fix, but there it may take me awhile without motivation.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Powered by enthusiasm