Go Down

Topic: I'm out of memory? Is the next thing up the Mega644P? (Read 2610 times) previous topic - next topic

jerseyguy1996

Well I've come to the sad realization that my code is just too long for the Mega328.  I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program.  I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE.  It doubles the amount of flash and sram relative to the 328.  It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package).  Any thoughts on using the 644P as a reasonable next step up from the 328?
Arduino Uno;
Mega328

wildbill

Sounds reasonable, especially if you have a lot of additional features you want to add. It might be worth posting your code though to see if anyone can suggest ways to save space, even if it just helps you avoid the problem on your new hardware.

Simpson_Jr

The mega1284p, (same packages as the 644) may be interesting as well, it has 4 times as much flash and 8 times as much ram as the 328-chip.

jerseyguy1996

Thanks to both of you!  Is the Arduino IDE support for the 1284 the same as for the 644?

WildBill, the code is fairly convoluted (as stated before, I don't know what I am doing), but I have posted it up on Github (mainly as a back up for me in case my macbook craps out).  It would be great if you would care to work your way through it to see if there are any major savings to be had.  Memory wise I am fine until I add the SD library.  I know there are some trimmed down versions but it would still be close and I would just like a bigger pool to swim in so that I can add more features.

It is located here:

https://github.com/jerseyguy1996/Leslie_GPS_Breadboard
Arduino Uno;
Mega328

Simpson_Jr


Thanks to both of you!  Is the Arduino IDE support for the 1284 the same as for the 644?


Yes, even slightly better, the latest sanguino-code at http://code.google.com/p/sanguino/downloads/list supports the 1284p at two speeds (8,16 MHz) and the 644p at 16 MHz.

oric_dan

#5
Jun 30, 2013, 11:03 pm Last Edit: Jul 01, 2013, 12:25 am by oric_dan Reason: 1

Thanks to both of you!  Is the Arduino IDE support for the 1284 the same as for the 644?
............
https://github.com/jerseyguy1996/Leslie_GPS_Breadboard

Unless changed in the most recent versions, the standard IDE libraries don't have direct support
for 1284 chips [or 644 ???], nor probably do several of the header files in the relevant libraries,
Code: [Select]
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h>
#include <avr/sleep.h>
#include <avr/power.h>


In general, you need to make changes such as the following for this to work, find the lines in
all of the library source and header files that say something like this,
Code: [Select]
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
 inline static void initSS()    { DDRB  |=  _BV(4); };
 inline static void setSS()     { PORTB &= ~_BV(4); };
 inline static void resetSS()   { PORTB |=  _BV(4); };

and add the 1284P extension:
Code: [Select]

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
 inline static void initSS()    { DDRB  |=  _BV(4); };
 inline static void setSS()     { PORTB &= ~_BV(4); };
 inline static void resetSS()   { PORTB |=  _BV(4); };


There are also a host of other issues with 1284 chips, which were discussed in long threads
in Feb 2013 in the Microcontrollers section.

jerseyguy1996

Oy......who's right?  Simpson_jr says yes and Oric_dan says maybe if I am willing to do some extra stuff.  I guess either way it can work....it may just not be a turn key solution.  I'll pick up the PDIP version of the 644 and 1284 and breadboard it.  Maybe it will work out of the box and if not perhaps it presents a good learning experience for me on some of the behind the scenes stuff in the libraries.  Thanks guys!
Arduino Uno;
Mega328

oric_dan

#7
Jul 01, 2013, 04:13 am Last Edit: Jul 02, 2013, 04:17 am by oric_dan Reason: 1
You can figure it out for yourself. Look in the libraries and various include files, and see if
they say this:
Quote
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

or this:
Quote

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)


Then you'll know. What you're gonna find is sometimes fixed, sometimes not.

Here's a clue, in the very latest of version of the IDE, the Arduino.h file [hidden many
levels deep in the IDE directory] says:
Quote
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)

whereas it previously said:
Quote
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)

and before that:
Quote
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)


However, in w500.h in the standard Ethernet library in the very latest version of the
IDE, it still says
Quote
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

so your Ethernet board won't work with 1284 chips.

The point is, 1284 support has only recently been started to be included in the IDE
*AT ALL*, and still hasn't been completely wrung out. The reason I know this is because
I've had to fix these things myself to get my 1284 boards to work.

If you really want an education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
http://forum.arduino.cc/index.php?topic=139671.0
http://forum.arduino.cc/index.php/topic,146773.msg1102743.html
http://forum.arduino.cc/index.php/topic,144165.msg1082609.html
http://forum.arduino.cc/index.php?topic=80483.0
http://forum.arduino.cc/index.php/topic,109550.msg822612.html

Mr_arduino


Well I've come to the sad realization that my code is just too long for the Mega328.  I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program.  I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE.  It doubles the amount of flash and sram relative to the 328.  It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package).  Any thoughts on using the 644P as a reasonable next step up from the 328?

I am not sure what you are trying to do but I think better coding would allow you to have all the features you want and keep using the atmega328. Also you only want strings and constant arrays in PROGMEM if it is just one varible you don't want that in PROGMEM. If it turns out that it is impossible to get the code to fit on an atmega328 then I would get something with more flash. Would you be able to post your code? It would help me evaluate if you really need to upgrade or this could be optimized to fit on an atmega328.

jerseyguy1996



Well I've come to the sad realization that my code is just too long for the Mega328.  I am positive that part of this is just that I don't code very efficiently (because I don't know what the heck I am doing) but going through all of my variables, even if I put some of the constant data (strings and such) in progmem I am still going to be constrained and it won't allow for any additional features on my program.  I'm thinking the Mega644P may be a good next step up since it appears that the good folks at Sanguino have added support for this uC in the arduino IDE.  It doubles the amount of flash and sram relative to the 328.  It also comes in a fairly reasonably sized package (I don't need something in a massive 100 pin package).  Any thoughts on using the 644P as a reasonable next step up from the 328?

I am not sure what you are trying to do but I think better coding would allow you to have all the features you want and keep using the atmega328. Also you only want strings and constant arrays in PROGMEM if it is just one varible you don't want that in PROGMEM. If it turns out that it is impossible to get the code to fit on an atmega328 then I would get something with more flash. Would you be able to post your code? It would help me evaluate if you really need to upgrade or this could be optimized to fit on an atmega328.


Sure!  There is a link on reply #3 that has the code.
Arduino Uno;
Mega328

jerseyguy1996


You can figure it out for yourself. Look in the libraries and various include files.......

If you really want education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
http://forum.arduino.cc/index.php?topic=139671.0
http://forum.arduino.cc/index.php/topic,146773.msg1102743.html
http://forum.arduino.cc/index.php/topic,144165.msg1082609.html
http://forum.arduino.cc/index.php?topic=80483.0
http://forum.arduino.cc/index.php/topic,109550.msg822612.html


This is fantastic information!  Thanks!
Arduino Uno;
Mega328

PeterH


Well I've come to the sad realization that my code is just too long for the Mega328.


From your comment about code length I guess you're talking about program memory. How much is your sketch taking currently? You've only got a few hundred lines of code there so I wouldn't have thought that your own code would be using up a lot of it and probably the libraries you're using are responsible for most of it.

By the way, your implementation of timer() does not handler millis() overflow correctly. To handle overflow, you can code it like this:

Code: [Select]

if(millis() - lastTime > interval)
{
    // interval has expired
    ....
I only provide help via the forum - please do not contact me for private consultancy.

jerseyguy1996




By the way, your implementation of timer() does not handler millis() overflow correctly. To handle overflow, you can code it like this:

Code: [Select]

if(millis() - lastTime > interval)
{
    // interval has expired
    ....



Mine should do the same thing.  My code is:

Code: [Select]
//keep track of time and handle millis() rollover
boolean timer(unsigned long timeout)
  {
    return (long)(millis() - timeout) >= 0;
  }


and then when I need to time something I do something like this:

Code: [Select]
last_valid_data = millis() + 2000;

and then I can just call timer like this:

Code: [Select]
if(timer(last_valid_data))

which I believe mathematically is equivalent to your code.  I could be wrong though.  I took calculus twice in college and still only squeaked out a "C" grade so my math may not be up to snuff.
Arduino Uno;
Mega328

PeterH


I believe mathematically is equivalent to your code.  I could be wrong though.

It is equivalent, except that your version doesn't handle counter rollover correctly.
I only provide help via the forum - please do not contact me for private consultancy.

oric_dan



You can figure it out for yourself. Look in the libraries and various include files.......

If you really want education, go read some of those interminable threads, where people
were scratching their heads for weeks, trying to get this stuff to work,
http://forum.arduino.cc/index.php?topic=139671.0
http://forum.arduino.cc/index.php/topic,146773.msg1102743.html
http://forum.arduino.cc/index.php/topic,144165.msg1082609.html
http://forum.arduino.cc/index.php?topic=80483.0
http://forum.arduino.cc/index.php/topic,109550.msg822612.html


This is fantastic information!  Thanks!

I also wrote up a page discussing my fixes and experiences,
http://www.ot-hobbies.com/resource/ard-1284.htm

Go Up