Pages: [1] 2   Go Down
Author Topic: I'm out of memory? Is the next thing up the Mega644P?  (Read 1544 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Arduino Uno;
Mega328

New Jersey
Online Online
Faraday Member
**
Karma: 48
Posts: 3396
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Netherlands
Offline Offline
God Member
*****
Karma: 5
Posts: 614
A naughty mind is a joy forever.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Arduino Uno;
Mega328

Netherlands
Offline Offline
God Member
*****
Karma: 5
Posts: 614
A naughty mind is a joy forever.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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:
#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.
« Last Edit: June 30, 2013, 05:25:55 pm by oric_dan » Logged

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Arduino Uno;
Mega328

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: July 01, 2013, 09:17:30 pm by oric_dan » Logged

Offline Offline
Full Member
***
Karma: 6
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Arduino Uno;
Mega328

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Arduino Uno;
Mega328

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11142
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if(millis() - lastTime > interval)
{
    // interval has expired
    ....
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Sr. Member
****
Karma: 3
Posts: 268
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



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

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

Mine should do the same thing.  My code is:

Code:
//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:
last_valid_data = millis() + 2000;

and then I can just call timer like this:

Code:
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.
Logged

Arduino Uno;
Mega328

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11142
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: