0
Offline
Newbie
Karma: 0
Posts: 25
Arduino rocks
|
 |
« on: October 12, 2009, 08:31:54 pm » |
If I create a 1000 item boolean array, my sketch will not run, even though I have 12000 bytes free, aren't booleans only 1 byte a piece? I can run the program fine with 750 booleans. Any ideas?
Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15312
Measurement changes behavior
|
 |
« Reply #1 on: October 12, 2009, 08:36:12 pm » |
Any ideas?
Yea, your "booleans" are variables. Variables are stored in SRAM so they can change value while your program runs. Program statements don't change, they are stored in FLASH memory. 168 chip has 16k of FLASH and 1K of SRAM, 328 chip doubles both those values. AVR chip has 'Harvard' computer architecture, that means it uses separate program and data memories, unlike Von neumann architecture (like your PC) where program and data reside in same memory. Make sense? Lefty
|
|
|
|
« Last Edit: October 12, 2009, 08:39:38 pm by retrolefty »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 25
Arduino rocks
|
 |
« Reply #2 on: October 12, 2009, 08:58:45 pm » |
Arggg. That makes TONS of sense, thanks so much. Is there any way I can get around that? I have a 328, but I'm using it in another project. Can I store variables like that in EEPROM? Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Spokane, Washington
Offline
God Member
Karma: 0
Posts: 686
My name is Bob, and I'm an addict.
|
 |
« Reply #3 on: October 12, 2009, 09:05:27 pm » |
Sorry I don't have any useful info, but I'm curious, what are you using these 1000 booleans for?
I'm not sure how your program is going to operate, but it seems like there would be an easier way. (I could be totally wrong, I'm just so lost on what you'd use 1000 of em for:D)
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 163
Arduino rocks
|
 |
« Reply #4 on: October 12, 2009, 09:07:24 pm » |
Slightly more work but you could use an array of characters - index operator to pick a byte, bitwise operator to pick a bit. That way for each byte consumed you're getting 8 bits to set.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 25
Arduino rocks
|
 |
« Reply #5 on: October 12, 2009, 09:14:20 pm » |
The character thing seems like a good idea. I'm using this to record input from an IR remote and play them back later.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #6 on: October 12, 2009, 11:35:57 pm » |
here are some functions that I find useful for this kind of thing: const int maxBits = 1024; // the number of bits to store (make this evenly divisible by 8)
unsigned char bitData[maxBits / 8]; // uses 128 bytes to store up to 1024 bits
// stores the given bitValue using an index ranging from 0 to 1023 void writeBitArray( int bitIndex, boolean bitValue) { int arrayIndex = bitIndex / 8; bitWrite(bitData[arrayIndex], bitIndex % 8, bitValue); }
// returns the bitValue stored at the given index boolean readBitArray(int bitIndex) { int arrayIndex = bitIndex / 8; return bitRead(bitData[arrayIndex], bitIndex % 8 ); } useage: writeBitArray(i, bit); // save bit in location given by i readBitArray(i); // return the bit value at location i
|
|
|
|
« Last Edit: October 12, 2009, 11:42:53 pm by mem »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 25
Arduino rocks
|
 |
« Reply #7 on: October 13, 2009, 08:12:00 am » |
Ha ha! Thanks, that's a very useful piece of code right there. I will definitely use that.
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #8 on: October 19, 2009, 10:58:37 am » |
i would like to point to this: http://www.arduino.cc/en/Reference/PROGMEM(just for completeness)... -arne
|
|
|
|
« Last Edit: October 19, 2009, 11:00:56 am by RIDDICK »
|
Logged
|
-Arne
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 12
Arduino rocks
|
 |
« Reply #9 on: October 19, 2009, 11:45:15 am » |
The character thing seems like a good idea. I'm using this to record input from an IR remote and play them back later. You can change the stuff store in the PROGMEM at runtime. Cool tell me how so i can do it.
|
|
|
|
|
Logged
|
|
|
|
|
Brunsbüttel, SH, F.Rep.GERM
Offline
God Member
Karma: 4
Posts: 596
|
 |
« Reply #10 on: October 19, 2009, 05:36:35 pm » |
ohoh i wasnt aware that u want to write to that array... i dont know how to write to the flash memory (but it must be possible somehow)... writing to flash memory might significantly reduce the life time of the flash memory (but i'm not sure)...
sorry... :-[
-arne
|
|
|
|
|
Logged
|
-Arne
|
|
|
|
0
Offline
Faraday Member
Karma: 16
Posts: 3195
20 LEDs are enough
|
 |
« Reply #11 on: October 19, 2009, 05:50:34 pm » |
Have a look at the atmel application notes AVR101 and AVR105
--> writing large amounts of data to flash is faster than writing them to EEprom
--> writing flash is more tricky than writing EEprom
--> there are algorithms for "wear leveling" the application notes describe a very practical one.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #12 on: October 20, 2009, 05:42:36 am » |
Hi Udo,
As it says in AVR105, Flash can only be reprogrammed from the Boot section of memory and so modifying flash at runtime means modifying the Boot code. Are you aware of anyone that has successfully done this with the Arduino boot code?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 12
Arduino rocks
|
 |
« Reply #13 on: October 21, 2009, 01:27:40 pm » |
if it is possible i would love to know how. it would make life so much easier for me.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Online
Brattain Member
Karma: 137
Posts: 19006
I don't think you connected the grounds, Dave.
|
 |
« Reply #14 on: October 22, 2009, 01:42:52 am » |
You'd have to write a custom bootloader, and it's already pretty tight up there.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|