Go Down

Topic: New fast data logging sketches (Read 12 times) previous topic - next topic

fat16lib

I just posted three new fast data logging programs here http://code.google.com/p/beta-lib/downloads/list.

The file is fastLoggerBeta20110623.zip.

The fastest program, binaryLogger.pde, can log 40,000 samples per second when used with the highest quality SD cards.  I have been using 4 GB SanDisk Extreme 30 MB/sec cards.

It's not the speed that's important, it's the very low write latency of these cards.

binaryLogger.pde - Read from a MCP3201 ADC and log the data to a binary file.

fastLogger.pde - Read from analog pin zero and log the data to a text file.

mcpLogger.pde - Read from a MCP3201 ADC and log the data to a text file.

These are demo sketches and will need modification for any real application.

I have included a library for Microchip SAR ADCs that supports MCP3201, MCP3202, MCP3204, and MCP3208 chips.  I will be adding MCP3001, MCP3002, and MCP3301 in the future.


oscarcar

Very cool.

I will try and test it out tonight and this weekend.

I've started a sketch for a binary storage format, that I can add-on to this.

oscarcar


fat16lib

Yes, I use the newegg card. 

Also I use the card with "HD Video" on it. The model is SDSDX3-004-P31.

Both work well.

oscarcar

Finally getting some time to work on this.

I'm debating on whether to use your MCP3208 code or use what I was working with.

I'm posting the relevant code to what I was using below. It is simpler for me to understand, but maybe you also made some considerable speed improvements in your code.

Code: [Select]

#include <SPI.h>

  void setup() {
    pinMode(53,OUTPUT);
    digitalWrite(53,HIGH);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
  }

  void loop() {
    readADC(0);
  }

uint16_t readADC(int channel) {
  uint16_t output;
  //Channel must be from 0 to 7
  //Shift bits to match datasheet for MCP3208
  byte commandMSB = B00000110;
  uint16_t commandBytes = (uint16_t) (commandMSB<<8|channel<<6);
 
  //Select ADC
  digitalWrite(53, LOW);
  //send start bit and bit to specify single or differential mode (single mode chosen here)
  SPI.transfer((commandBytes>>8) & 0xff);

  byte msb = SPI.transfer((byte)commandBytes & 0xff) & B00001111;
  byte lsb = SPI.transfer(0x00);
 
  digitalWrite(53,HIGH);

  // cast before shiting the byte
  output = ((uint16_t) msb) <<8 | lsb;
  return output;
}



Go Up