1284P - lack of SRAM but I need a high speed accessable memory for a POV-display

I am sorry techylan.... I am quite new to all that stuff, and I read numbers (ACII) from an.TXT file on the sd card, and substracted '0' to get the real '0' and '1' out of the .TXT and then I shifted that boolean into a 16 Bit number and stuffed an array fith lots of loops and counters.
I´ve never seen such a method like you mentioned before... Can I anywhere look up for more details how to use that?

But my main problem is still getting the 1284P to life :frowning:
Today I spent many order with burning different bootloaders and filtering the web for good answeres.
So far, I cant spot any mistakes
-I use a fresh install of the Arduino 1.0 IDE
-I use the Mighty 1284P (GitHub - maniacbug/mighty-1284p: Mighty 1284P Platform for Arduino)
-I followed the instruktions on Arduino on ATmega1284P | maniacbug
-The bootloader led (on PIN 1) also flashes when I press reset.
-I have an 16MHz external crystal with two 22pF tied to ground
-I want to use an Arduino UNO board to upload the sketches (as an serial adapter) (of course I removed the 328P)
--> I connected the RXD0 to the RX of the arduino UNO board and the TXD0 to the TX

It says "bootloader burn done", but when I want to upload a simple sketch (e.g. "Blink"), I get no response from the 1284P
Here is the log from the AVRDUDE:

Using Port                    : \\.\COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.

I have also tried to look if the fuse bits are set properly. - I did this by a tool created by Nick Gammon (http://arduino.cc/forum/index.php?topic=105089.0)

Here is the result:

Atmega fuse calculator.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 0x1E 0x97 0x05 
Processor = ATmega1284P
Flash memory size = 131072
LFuse = 0xFF 
HFuse = 0xDE 
EFuse = 0xFD 
Lock byte = 0xCF 
Clock calibration = 0x9D 
OCD Enable.............................. [ ]
JTAG Enable............................. [ ]
Enable Serial (ICSP) Programming........ [X]
Watchdog Timer Always On................ [ ]
Preserve EEPROM through chip erase...... [ ]
Boot into bootloader.................... [X]
Divide clock by 8....................... [ ]
Clock output............................ [ ]
Bootloader size: 4096 bytes.
Start-up time: SUT0: [ ]  SUT1: [ ] (see datasheet)
Clock source: low-power crystal.
Brownout detection at: 2.7V.

So far the fuses are set properly.

I hope you guys have an idea....
grz mx

This should work with your original single Arduino Uno, a single 1024 bytes of memory shifted out at a time.
The SD class returns a File object, which you then read using stream reads rather than single char read();
This should be at least 10 times faster than your Ascii single character stuff.
Look at:

This ought to dump even Gigabytes (or the full size of any file) to your display more than fast enough!

File mySDBinaryFile = SD.open(myFilePath);
while (true)
{ 
     if (mySDBinaryFile.stream.readBytes(myBuff, 1024) == 0)
           break;
     myShiftOutRoutine (myBuff, 1024);
//  delay(10);     // Add slow down as needed!
}
mySDBinaryFile.close();

Now you just need to write the binary files from your PC.
By the way, once you have this working, you are free to create your own binary file format that is a series of "display records".
You'd know better than me, but I'm thinking of something where each display record has a header, which is a bunch of int fields to specify:
size of Frame
number of Frames
delay ms per Frame
repeat factor for this set of Frames

Your Arduino code would "execute" the file.
You would use mySDBinaryFile.seek() to go back to the beginning to implement the repeat factor.

I think the use of an SD card with your POV is a splendid idea. Pop a different chip in and ... Voila! New stuff!
You can time the above code first just to satisfy yourself that the speed is sufficient.

You are connecting the Reset pin as well? And the power & ground pins - I think there are 2 of each?

When you get the sketch downloaded:
Try all the IO pins, I believe D13 is in a different location than you might be looking.
If you use Bobuino as the board type, D13 is the SCK pin.
If you use one of the others, I don't know which pin it is. You'll have to review the '1284 pins_arduino.h file to see where they are assigned.

wow thx crossroads - you finally make me feel a little better after that senseless day of trying to get it run.
Now I connected the reset as well, and it at least pops out another error.
It compiles successfull, and avrdude starts to send data (RX flashes) it also gets response from the 1284p, but it never finishes the upload successfull...
it stops at an random point at upload (I think its never the same) and pops me that error:

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: Send: V [56] @ [40] . [00] . [00] . [0c]   [20] 
avrdude: Recv: 
avrdude: stk500_cmd(): programmer is out of sync

maybe there is something wrong with the bootloader? or is there a wrong fuse setting?

grz mx

That error I think usually indicates a mismatch between bootloader speed and IDE speed. I think.
If it's fuse settings, NickGammon has a sketch that can be used to read them.
I hvae an Atmel AVR ISP MKii and I use that.

I have already read the fuse settings with Nick Gammon´s tool -please look my reply #9
Now I tried the same to completely virgin 1284p - same thing happens...

I gonna get mad....

I followed that tutorial to set the 1284 up on a breadboard : http://wiki.wiring.co/wiki/Creating_your_own_Wiring_board_with_a_DIP_atmega1284p_using_Duemilanove
Can it be a problem that i use ceramic disk capacitors?
I dont know what I am doing wrong! - I followed all instruktions properly.
Please tell me what I can do.
Is there any way that I can check if the speeds are identical (I have no osciloscope here)?

BTW.: I would like to buy a Atmel AVR ISP MKii aswell. The genuine from avr costs around 40$ and a rip of clone from the bay around 15$ - can I buy the rip of clone? - or should I better buy the original from AVR direktly?

grz mx

finally got that damn chip to life!
I used many different bootloader and only this one worked:

its a mix out of many different packages available, and it work very well.
Something strange is, that the 1284p works about 20% faster than my atmega2560 running the same sketch
(i did a shift out demo for an 16bit regsister to steer the leds)
the 1284 does update the 16bit LED display at 13,5khz and the 2560 at 11,6khz (calculated on 50000 cycles each)

now I need to port my current sktches to that baby. Hopefully the flash library will work.
thx for your help!

"BTW.: I would like to buy a Atmel AVR ISP MKii aswell."
I bought mine from mouser.com for ~$33.
I don't trust e-bay for tools like that, nor the 3 week delivery times.

mzure,
I updated my code (Reply#10) so it can handle any size SD file.
You can test it out for speed immediately.
You can use any file, even a text file or jpg, and you can even shift out to a non-connected device.

I'm claiming it should be blazingly faster than current, 5-10x or more.
Techylah

@techylah

I totally agree to your idea! The sd card interface was always supposed as an animation memory. But I dont understand how to use your code snippet to read it binary.
I think it would do the same job, if I just read a binary file, and instead of an ASCII character I get the byte I want directly (8x Times faster). Is there any way to stream that bytes directly into my array - without the use of counters, comperators, and so on - (that decrease speed extremely)?
But what is a shame, that I cant find ANY binary level file editor for windows! All "binary" editors show the value only in HEX, DEC, or ASCII! I tried a bunch of them and no one has the function to display it really binary!
Here is how I did it before (reading the ASCII):

myFile = SD.open("data1.txt")
 if (myFile) {  //does if file exists
    sd_member = 0;  //resets for array mergeing
    sd_position = 0;
    sd_layer = 0;
    while (myFile.available()) {   // reads from the file until there's nothing else in it
      data1[sd_layer][sd_member] = data1[sd_layer][sd_member] << 1;  //shifts it one position to the left
      data1[sd_layer][sd_member] |= (myFile.read() - '0');   //myFile.read acts like a serial communication - all fetched data is ASCII (for this reason -'0' : 48-48 = 0 ; 49-48=1 
      sd_position++;  //counts up position
      if (sd_member == 32) { 
        sd_member = 0; //resets member that new layer starts being written at the beginning member
        sd_layer++; //counts up layer to acces trough array
      }
      if (sd_position == 16) { //checks if lenth of one member is reached (as for datatype word its 16)
        sd_position = 0; //resets position that new member starts being written at the beginning
        sd_member++; //counts up member to acces trough array
      }
      }
    }
 myFile.close();    // close the file

grz mx

something really strange I found out now:

I am using the SD.h library on Arduino IDE r23.
I am using some interrupts and timers for my sketch.
The problem is, that the SD library crashes when the timer 1 overflow intrrupt is activated
-When i deactivate it it works very well (atmega 1284p).
Has anyone a idea??

My sketch now reads an .BIN file (i filled it up in an HEX editor - random values)
the file is 4096bytes big, and it is transfering at a speed of around 20kByte/sek.

  • That still seems a little slow to me - I need to investigate a bit further to test where the speed gets so lacked down...

EDIT: same problem with an external interrupt (INT0)
EDIT2: found out that disableing cli(); before my setup fexes the INT0 problem - the overflow problem is still there and I have no f**** clue why that is happening...

mzure,
It depends on your declaration of data1. What is it?
It looks like you have a 2D array of ints (16 bits) as in:
int data1[8][32];
Thus the size of data is 512 bytes ( 8 * 32 * 2 ).

If the data is binary, you can read it in directly in one step with:
myFile.stream.readBytes(data1, 512); // If that doesn't compile, then use "readBytes((char *)data1, 512)" or "readBytes(&data1[0][0], 512)"

If you want to create your patterns in an editor, as opposed to algorithmically, you're right, a hex editor is out of the question.

You could, however, let the user edit an ascii file of '.'s and 'x's, however many to the line you need, with the editor of his choice.
(it's only easy if you use an equi-spaced font like Console or Console)
Then you have a program which reads each line, converts it to binary, and writes the binary version.
For example it would take these 2 lines
......xxx.......
.....xxxxx......
and convert them to the 4 bytes for 2 ints in your array, namely
0x38, 0x7C

hey techylah! thx for your reply!
All your discribed methods give an compiler error...
readBytes() is not understood by r23 nor 1.0
myFile.stream.read() is also not acceptet by my compiler
only myFile.read() works.

Here is my current SD function:

void f_SdToArray() {
  sdx = 0;
  sdy = 0;
  myFile = SD.open("data2.bin");  //open file 1
  if (myFile) {  //does if file exists
    while (myFile.available()) {   // reads from the file until there's nothing else in it
      
      FRAME_1[sdx][sdy] = word(myFile.read(),myFile.read());
      sdy++;
      if (sdy == 256) {
        sdx++;
        sdy = 0;
      }
      if (sdx == 8) {
        sdx = 0;
      }
    }
  }
   myFile.close();    // close the file

data2.bin is exacly 4096 bytes bif and my array (2D) FRAME_1 is [8] [256] (4096 bytes as well)
It would be nice to achieve it whithout that massive counting´n loops and that stuff.

Anyway - I have still no clue why some interrupts interfer with the SD library... Are there some SPI interrupt flags set, which can be used normally as well?

grz mx

Try:

myFile.readBytes(data1, 512);         // If that doesn't compile, then use   "readBytes((char *)data1, 512)"   or   "readBytes(&data1[0][0], 512)"

no one of these want to work for me...
compiler says:

error: 'class File' has no member named 'readBytes'

I am using the SD.h library with arduino r23

here is my code:

void f_SdToArray() {
  sdx = 0;
  sdy = 0;
  myFile = SD.open("data2.bin");  //open file 1
  if (myFile) {  //does if file exists
    while (myFile.available()) {   // reads from the file until there's nothing else in it
     // FRAME_1[sdx][sdy] = word(myFile.read(),myFile.read());
     myFile.readBytes(FRAME_1, 4096);
      sdy++;
      if (sdy == 256) {
        sdx++;
        sdy = 0;
      }
      if (sdx == 8) {
        sdx = 0;
      }
    }
  }
   myFile.close();    // close the file
}

mzure,
This is my mistake. There is another library "SdFat.h" that has the stream read and write ability.
It appears this was not exposed to the simple SD library.
Example: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1281920236

This library lets you specify a buffer and how many bytes in the read() command.
I'm an experienced programmer, not really an Arduino expert.
It might be as simple as "include "SdFat.h""
sri

I don't know much about this and cannot work out how much data you are storing so I may be completely wrong ( I usually am ) but would it be possible to store the data in progmem? That way it doesn't use the sram and I think it would be very quick to read it.

progmem cannot be written to by the program once the sketch starts, only at download time.

Well I knew that. My understanding was that data was being read from an SD card not written to it. hence it seemed practical to do it that way. As I said I usually am wrong :wink: