![]() During this logging you may use Serial for communication with the system, as the Serial is also buffered. The average time to write a record onto sdcard was ~2msecs. The fifo then wrote the 4 buffered data records (and the new records) within 9 subsequent measurements onto the sdcard. You may see when the sdcard's latency jumped to 17.472msecs the fifo buffered the records (the "0,149" means the fifo is empty, "4,145" means there are 4 records buffered in). The last five data are fifo's consumer/producer watermarks and the write latency. Here is an example - each csv record is sampled with 4ms period. In parallel you may run many other tasks, for example a third task which does something via Serial. You may log the fifo stats (consumer and producer sides) on the card along with each measurement record - you will see how the fifo fills/empties during your logging, based on the sdcard's latency (latency - the actual time the "write of a fifo record into sdcard" took - you can measure it with micros() and log on the card as well). You may print out the fifo statistic during the sampling, you may see how much of fifo the process consumes. 10ms sampling rate) and the second one is with "as fast as possible" timing. Those two tasks are asynchronous - the first task is periodic (ie. Thus when the sdcard is not ready for a longer period of time you fills in the fifo, when the card is ready again you writes the fifo content onto the card. The synchronization is done via semaphores. You need a periodic task which reads data (from internal/external ADCs for example) and writes the data (in form of a structure) into the fifo (when the fifo is not full), and then you need a second task which reads the fifo (when the fifo is not empty) and writes the data onto the sdcard. You have to get into the concept yourself, after that it might be easy. Have a look on the NilRTOS.html documentation there - the fifo principle is explained there along with nice pictures ( see Examples in the html ). There is an example on data logging, a good point to start. Serial.println("error opening datalog.txt") if the file isn't open, pop up an error: if the file is available, write to it: so you have to close this one before opening another.įile dataFile = SD.open("datalog2.txt", FILE_WRITE) note that only one file can be open at a time, ![]() make a string for assembling the data to log: Serial.println("Card failed, or not present") see if the card is present and can be initialized: make sure that the default chip select pin is set to Open serial communications and wait for port to open: 53 on the Mega) must be left as an output or the SD library used as the CS pin, the hardware CS pin (10 on most Arduino boards, This example code is in the public domain. ![]() * SD card attached to SPI bus as follows: * analog sensors on analog ins 0, 1, and 2 This example shows how to log data from three analog sensors ![]() The code below I used to understand the delay to write to the serial port, where I saw the "LONG" and somewhat unpredictable write times to the SD card. With that, If Im in the SD writing procedure, which I have on the LOOP(), then if the SD takes longer than say 50ms, my serial buffer will overflow, and I dont execute the SerialEvent() routine to clean it up, and thats how I think I loose messages. I use the "SERIALEVENT()" routine, but apparently this is only run between each LOOP() time. I did some testing and realized that the SD card write routine was taking sometimes up to 300ms to finish, and in the mean time, I was loosing messages from my serial port. ![]() My code was pretty simple, but I then realized I was missing some messages. Basically i READ the serial bus (regular UART serial port on arduino UNO), and every ~200 bytes in a buffer, I record that to the SD Card. Im "sniffing" a serial bus from a product, and want to record EVERY message that is flowing on that Bus into an SD Card. ![]()
0 Comments
Leave a Reply. |