Show Posts
Pages: 1 ... 57 58 [59] 60 61 ... 107
871  Using Arduino / Sensors / Re: Static Accuracy Tests of the Arduino Internal ADC. on: September 01, 2012, 05:31:01 pm
After more thought, I am puzzled why Atmel specifies the formula
Quote
v = (Vref/1024)*n

for converting an ADC value, n, to voltage v.

This formula, that I sometimes use, is no better.

Quote
v = (Vref/1023)*n

An ideal 10-bit ADC returns the value n for voltages between (Vref/1024)*n and Vref/1024)*(n+1).

It seems like you should use the average value of voltage for bin n.  The formula for the average bin voltage is:
Quote
v = (Vref/1024)*(n + 0.5)

The Arduino ADC is anything but ideal so I calibrate it, as above, for accurate measurements. 

The problem with calibration is that non-linearity is a ragged function so you can't just do a few measurements to get a good calibration.

I measure the response of the ADC for over 4000 voltages.  I use a linear fit to these measurements.  This gives very good results for almost all ATmega chips.

That brings up the question of how can you select the best chip based on a few measurements?

ADC theory articles often show smooth curves for integral non-linearity but for real parts the plot is a very ragged/jagged line.  A calibration based on just a few measurements is an improvement but nowhere near optimal.

A comment on the S/H impedance measurements.  These measurements should not be relied on for real situations.  Stray capacitance becomes a key factor for high impedance sensors. 

High impedance sensors are not likely to output high frequency signals so you can improve accuracy by adding a 2-20nf cap between the sensor's analog pin and ground.

When the ADC MUX switches to this pin, the charge in the pin cap will be used to charge the S/H cap. The S/H cap is about 14pf so the S/H voltage will be accurate to 1% if you use a 2nf cap and 0.1% for a 20nf cap.

Of course the best solution is to use a good op-amp and filters to condition the signal from high impedance sensors.
872  Using Arduino / Storage / Re: SD won't init with brand new Leonardo + Ethernet Shield Rev3 on: August 31, 2012, 06:03:46 pm
See this topic http://arduino.cc/forum/index.php/topic,113058.0.html.
873  Using Arduino / Storage / Re: Read/Write MicroSD in 1-bit mode on: August 31, 2012, 02:45:33 pm
There is no hardware support for SD 1-bit mode so only slow bit-bang would work.  In SD bus mode CRC is required and this is also slow on the Arduino.

You can use bit-bang SPI with the SD.h library and SdFat.

For SD.h edit Sd2Card.h to enable software SPI and define the pins to be used.

Most MicroSD cards support SPI.
874  Using Arduino / Sensors / Re: Static Accuracy Tests of the Arduino Internal ADC. on: August 31, 2012, 11:37:37 am
ardnut,
I would have expected 1023 also but the datasheet and Atmel app notes say 1024.
Quote
ADC = VIN ⋅ 1024/VREF
Data sheets for most SAR ADCs use 2^n where n is the number of bits.  I often use 2^n-1 since that is full scale.

MarkT,

Here is a demonstration of how the ADC MUX and S/H are affected by external resistance.

I connected analog pin 0 to ground and analog pin 1 to 5V through a resistor.  I used resistor values from 10K to 470K.

I used  ADC prescalers values from 16 to 128 which results in an ADC clock from 1MHz to 125kHz in this sketch.
Code:
const uint8_t ADC_PS_16  = (1 << ADPS2);
const uint8_t ADC_PS_32  = (1 << ADPS2) | (1 << ADPS0);
const uint8_t ADC_PS_64  = (1 << ADPS2) | (1 << ADPS1);
const uint8_t ADC_PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
const uint8_t ADC_PS_BITS = ADC_PS_128;

void setup() {
  Serial.begin(9600);
  ADCSRA &= ~ADC_PS_BITS;
  ADCSRA |= ADC_PS_128;    
}
void loop() {
  uint16_t v0 = analogRead(0);
  uint16_t v1 = analogRead(1);
  Serial.print(v0);
  Serial.write(',');
  Serial.println(v1);
  delay(500);
}
Here are the results for the value of v1.  It should be 1023.

10K22K33K47K68K100K220K330K470K
PS16970920880840805770727710704
PS3210231015997970932883797760745
PS641023102210191010990950858808785
PS128102310231023102310221016964913874

Note that even with zero external resistance, PS16 has an error.  This is because the ADC input has more than 10K of internal resistance.

I then ran the test after adding a line to throw away the first reading after changing the channel to analog pin 1.  This is recommended by Atmel for more accuracy in an app note.

Here is the sketch.
Code:
const uint8_t ADC_PS_16  = (1 << ADPS2);
const uint8_t ADC_PS_32  = (1 << ADPS2) | (1 << ADPS0);
const uint8_t ADC_PS_64  = (1 << ADPS2) | (1 << ADPS1);
const uint8_t ADC_PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
const uint8_t ADC_PS_BITS = ADC_PS_128;

void setup() {
  Serial.begin(9600);
  ADCSRA &= ~ADC_PS_BITS;
  ADCSRA |= ADC_PS_128;    
}
void loop() {
  uint16_t v0 = analogRead(0);
  analogRead(1);
  uint16_t v1 = analogRead(1);
  Serial.print(v0);
  Serial.write(',');
  Serial.println(v1);
  delay(500);
}

Here are the results.

10K22K33K47K68K100K220K330K470K
PS1610231023102210191012999947901870
PS32102310231023102310221017992966941
PS641023102310231023102310221010997983
PS128102310231023102310231023102210161011

If you have a very high impedance sensor you can add a one ms delay after the first analogRead(1) with PS128.  Then even a 1Meg resistor will result in 1022 or 1023.
Code:
 analogRead(1);
  delay(1);
  uint16_t v1 = analogRead(1);

875  Using Arduino / Storage / Re: Unformatted write to SD on: August 30, 2012, 10:52:29 am
The strange 1 ms delay was removed a long time ago. 

I did a check on 1.0.1 running this sketch and it performs as expected for a 125 kHz ADC clock.

Code:
void setup() {
  Serial.begin(9600);
  uint32_t t0 = micros();
  uint16_t v0 = analogRead(0);
  uint32_t t1 = micros();
  uint16_t v1 = analogRead(0);
  uint32_t t2 = micros();
  Serial.println(t1 - t0);
  Serial.println(t2 - t1);
}
void loop() {}
It prints
Quote
212
112

The first call takes 26.5 ADC clock cycles, a bit more than 25 required by the hardware.

The second takes 14 ADC clock cycles, again a bit longer than the time required by the hardware.

I did some more ADC tests that you might look at http://arduino.cc/forum/index.php/topic,120004.0.html.

These tests show how important calibration is and examine Noise Reduction Mode.
876  Using Arduino / Storage / Re: Unformatted write to SD on: August 30, 2012, 09:40:04 am
Thanks, I meant to check if the compile order was correct for 16-bit access but never got back to it.  
877  Using Arduino / Storage / Re: High Performance Industrial SD Cards on: August 28, 2012, 06:24:37 pm
Here is a low cost high performance card.

An ATP 1GB Secure Digital SLC Industrial Grade card for $5.75 when I bought it.

http://www.newegg.com/Product/Product.aspx?Item=9SIA12K0CT6829

Here are the SdFat bench results for 100 and 512 byte records.
Quote
Buffer size 100 bytes
Write 258.95 KB/sec
Maximum latency: 69400 usec, Minimum Latency: 84 usec, Avg Latency: 380 usec
Read 329.38 KB/sec
Maximum latency: 2240 usec, Minimum Latency: 80 usec, Avg Latency: 298 usec


Buffer size 512 bytes
Write 392.32 KB/sec
Maximum latency: 62500 usec, Minimum Latency: 1184 usec, Avg Latency: 1339 usec
Read 469.41 KB/sec
Maximum latency: 2164 usec, Minimum Latency: 1072 usec, Avg Latency: 1085 usec
878  Using Arduino / Storage / Re: SDFat - pulling out the card on: August 28, 2012, 06:04:14 pm
Sorry you are so upset.  I thought it was strange that you assumed an Ethernet shield was used.
Quote
Guess you have the ethernet shield if you have the SD reader.

At least a thousand people have contacted me about data logging and only a small percentage use the Ethernet shield for data logging.

Sorry, I can't refer you to a peer-reviewed paper.
Quote
Wondering what your research method was: group size, demographic, distribution, duration, correlation ...
You may want to direct me to the peer-reviewed paper you have written on the subject.

Shields like this one from Adafruit are very popular http://www.adafruit.com/products/243.

Many people use the SparkFun shield https://www.sparkfun.com/products/9802.

People like these shields for data logging since they have a prototyping area.

Networking is a good solution and a number of people have used Ethernet to upload data from an SD.

The WiFi Shield can be used http://arduino.cc/en/Main/ArduinoWiFiShield.

Another Idea people are using is an Eye Fi card http://www.ladyada.net/make/IoTcamera/.

879  Using Arduino / Storage / Re: SDFat - pulling out the card on: August 28, 2012, 08:58:10 am
Most people who log data to an SD do not use the Ethernet Shield.  There are now dozens of SD shields/modules.

A network is great if it is suitable.
880  Using Arduino / Storage / Re: Runtime determination of EEPROM size on: August 27, 2012, 04:38:53 pm
The symbol E2END is the last EEPROM address.

For a 328 Arduino this sketch
Code:
void setup() {
  Serial.begin(9600);
  Serial.println(E2END);
}
void loop() {}

Prints this

Quote
1023

See this http://www.nongnu.org/avr-libc/user-manual/group__avr__io.html
881  Using Arduino / Storage / Re: micro SD "HC class 4" card on: August 27, 2012, 08:03:07 am
Here are the results for a Class 4 Kingston 4GB HC card with the Ethernet shield on an UNO.

http://www.amazon.com/Kingston-microSDHC-Memory-SDC4-4GBET/dp/B00200K1TI

For SdInfo:
Quote
init time: 990 ms

Card type: SDHC

Manufacturer ID: 0X41
OEM ID: 42
Product: SD4GB
Version: 2.0
Serial number: 2711490139
Manufacturing date: 3/2009

cardSize: 7745536 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

SD Partition Table
part,boot,type,start,length
1,0X0,0XB,8192,7737344
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT32
blocksPerCluster: 64
clusterCount: 120768
freeClusters: 120539
fatStartBlock: 14496
fatCount: 2
blocksPerFat: 944
rootDirStart: 2
dataStartBlock: 16384

Here is the SdFat bench result (Note write is very slow):
Quote
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 65.34 KB/sec
Maximum latency: 234516 usec, Minimum Latency: 84 usec, Avg Latency: 1521 usec

Starting read test.  Please wait up to a minute
Read 278.91 KB/sec
Maximum latency: 3588 usec, Minimum Latency: 80 usec, Avg Latency: 353 usec

Here are the bench results for a Class 10 Amazon 4GB card http://www.amazon.com/AmazonBasics-microSDHC-Class-Memory-Adapter/dp/B0058GH3II
Quote
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test.  Please wait up to a minute
Write 169.04 KB/sec
Maximum latency: 189888 usec, Minimum Latency: 84 usec, Avg Latency: 586 usec

Starting read test.  Please wait up to a minute
Read 288.37 KB/sec
Maximum latency: 3136 usec, Minimum Latency: 80 usec, Avg Latency: 341 usec
882  Using Arduino / Storage / Re: High Performance Industrial SD Cards on: August 26, 2012, 02:53:18 pm
The next generation of consumer SD cards will be even slower on Arduino.

Here is the result of running bench on a 64GB SDXC card.

Quote
Write 116.69 KB/sec
Maximum latency: 192708 usec, Minimum Latency: 84 usec, Avg Latency: 851 usec
Read 296.70 KB/sec
Maximum latency: 2980 usec, Minimum Latency: 80 usec, Avg Latency: 331 usec

The reason is that new cards have very dense TLC (Triple Level Cell) NAND flash.  Three bits are stored in the gate of the one transistor cell as eight levels of charge, each level differing by less than 100 electrons.

These chips are designed for very large contiguous writes.  The Arduino does not have sufficient buffering to achieve this.

The page size of these chips is much larger than a 512 byte block so in only part of a page is used when a single 512 byte block is written. The rest of the page is "dead" meaning unusable until it is erased.

Eventually the SD controller collect these blocks and rewrites them to a new page.  This is a very high overhead process.

In addition TLC flash is very susceptible to wear so the Arduino's inefficient use of the device causes lots of data movement.  The Erase Block Size for these flash chips can be 256KB. Moving this much data take a long time.

Even unchanged data gets moved with the wear-leveling algorithms.
Quote
Blocks that contain static data with erase counts that begin to lag behind other blocks will be included in the wear-leveling block pool, with the static data being moved to blocks with higher erase counts.


The 64GB SDXC card I tested can have an occasional write latency of almost 200 ms.

If you want to learn more about the internals of SD cards and modern NAND flash here are some links.

http://www.micron.com/~/media/Documents/Products/Technical%20Note/NAND%20Flash/151tn2942_nand_wear_leveling.pdf

http://www.es.ele.tue.nl/~kgoossens/2011-codes+isss-special-session/kuo.pdf

http://www.eetindia.co.in/STATIC/PDF/200809/EEIOL_2008SEP22_STOR_AN_01.pdf
883  Using Arduino / Storage / Re: sd with serial communication, how do? on: August 26, 2012, 02:21:31 pm
There is a serious bug in the dynamic memory free() function that can cause String to crash.

http://arduino.cc/forum/index.php/topic,115552.0.html

Fixes are presented in the above topic.

The problem may also cause SD.h to crash if many files are opened an closed.
884  Using Arduino / Storage / High Performance Industrial SD Cards on: August 25, 2012, 02:49:25 pm
Many new consumer SD cards have poor file write performance with Arduino SD libraries.

I bought and tested two industrial grade SD cards and compared them with two consumer SD cards.  Industrial SD cards cost a great deal more than consumer cards.

The industrial cards are:

Swissbit 1GB card http://www.digikey.com/product-detail/en/SFSD1024L1BN2TO-I-ME-151-STD/1052-1033-ND/2620367.

Wintec 1GB card http://www.digikey.com/product-detail/en/W7SD001G1XA-H60PD-002.02/385-1079-ND/3152960

The consumer cards are:

4GB Amazon class 10 card http://www.amazon.com/AmazonBasics-SDHC-Class-Secure-Digital/dp/B004Q3R9AQ/ref=sr_1_3?ie=UTF8&qid=1345922948&sr=8-3&keywords=4gb+class+10+sdhc

2GB SanDisk class 2 card http://www.amazon.com/SanDisk-Class-Flash-Memory-SDSDB-2048-A11/dp/B0009RGLSE/ref=sr_1_8?s=electronics&rps=1&ie=UTF8&qid=1345923062&sr=1-8&keywords=2gb+sandisk+class+2+sd

I ran the SdFat bench example with two record sizes.  First I used the default 100 byte records.  Here is a summary of write results.
Quote
1GB Wintec: 278.40 KB/sec
1GB Swissbit: Write 265.10 KB/sec
2GB SanDisk class 2: 127.41 KB/sec
4GB Amazon class 10: 165.69 KB/sec

Next I ran the bench example with 512 byte records.  In the case of 512 byte records, data is written directly to the SD without being copied to SdFat's internal buffer.   Here is a summary of write results.
Quote
1GB Wintec: 407.57 KB/sec
1GB Swissbit: 384.92 KB/sec
2GB SanDisk class 2: 152.31 KB/sec
4GB Amazon class 10: 200.62 KB/sec

In this case the industrial cards are about twice as fast as the consumer cards.  There is not as much gain for read.

Here are the detailed results.
Quote
100 byte records

1GB Wintec card
Write 278.40 KB/sec
Maximum latency: 84916 usec, Minimum Latency: 84 usec, Avg Latency: 354 usec
Read 338.89 KB/sec
Maximum latency: 2164 usec, Minimum Latency: 80 usec, Avg Latency: 289 usec

1GB Swissbit card
Write 265.10 KB/sec
Maximum latency: 72608 usec, Minimum Latency: 84 usec, Avg Latency: 372 usec
Read 338.07 KB/sec
Maximum latency: 2172 usec, Minimum Latency: 80 usec, Avg Latency: 290 usec

2GB Sandisk class 2 card
Write 127.41 KB/sec
Maximum latency: 61372 usec, Minimum Latency: 84 usec, Avg Latency: 778 usec
Read 276.33 KB/sec
Maximum latency: 3180 usec, Minimum Latency: 80 usec, Avg Latency: 356 usec

4GB Amazon class 4 card
Write 165.69 KB/sec
Maximum latency: 191320 usec, Minimum Latency: 84 usec, Avg Latency: 598 usec
Read 290.17 KB/sec
Maximum latency: 3108 usec, Minimum Latency: 80 usec, Avg Latency: 339 usec

512 byte records

1GB Wintec card
Write 407.57 KB/sec
Maximum latency: 85756 usec, Minimum Latency: 1152 usec, Avg Latency: 1250 usec
Read 488.39 KB/sec
Maximum latency: 2088 usec, Minimum Latency: 1032 usec, Avg Latency: 1043 usec

1GB Swissbit card
Write 384.92 KB/sec
Maximum latency: 67700 usec, Minimum Latency: 1160 usec, Avg Latency: 1324 usec
Read 486.68 KB/sec
Maximum latency: 2096 usec, Minimum Latency: 1036 usec, Avg Latency: 1046 usec

2GB SanDisk class 2 card
Write 152.31 KB/sec
Maximum latency: 59452 usec, Minimum Latency: 2132 usec, Avg Latency: 3355 usec
Read 366.17 KB/sec
Maximum latency: 2700 usec, Minimum Latency: 1288 usec, Avg Latency: 1393 usec

4GB Amazon class 10 card
Write 200.62 KB/sec
Maximum latency: 191596 usec, Minimum Latency: 2132 usec, Avg Latency: 2545 usec
Read 391.00 KB/sec
Maximum latency: 3020 usec, Minimum Latency: 1164 usec, Avg Latency: 1304 usec

885  Using Arduino / Sensors / Re: Static Accuracy Tests of the Arduino Internal ADC. on: August 25, 2012, 11:24:49 am
Both WaveRP and AnalogIsrLogger have configurable sample rates.  You need to look at the programs and documentation for more details.
Pages: 1 ... 57 58 [59] 60 61 ... 107