OCCRA
Go to Post At championship, as we do at every regional, we'll be counting every point scored (or lost) by each robot. Nothing beats numbers. - Derek Bessette [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-11-2007, 11:56 AM
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 695
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
How much memory is there really?

Hi

I just started trying some algorithms for our arm, and ran into some memory problems. I want a big lookup array.

The linker barfed when I tried to declare an 800 BYTE array. So I started poking around in the MAP file.

It seemed that there was a lot of code space to spare (I was only utilizing 12%), so I tried declaring the array as "rom" to see if I could use code space for my lookup table (since it will never change).

Woo-Hoo. I can seem to define SCADS of space there: eg:

rom BYTE Omega[20000][2] ;

The map file verifies that this allocation is OK and ending up in the code space... so my question is:

Does this memory really exist in the RC?
In other words will the linker protect me from over declaring space?

I want to be sure that I'm not just being fooled by the compiler/linker.

Any experiences with large const data in the code memory?
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
  #2   Spotlight this post!  
Unread 01-11-2007, 12:53 PM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Itinerant Programmer
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 7,454
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How much memory is there really?

The Linker won't necessarily directly complain about memory over "drafts," so you have to watch it. What you usually get when you run out of space is a link error about not being able to load one of the libraries at the end. As reported by MPLab and the linker you will actual have less memory available to you due to other system overhead. As I recall the MAP file will report ~97% utilization when it is actually full.

We have three types of memory on the RC available to use.
See http://www.ifirobotics.com/rc.shtml#Specifications for the PIC18F8722

128,000 bytes program space
3936 bytes variable space (less the PROTECTED, etc. areas listed in 18f8722.lkr)
1024 bytes EEPROM

The default is to put variables into the 3936 byte variable space where your code can modify the values while it's running. There is a further limitation on the variable space due to how the linker has the space blocked out.
You are only able to declare 256 bytes of variable space in any one MPLAB project file.

"rom" puts your stuff into the 128K program space, but you cannot change values placed here as you noted. They are fixed and read-only when your code runs. As you said it is probably the best place for our fixed lookup tables.

The EEPROM requires special runtime reads/writes to use, but it is maintained even when your robot power is off.


In MPLAB you can also check on your memory utilization via: View -> Memory Usage Gauge
Note though that the Program memory is stated in two-byte words, not bytes for some reason.

P.S. We've kept our autonomous modes in large arrays in program space since these PIC RCs came out in 2004.
__________________
The mind sees only what the mind is prepared to comprehend - Henri Bergson
358 Beta notes & results

Last edited by Mark McLeod : 01-11-2007 at 01:12 PM.
  #3   Spotlight this post!  
Unread 01-11-2007, 12:58 PM
Matt Krass's Avatar
Matt Krass Matt Krass is offline
"Old" and Cranky. Get off my lawn!
AKA: Dark Ages
FRC #0263 (Sachem Aftershock)
Team Role: Mentor
 
Join Date: Oct 2002
Rookie Year: 2002
Location: Long Island, NY
Posts: 1,187
Matt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond repute
Send a message via AIM to Matt Krass Send a message via Skype™ to Matt Krass
Re: How much memory is there really?

Due to the linker methodology, each individual file can only declare up to 256 bytes of dynamic memory, things like lookup tables are constant, as you noted and should be done with rom qualifiers so they are stored as constants in program memory and not in the variable space. It's just a limitation imposed by the way things are linked together, it's not often a problem unless you use a lot of variables or large arrays. What you're doing is the proper solution to the problem, by making the table a constant.
__________________
Matt Krass
If I suggest something to try and fix a problem, and you don't understand what I mean, please PM me!

I'm a FIRST relic of sorts, I remember when we used PBASIC and we got CH Flightsticks in the KoP. In my day we didn't have motorized carts, we pushed our robots uphill, both ways! (Houston 2003!)
  #4   Spotlight this post!  
Unread 01-11-2007, 02:30 PM
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: How much memory is there really?

"You are only able to declare 256 bytes of variable space in any one MPLAB project file."

That is the default. The default is based upon the h/w architecture having 256 byte ram banks. PIC18F instructions have 8bit ram address offset hence the default of 256 byte banks. However, you can override by changing the setup in the lkr file.

This shouldn't be done lightly because it introduces more overhead in accessing data - but you essentially tell the linker to merge two adjacent ram banks and treat them in software as a single resource. Refer to the C18 user guide.

Changed 18f8722.lkr:
Code:
DATABANK   NAME=gpr2       START=0x200          END=0x2FF
DATABANK   NAME=grp3       START=0x300          END=0x3FF
DATABANK   NAME=gpr4       START=0x400          END=0x4FF
To:
Code:
DATABANK   NAME=gpr2       START=0x200          END=0x3FF
DATABANK   NAME=gpr4       START=0x400          END=0x4FF

created:
static unsigned char bigarray[500];

Build project, map file shows:

Code:
                 bigarray   0x000202       data     static user_routines.c
                           i   0x0003f6       data     static user_routines.c
x3f6-x202 = 500 byte array. Compiles/links/runs ok. I read about this in the C18 user guide somewhere. Currently only the "3.2.4 Managing the Software Stack" section jumps out at me - but it shows the steps for doing the same thing to create larger stack areas. Ram is a limited resource... use it wisely.

Bud

Last edited by dcbrown : 01-11-2007 at 02:34 PM.
  #5   Spotlight this post!  
Unread 01-11-2007, 10:40 PM
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How much memory is there really?

What do you use to see how much space is being used?
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #6   Spotlight this post!  
Unread 01-11-2007, 11:07 PM
Robby's Avatar
Robby Robby is offline
Registered User
AKA: Kevin Beranek
FRC #0269 (Cooney Robotics)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Wisconsin
Posts: 47
Robby has a spectacular aura aboutRobby has a spectacular aura about
Re: How much memory is there really?

You can look at FrcCode.map and a ways down it will tell you how much program space you are using. It looks like:

Code:
                              Program Memory Usage
                               Start         End
                           ---------   ---------
                            0x000800    0x0078ba
            28859 out of 132120 program addresses used, program memory utilization is 21%
  #7   Spotlight this post!  
Unread 01-11-2007, 11:43 PM
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 695
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Re: How much memory is there really?

Thanks guys.... It looks like I'll be OK.

Now I just need to write the program to create the file that declares all the values :0

BTW, Nice PID article Matt. I'l have to hand it out at the next S/W meeting.

Phil.
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
  #8   Spotlight this post!  
Unread 01-12-2007, 12:11 AM
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 392
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: How much memory is there really?

Quote:
Originally Posted by PhilBot View Post
I just started trying some algorithms for our arm, and ran into some memory problems. I want a big lookup array. ...

so I tried declaring the array as "rom" to see if I could use code space for my lookup table (since it will never change). ...
Thanks for sharing the tip on using "rom" space for constant lookup tables!

Quote:
Originally Posted by Mark McLeod View Post
We have three types of memory...

128,000 bytes program space
3936 bytes variable space (less the PROTECTED, etc. areas listed in 18f8722.lkr)
1024 bytes EEPROM

The default is to put variables into the 3936 byte variable space where your code can modify the values while it's running. There is a further limitation on the variable space due to how the linker has the space blocked out.
You are only able to declare 256 bytes of variable space in any one MPLAB project file.
Thanks for the information on the amount of memory available in each type of space! It's nice to have the quick summary as well as the pointer to the description in the manual.

An additional approach I might mention is one that we used last year in order to be able to have declarations of more than 256 bytes of variable space within a single MPLAB file -- we made use of the pragma directive to explicitly switch memory sections.

Code:
#pragma idata mem_section_1
  // put up to 256 bytes of declarations here

#pragma idata mem_section_2
  // put up to 256 more bytes of declarations here

#pragma idata mem_section_3
  // put up to 256 more bytes of declarations here

#pragma idata
  // actual code goes down here
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2013 Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"
  #9   Spotlight this post!  
Unread 01-12-2007, 11:57 AM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Itinerant Programmer
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 7,454
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How much memory is there really?

I'm a proponent of the pragma approach Ken described rather than modifying the linker directives. The pragma's are obvious and self-commenting in the code while the linker script is hidden and doesn't leave a discernable audit trail. Misuse of the linker script is also harder to ferret out from a distance.

Linker script modification is obviously not an issue for the current knowledgable programmer, but more so for clarity when future programmers borrow code and they can't figure out why it doesn't work.
__________________
The mind sees only what the mind is prepared to comprehend - Henri Bergson
358 Beta notes & results
  #10   Spotlight this post!  
Unread 01-12-2007, 12:50 PM
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: How much memory is there really?

Correct, specifying essentially hand placement of data by specifying data section via pragma is the better choice except when you want to build a single array that is larger than 256 bytes. Then you really don't have much choice except the linker modification.

Bud
  #11   Spotlight this post!  
Unread 01-12-2007, 01:17 PM
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
An inspired alumnus
AKA: Jamie Bliss
no team (previously 904 (D-cubed) and 1227 (Techno-Gremlins))
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Send a message via ICQ to Astronouth7303 Send a message via AIM to Astronouth7303 Send a message via MSN to Astronouth7303 Send a message via Yahoo to Astronouth7303
Re: How much memory is there really?

You may also be able to configure the compiler to use the large memory model instead of the small one. (At least with the full compiler, I don't know about the cbot version on the CD.)
  #12   Spotlight this post!  
Unread 01-12-2007, 07:57 PM
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How much memory is there really?

Whoa, Whoa, Whoa, back the truck up a wee bit. So I can't ROM declare variables? How many memory sections can I use #pragma on (1,2,3,4?) I don't understand where to put it nor what "actual code goes here" means. Can anyone kindly expain this to me?

And how do I calculate variable usage? For program usage, do I just hex convert what was posted above and subtract?
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #13   Spotlight this post!  
Unread 01-13-2007, 11:46 AM
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: How much memory is there really?

You can declare constants, not variables, in rom. You can use EEPROM and program (flash memory) for constants. You can write EEPROM and reflash code memory (blocks) - but both are slow operations compared to regular ram.

I've seen code/application somewhere - Kevin's code i believe - that had a write queue to eeprom for doing background writes. It eliminates having to wait to write the data but doesn't make writes any faster - that is, eeprom isn't a good place to have general read/write variables. It would be an ok place to store or build data for autonomous routines at the beginning of a match or for storing/updating variables that change infrequently (on the order of seconds between writes).

There is a 4k byte ram space, but a chunk of this is the memory mapped hardware control registers that serve specific functions. Another chunk is stack temporary variable space, another chunk is .tmpdata section used to hold intermediate computations for compiler generated code, another chunk is MATH_DATA section which holds temporaries for the math library, another chunk is used up if you use any of the interrupt driven uart routines for printf, etc.

I've never actually measured how much total ram space is really left for general user programmer, but maybe 2k. You can make this go a long way by using overlay and other means or you can just code and not worry about it until its gone. The only time I've had a problem is when I tried to build a number of arrays for debugging to hold/track data.

I strongly recommend reading the C18 user guide and PIC18F manual sections on memory models and address space to get a fuller understanding of how it works and the limitations of the different methods. If after reading these fairly short sections of the reference material you still have questions, feel freel to post them or private message me.

Like everything in life, there are tradeoffs and consequences of using the different types of memory available.


Bud

Last edited by dcbrown : 01-13-2007 at 11:49 AM.
  #14   Spotlight this post!  
Unread 02-05-2007, 02:42 PM
robind robind is offline
Registered User
FRC #0675
 
Join Date: Dec 2006
Location: Rohnert Park
Posts: 31
robind is an unknown quantity at this point
Re: How much memory is there really?

Actually, reading from EEPROM is very fast. It's the writing that's slow--and even then it's not that slow.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A robotic challenge that's really out there Richard Wallace General Forum 3 09-19-2006 08:26 PM
How much does Israel really cost the US tax payer?? Matt Attallah Chit-Chat 9 07-23-2006 01:18 AM
Is there really inspiration in teams? Philip W. General Forum 22 08-22-2005 11:53 AM
Do teachers really know that there talking about?!? Erodge Chit-Chat 17 10-19-2002 12:41 AM
how much is too much on the DRILL MOTORS? archiver 2001 11 06-23-2002 11:53 PM


All times are GMT -5. The time now is 12:28 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi