not enough variables

axeman22

Member
Hi All,

Something very basic is bugging me - no pun!

I always seem to be running out of variables.! Granted I'm not a professional code writer so perhaps not following the most ideal practices but I am used to being able to have practically as many variables as I want.

To have just B0-B13 etc is killing me.. I am playing with a DS3232 and I can easily use up all b0-b13 .. Then I'm run out. Granted, 14 variables usually seems to be enough within a subroutine but within a greater full program I seem to always want more. Perhaps I store my variables different sections of EEPROM and just load what I need for the various subroutines then store at the end again etc..?

I'm sure there must be some basic concept which I'm missing.

Thanks :)
 

Svejk

Senior Member
It all depends on what Picaxe version are you using. M parts have 14 named variables [b0-b13], x1 and x2 parts may have up to 56 named variables. Have a look in Manual #2.

Also, on some versions you can indirect access variables, see peek and poke commands in the same Manual.

On the other hand, named variables can be reused if due care is taken.

It would help if you post your code so others can have a look at it and make apropriate sugestions.
 

Chavaquiah

Senior Member
Perhaps I store my variables different sections of EEPROM and just load what I need for the various subroutines then store at the end again etc..?
That's the right idea, in general. Just do not use EEPROM for that (limited number of reads and writes before it starts failing).

Svejk pointed you in the right direction with PEEK and POKE.
 

axeman22

Member
Ok. Will post the code when I'm back home.

I want to make use of the temperatrure sensor in the DS3232 and record daily highs and lows..

So need a half decent amount of non volatile memory. I'm getting the vibe that I jPust should not look at using the EEPROM In the PICAXE and look at using some kind of external memory chip via I2C etc? Any suggestion on a good memory chip etc for this?
 

lanternfish

Senior Member
I find that by allocating some general purpose variables (2 - 4 depending on the app) is a good way of manipulating data while still have a small number of named variables.

Optimising subroutines/gosubs makes all the difference. And I ain't that knowledgable about the finer points of optimising.

Some may argue that good programming results in reduced code. It can also result in unreadable code.
 

westaust55

Moderator
The lower byte variables b0, b1 and extra on later PICAXE chips are also available as bit variables.
So if you have values that are only 0 or 1 such as for simple (eg Yes/No, On/Off) type status flag then use bit variable rather than byte (8-bit) variable.

If you map out you variable useage and where they are required it is possible to reuse the variables several times.

Then if that that does not work you can save variables in SFR RAM.
My memory may covering most PICAXE chips here may help you in identifying what extra RAM each chip has:
http://www.picaxeforum.co.uk/showthread.php?t=11514
 

westaust55

Moderator
The DS3232 RTC chip that axeman22 is using also has 236 bytes of battery backed RAM which could be used for storage without some of the timing issues related to EEPROM chips.

Even the ubiquitous DS1307 RTC (or the DS1338 with fast i2c comms that I often use) has 56 bytes of battery backed RAM.
 
Top