Show Posts
Pages: 1 ... 70 71 [72] 73 74 ... 110
1066  Using Arduino / Storage / Re: SdFat for bigger RAMs on: July 13, 2012, 01:18:39 pm
I did a test writing the same block in a tight loop 100,000 times which is a 5,1200,000 byte file.  It took 8223 ms which is 623 KB/sec.

If you are using 4-bit SDIO at 25 MHz, your bit rate is 12.5 times as fast as the Arduino's 8 MHz SPI bus.

If rates scaled by bus bit rate you would get 7.78 MB/sec on the STM32F4.  Of course it is unreasonable to expect that kind of scaling but the Arduino is not doing too bad.

The STM32F4 scores 501 in the CoreMark benchmark http://www.coremark.org/benchmark/.

AVR processors do about 0.54/MHz so a 16 MHz Arduino would score about 8.64. 

That's a factor of 59 more powerful!!
1067  Using Arduino / Storage / Re: SdFat for bigger RAMs on: July 13, 2012, 12:49:18 pm
You don't need buffering to use the streaming multi-block mode.  I do it in my binaryLogger on the 328.  You just send a multi-block write command to the SD and then write a block each time a block buffer is full.  Finally you send a write end command to the SD.  

The binaryLogger is an example in fastLoggerBeta20110802.zip http://code.google.com/p/beta-lib/downloads/list.  I will soon post another example that uses this mode to log 100,000 8-bit samples per second from the built-in AVR ADC.

An absolute minimum time to write a block due to SPI speed is 520 us.  It takes longer since you must fetch the data, check that the SPI data register is empty, and do loop control.  The current SdFat block write function takes about 820 us to write a block or about 620 KB per second.

This is the max rate for streaming in multi-block raw write mode.  It might be possible to improve a bit on this with some cleaver assembly code in the loop.  Currently I have optimized it with two bytes per iteration.  

In a practical application like my fast ADC logger which uses this mode, the main overhead is the ISR for the ADC.  At 100,000 samples per second that's two interrupts ever 10 us.  One to clear the timer flag which starts the next conversion and a conversion done interrupt to read the data.  The SD write is a small part of the overhead.  The write needs to be reliable with no random delays and streaming raw write does that.  On a Mega I use thirteen 512 byte buffers to increase reliability.  This means a write can take as much as 65,000 us and still not lose data.

For normal file operations extra cache won't payoff on the Arduino.  The AVR is at most a few percent as fast as the STM32F4 for data handling.  SDIO is a 4-bit bus and much faster so the Arduino is hopelessly outclassed here also.
1068  Using Arduino / Storage / Re: SdFat for bigger RAMs on: July 12, 2012, 04:36:13 pm
I have thought of using a multiple block cache but I don't think it would improve performance much for most applications.  The problem is that the copy to/from the cache costs so much with the AVR.

The best way to get better performance is to avoid the cache and use raw read/write of blocks with a contiguous file.

The other big variable is the SD card.  Each card has varying performance depending on the access pattern.  SD cards have occasional delays when written and the delays depend on the timing and pattern of writes.

Do you have some specific application in mind or is this just a general question?
1069  Development / Other Software Development / Re: what about debugging? on: July 12, 2012, 09:07:20 am
westfw,

There is a single-step capability for AVR. 

I posted this link above about DebugWIRE http://husks.wordpress.com/2012/03/29/hardware-debugging-the-arduino-using-eclipse-and-the-avr-dragon/.

The article demonstrates single-step with an Arduino.
Quote
As the exercise, you can single-step (step into/step over) until you get into your loop() routine, and then you can use step-over each of the digitalWrite() commands, and you should see the light on the Arduino change accordingly.

Once again you must modify the Arduino since DebugWIRE is a one wire serial protocol over the reset line and the cap that does the auto reset messes up the serial which runs at F_CPU/128.
1070  Development / Other Software Development / Re: ChibiOS/RT 2.4.1 RTOS update on: July 11, 2012, 06:14:39 pm
I remembered how to fix malloc.  Here is the documentation http://www.nongnu.org/avr-libc/user-manual/malloc.html.

If you add this at the beginning of setup(), String will work in your program.  It may fail if malloc is called in separate threads since I suspect malloc is not thread safe.
Code:
  char stkVar;
  extern char* __malloc_heap_end;
  // allow 256 locations for loop() stack
  __malloc_heap_end = &stkVar - 256;
No need to fix the linker script.
1071  Using Arduino / Storage / Logging 100 ksps with the Arduino internal ADC on: July 11, 2012, 02:40:36 pm
I have been experimenting with a fast logger using an Adafruit Data Logging Shield and a sketch to log 8-bit data from an Arduino analog pin. Any SD shield/module could be used. 

I have been able to log data to an SD card at 100,000 samples per second.

If there is any interest in this sketch I will polish it a bit and post it.

Plots, pictures and more info is here http://forums.adafruit.com/viewtopic.php?f=31&t=30557
1072  Development / Other Software Development / Re: what about debugging? on: July 11, 2012, 01:34:19 pm
Here is a recent article on using DebugWIRE with AVR Dragon on an Arduino.   It uses an Eclipse plugin.  AVR Dragon is a programmer/debugger that costs $50.96 from DigiKey.

http://husks.wordpress.com/2012/03/29/hardware-debugging-the-arduino-using-eclipse-and-the-avr-dragon/

You need to modify the Arduino to use DebugWIRE since the cap that does the reset pulse for download interferes with DebugWIRE.  DebugWIRE is a one wire serial protocol at F_CPU/128 using the reset pin.
1073  Development / Other Software Development / Re: what about debugging? on: July 11, 2012, 11:20:53 am
I forgot one comment.  Note the yellow mass of wires above the panel.  That is how the machine back-plane was wired.  Much of the stuff we built back then used wire-wrap instead of PCBs.
1074  Development / Other Software Development / Re: what about debugging? on: July 11, 2012, 09:36:20 am
I am really old and started embedded programming in the 1960s.  We debugged using the front panel switches and lights.  All the registers and some of the processor status was shown.  You could use the switches to enter data into memory or registers.

Single stepping was the last resort.

This machine had eight instructions and the lights on right side decode the instruction.

1075  Development / Other Software Development / Re: ChibiOS/RT 2.4.1 RTOS update on: July 11, 2012, 08:33:43 am
I looked at the problem again and found that dynamic memory in avr-libc will not work with ChibiOS.  Avr-libc assumes there is one stack and the heap is above the stack.  In ChibiOS the workspace for a thread is above the heap so malloc/realloc fails.

To use dynamic memory with ChibiOS you would need to enable the ChibiOS heap manager.

I have not used the ChibiOS driver for AVR, just ARM.  The serial driver is very basic in terms of functionality but is multithread friendly. 

If a thread reads and there is no data or writes and the queue is full, it uses qwait so lower priority threads can run.  This makes programing simple in the thread.

Using chThdYield in your program with Arduino Serial will use round robin scheduling to allow equal priority threads to run if you are waiting for input and will block lower priority threads.  Only higher priority threads will run if you block on output using Arduino Serial.

You would need to add ports three and four to serial_lld.c.
1076  Development / Other Software Development / Re: ChibiOS/RT 2.4.1 RTOS update on: July 10, 2012, 05:56:41 pm
The problem appears to be the Arduino String class. 

I never use the String class or anything that uses malloc/free in my sketches. 

Most coding standards for critical embedded systems forbid use of dynamic memory after system start-up and my background was with this type system.  My libraries do not use dynamic memory.

If you want to use String it appears that you will need to enable the ChibiOS wrapper for dynamic memory and modify the Arduinos String class to be multithreaded.

Note that Serial is the Arduino HardwareSerial driver, not the ChibiOS driver.

This sketch which uses char arrays seems to work.
Code:
#include <ChibiOS.h>
#include <util/atomic.h>

static WORKING_AREA(waSerialHandler,256);
static msg_t SerialHandler(void *arg)
{
  Serial.begin(9600);
  char str[20];
//  String inputStr = "";
//  inputStr.reserve(200);
  volatile uint8_t count = 0;
  char inChar = 0;
  while (true)
  {
    if (!Serial.available()) chThdYield();
    else
    {
      do
      {
        inChar = (char)Serial.read();
        if(inChar=='c')
        {
          str[count] = 0;
          Serial.print("Count:  ");
          Serial.println(count);
          Serial.print("Output string:  ");
          Serial.println(str);
        }
        str[count] = inChar;
  //      inputStr.concat((String)inChar);
        count++;
      }while (Serial.available());
    }
    if (count >= 10)
    {
      str[count] = 0;
      Serial.println(str);
  //  Serial.println(inputStr);
    Serial.flush();
    count=0;
//    inputStr = "";
    }
//    chThdSleep(1);
  }
}
void setup() {
  // put your setup code here, to run once:
  cli();
  halInit();
  chSysInit();

  Serial3.begin(9600);
 
  chThdCreateStatic(waSerialHandler,sizeof(waSerialHandler),NORMALPRIO +100, SerialHandler, NULL);

}

void loop() {
  // put your main code here, to run repeatedly:
  chThdSleep(10);
 
}
1077  Development / Other Software Development / Re: ChibiOS/RT 2.4.1 RTOS update on: July 09, 2012, 08:52:51 am
Nil Rtos examples look interesting.  Many Arduino projects need two or three threads and this should work well with Nil Rtos.

Looks like all development is with ARM CM0 but it should not be too hard to port to AVR and make an Arduino library.

There are many tiny systems like this but Giovanni Di Sirio is a real expert in embedded systems so I expect this will be a very good OS.

Designing a good general RTOS takes a lot of experience and talent and Giovanni has both.  I worked on some the largest embedded systems in physics research for 40 years.  The last system I did design work for was the LHC Atlas experiment at CERN which may have discovered the Higgs Boson.

I think ChibiOS is one of the best free systems available so it will be worth trying Nil Rtos on Arduino.
1078  Using Arduino / Storage / Anyone using SD.h with Leonardo? on: July 05, 2012, 03:30:02 pm
Anyone tried SD.h with Leonardo?

While updating SdFat for Leonardo, I realized that the version of SdFat used in Arduino 1.01 assumes an ATmega32U4 is a Teensy 2.0.

I tried SD.h with a Leonardo and a SD in the Ethernet shield and it failed.

I modified the SD library by editing Sd2Card.h in the SD/utility folder.

I changed this:
Code:
/** The default chip select pin for the SD card is SS. */
uint8_t const  SD_CHIP_SELECT_PIN = SS_PIN;
// The following three pins must not be redefined for hardware SPI.
/** SPI Master Out Slave In pin */
uint8_t const  SPI_MOSI_PIN = MOSI_PIN;
/** SPI Master In Slave Out pin */
uint8_t const  SPI_MISO_PIN = MISO_PIN;
/** SPI Clock pin */
uint8_t const  SPI_SCK_PIN = SCK_PIN;
To this:
Code:
#include <Arduino.h>
/** The default chip select pin for the SD card is SS. */
uint8_t const  SD_CHIP_SELECT_PIN = SS;
// The following three pins must not be redefined for hardware SPI.
/** SPI Master Out Slave In pin */
uint8_t const  SPI_MOSI_PIN = MOSI;
/** SPI Master In Slave Out pin */
uint8_t const  SPI_MISO_PIN = MISO;
/** SPI Clock pin */
uint8_t const  SPI_SCK_PIN = SCK;

That made this version of the ReadWrite example work with Leonardo and a SD in the Ethernet shield.
Code:
/*
  SD card read/write
 
 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
 
 */
 
#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // disable Ethernet
   pinMode(10, OUTPUT);
   digitalWrite(10, HIGH);

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}
1079  Using Arduino / Storage / Re: Arduino and SD card help on: July 03, 2012, 08:35:36 pm
Using the C++ I/O streams library can be very powerful but most old-timers and hobbyists don't have the knowledge to effectively use this library so maybe sticking with the simpler Arduino SD API will be best for you.

The Arduino API is a simple wrapper for an old version of SdFat that does not expose I/O streams.

The I/O streams library is nice since one line can read text for an entire structure, convert the text to binary, store the result in program variables, and check for errors.

Here is the statement for your data:
Code:
  jessicaFile >> jessica.hours >> jessica.mins >> jessica.secs >> jessica.pillOne >> jessica.pillTwo;
You can test for success of the above read statement like this:
Code:
  if (!jessicaFile) {
    // error occurred
  }


1080  Using Arduino / Storage / Re: Writing binary file to SD (creating BMP files) on: July 03, 2012, 04:52:06 pm
I was lazy so I just hard coded 24.

Each row must be a multiple of four bytes so I think the correct expressions for rowSize and fileSize are

Code:
  int rowSize = 4*((3*w +3)/4);
  int fileSize = 54 + h*rowSize;
This depends on truncation of integer divide.

The number of padding bytes at the end of a row would be:

Code:
  int nPad = rowSize - 3*w;

In your case rowSize is 12 bytes and fileSize is 78 =  (54 + 2*12).

Padding at the end of a row is three bytes.

I have not really tested this very well, just ran this sketch:
Code:
void setup() {
  Serial.begin(9600);
  int h = 2;
  for (int w = 0; w < 10; w++) {
    Serial.print(w);
    Serial.write(' ');
    int rowSize = 4*((3*w +3)/4);
    int fileSize = 54 + h*rowSize;
    int nPad = rowSize - 3*w;
    Serial.print(rowSize);
    Serial.write(' ');
    Serial.print(nPad);
    Serial.write(' ');
    Serial.println(fileSize);
  }
}
void loop() {}

and got this result:
Quote
0 0 0 54
1 4 1 62
2 8 2 70
3 12 3 78
4 12 0 78
5 16 1 86
6 20 2 94
7 24 3 102
8 24 0 102
9 28 1 110
Pages: 1 ... 70 71 [72] 73 74 ... 110