|
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 : 13-01-2007 at 11:49.
|