Show Posts
Pages: 1 ... 31 32 [33] 34 35 ... 139
481  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 04:39:43 pm
Quote
Now I understand the NilRTOS is sort of a non-preemtive Operating System
It is a preemptive RTOS..

Quote
But even with a better structure, what exactly in that RTOS helps me deal with the Serial interrupt whilre writing to SD
Based on your problem description above - I do not understand why you think you have problems with Serial interrupt.
Serial is a subsystem which includes interrupt processing and buffering. You do not need to touch it.

You are missing your serial data you want sniff because your approach is not optimal. You need "something" which is able to work "in parallel":

a) receiving the data via serial, and

b) writing the data to the sdcard, and

c) to buffer the data somehow because of sporadic sdcard's write latencies, and

d) the above a), b), c) done in parallel.

No busy-wait operation (waiting while "something else" happens), asynchronous operation with a buffering mechanism to avoid latencies.

200bytes from serial to catch and write to an SDcard is easily doable with NilRtos and 2-3 simple tasks I think. You have to provide some additional info on your problem however - ie. how often the 200bytes data package needs to be written to the SDcard. Based on my experience with Nilrtos, you can easily write a continual data stream (ie. text data) up to 20kB/sec to the sdcard without loosing a single byte.

The assumption here is you have enough RAM for creating a sufficient fifo buffer to compensate the sporadic sdcard's outage. For 20kB/sec (eqv. ~230kbaud serial speed) and a worst case sdcard's write latency of 300ms you need ~7kBytes large fifo buffer..


482  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 01:23:49 pm
Here is an example - each csv record is sampled with 4ms period. The last five data are fifo's consumer/producer watermarks and the write latency. 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 fifo then wrote the 4 buffered data records (and the new records) within 9 subsequent measurements onto the sdcard. No record was lost. The average time to write a record onto sdcard was ~2msecs. During this logging you may use Serial for communication with the system, as the Serial is also buffered.

Code:
,1379355276,104,0.049,85.71,92.24,95.10,96.13,96.61,96.12,96.17,89.31,-1,149,0,149,1864
,1379355276,108,0.049,85.71,92.24,95.10,96.13,96.61,96.12,96.17,89.31,-1,149,4,145,17472   <<< Write Latency
,1379355276,112,0.049,84.25,90.40,93.20,94.21,94.68,94.20,94.25,87.56,0,148,3,146,1864
,1379355276,116,0.049,84.03,90.35,93.26,94.38,94.99,94.62,94.25,87.56,1,147,3,146,2608
,1379355276,120,0.049,84.03,90.35,93.26,94.38,94.99,94.62,94.85,88.27,2,146,3,146,1936
,1379355276,123,0.049,85.45,92.00,94.91,96.02,96.59,96.14,96.33,89.51,3,145,2,147,1848
,1379355276,127,0.049,85.45,92.00,94.91,96.02,96.59,96.14,96.33,89.51,2,146,2,147,2232
,1379355276,131,0.049,83.88,90.16,93.01,94.10,94.66,94.22,94.40,87.84,2,146,1,148,1860
,1379355276,135,0.049,83.88,90.16,93.01,94.10,94.66,94.22,94.40,87.84,1,147,1,148,1936
,1379355276,140,0.049,84.64,91.32,94.33,95.55,96.24,95.88,96.15,89.40,0,148,1,148,3132
,1379355276,144,0.050,86.05,92.79,95.81,97.00,97.66,97.24,96.15,89.40,0,148,0,149,1804
,1379355276,148,0.050,86.05,92.79,95.81,97.00,97.66,97.24,97.45,90.49,-1,149,0,149,1764
483  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 16, 2013, 12:01:29 pm
Download and install NilRtos:
http://forum.arduino.cc/index.php?topic=178532.0

There is an example on data logging, a good point to start. Have a look on the NilRTOS.html documentation there - the fifo principle is explained there along with nice pictures ( see Examples in the html ). Also search forum for Nilrtos topics.

You have to get into the concept yourself, after that it might be easy. 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. The synchronization is done via semaphores.

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. Those two tasks are asynchronous - the first task is periodic (ie. 10ms sampling rate) and the second one is with "as fast as possible" timing.. You may print out the fifo statistic during the sampling, you may see how much of fifo the process consumes. 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).

In parallel you may run many other tasks, for example a third task which does something via Serial.

See also:
http://forum.arduino.cc/index.php?topic=144715.30
484  Using Arduino / Project Guidance / Re: data collection and storage rates on: September 15, 2013, 05:05:55 pm
Quote
If I collect acceleration data WRT time and perform some integrations, I will be able to calculate velocity and position.
That might work, provided the accelerometer is mounted on a gyroscope stabilised platform. Wernher v.B. did it long time back, he needed such stabilized platform, even such his dead reckoning did not work well, fortunately..
485  Using Arduino / Project Guidance / Re: data collection and storage rates on: September 15, 2013, 04:49:39 pm
Quote
What is the best way to collect this data? Should I look at getting a SD card shield? How many samples per second can the arduino uno collect and transfer to a SD Card?
It depends.. I've been logging ~20kBytes/sec of .csv data (90bytes 250x per second), you need a FIFO however - to compensate sdcard's write latencies (typically 10-30ms, peaks up to 200ms). So based on data rate you need a sram space for FIFO - ie for 20kB/sec and 200ms latency you need up to 4kB deep FIFO.
486  Topics / Science and Measurement / Re: How to treat SERIAL INTERRUPTS, while recording to SD CARD on SPI. on: September 15, 2013, 04:04:37 pm
You have to use an FIFO in order to compensate the sdcard's write latencies. I've been using NilRtos with NilFIFO for that purpose - logging up to ~20kB/sec of text data, serial works during logging as well..
487  Using Arduino / Microcontrollers / Re: How to choose the chip I need? on: September 15, 2013, 10:25:26 am
Quote
..the sketch size is 6.5k.  Does that mean I need a chip with a flash memory of 6.5k or less?
You mean the size of sketch source (the text you see in the IDE), or the compiled binary size?
From the source size you cannot judge on the flash memory required, as a 6.5k source code may create binary of any size..
488  Using Arduino / Sensors / Re: LM35 problem on: September 15, 2013, 09:22:20 am
Quote
tempC = commPort.read();

 read() returns a number between 0 and 255 for the next byte that's waiting in the buffer..

So you will not get your temperature in the integer or float format.. You will get the first byte coming from the serial only..

Quote
..my temp returns as 50 degrees C

You got the number 50 - in the ASCII it means "2" - that is the first char (first byte) of your temperature sent as string "22"  smiley-wink

You may try (maybe it works with processing) provided your temperature has been sent as an integer:

Code:
if (commPort.available()>0) {
tempC = (float)(commPort.parseInt());
}

or

Code:
if (commPort.available()>0) {
tempC = commPort.parseFloat();
}

when sent as a float.

489  Using Arduino / General Electronics / Re: What PNP transistor should be used ? on: September 15, 2013, 03:55:42 am
I've been using BC639 (NPN) or BC640 (PNP) for higher Ic currents.
490  Using Arduino / Programming Questions / Re: unsigned zero != zero on: September 15, 2013, 03:18:47 am
http://stackoverflow.com/questions/665745/whats-the-best-way-to-do-a-reverse-for-loop-with-an-unsigned-index
491  Using Arduino / Motors, Mechanics, and Power / Re: Quadcopter Motor Driver on: September 14, 2013, 12:30:38 pm
Vgs too low for full current?
492  Using Arduino / Programming Questions / Re: [RTC] How to set date and time permanent on: September 14, 2013, 10:32:37 am
Code:
// The simplest way to set DS1307's Date and Time
// Run it once only.. Pito 2013 ;)

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

void setup()
{
Serial.begin(115200);
Serial.print("Type any character to set RTC Time and Date\n");
while (Serial.read() < 0) { };
// hr,min,sec,day,month,yr
setTime(22,59,59,14,9,2013);
RTC.set(now());
}

void loop()
{
}


You have to set the proper date and time in the above source, of course. Run it and Type any character when the current date&time is equal the one set in your source.. Run it once smiley
PS: compiled but not tested with real RTC as I don't have the ds1307 chip handy..
493  Using Arduino / Storage / Re: SD card with examples not working on: September 14, 2013, 10:07:09 am
It does not work on my system either (my system works fine with SdFat lib).. Card Init failed.. CS = SS = 10
UECIDE, 1.0.5, fresh formatted 4gb fat32 card.
PS: go with SdFat library, similar demos there as well..
494  Using Arduino / Programming Questions / Re: [RTC] How to set date and time permanent on: September 14, 2013, 09:19:18 am
There is the Time.h library, which does everything you need.
http://playground.arduino.cc/Code/time

495  Using Arduino / Storage / Re: SD card with examples not working on: September 14, 2013, 09:03:47 am
It seems your card is ok, but you do not close the file properly, therefore the 0 size there..
Pages: 1 ... 31 32 [33] 34 35 ... 139