How to get datalogger to write into memory once per hour?

TravisH

New Member
I am using a Picaxe 28X1 fw A.0, a 24LC256, a DS1307 and 3 DS18B20's (with the Program Editor ver. 5.1.5) in an application that could be used in various situations to monitor and log time & temp., etc.

The LCD display (4 X 20) shows day of week, time, date, and the temperatures for three different areas of an aquaponics system. My existing code takes 3-4 seconds to go through the temperature read, time register read, and display parts of the program and return to the beginning. This is OK as I don't need to read the temps from the DS19B20's any quicker than that. The end user can see the various temperatures and time in "somewhat" realtime.

This is my first major Picaxe project. I've gotten the program to read the three DS18B20's relying heavily on phanderson's code, found some code for the DS1307 on this forum, and wrote my own three push button scheme to externally set the date, month, year, hour, DOW and minute. Dr_Acula is right, it takes a LOT of code to do that (1200+ lines of memory/code).

And now to work on the datalogging portion of the code.

However, my question is this: what would be the best way to arrange the program to take one reading per hour? I've poked at this long enough so that all the other code works as expected. As mentioned above it takes about three-four seconds to loop through the existing code, I've run out of variables to use, so I can't check the variables for the (say) seconds (b0) and minutes (b1) and have something like if b0 = 59 and b1 = 59 then take reading and write to the 24LC256 because the other parts of the code use the existing variable for other purposes;

With the firmware I have I think I can use flag5 as one of the variable "flags" but I really need two.

I've looked at the timer and timer variable, but the first time I read about it I thought I understood it, but now, after many additional reviews, I'm not quite sure of my own name anymore! Maybe that's the answer, but I just can't get my head around the timer yet.

I've tried setting flags using the memory in the on-board EEPROM such as:

pseudo code:
if minutes = 59 then goto already_set
if minutes = 59 then write value to eeprom

already_set:
(some other code)
read eeprom
if seconds = 59 and minutes = 59 then gosub take_reading

Unfortunately this reads an eeprom location about 28K times a day and I figure I'd blow out that eeprom location in about a month or so, unless only writes to an eeprom wear them out, but I think it's read OR write that wears out an eeprom location?

Have I written my self into the proverbial corner? Or can some clever soul tell me a concept that will allow me to allow the program to continue to run showing time, date and temperatures in almost realtime and log the temperatures and time into the 24LC256 once an hour, considering I may only have one variable left to use? (Please no code, just the idea/concept; more fun that way<g>)
Thanks,
Trav
 

lbenson

Senior Member
Many ways to accomplish what you want. First, have you looked at westaust55's memory table here, at post 14 in this thread?

http://www.picaxeforum.co.uk/showthread.php?t=9525

When you say you are using all the registers, are you using all 28 available on the 28X1? Plus ptr? Do some of your variables have values of only 0 or 1--if they do then you could use the bit variables bit0-31 (occupying the same space as b0, b1, b2, b3, also w0 & w1)--use only as many as you need.

You can also use peek and poke to store infrequently used variables in SFR memory (0x50 - 0x7E, 0xC0 - 0xEF). You could use ptr and @ptr and @ptrinc in a loop to move, say, registers 14-27 to the scratchpad (128 bytes available), then use the registers as you like (say to read the DS1307), and then restore the values you had moved to the scratchpad.

Regarding the 24LC256, I'd welcome correction if I am wrong, but I thought that only writes would cause it to wear out. A question--do these devices have wear-leveling?

If you are worried about many reads and writes to the same location for your seconds and minutes, can you put those values in registers and put less frequently changing values in the eeprom?

Are you using the internal SFR (PEEK/POKE) and eeprom areas (READ/WRITE)?

If you want to do something once an hour, save a variable lasthour and do what you want only when the current hour, read from the DS1307, is different from lasthour (and then save the current as lasthour).
 
Last edited:

boriz

Senior Member
Firstly, you may not have run out of variables. Look up the POKE command. You have some RAM available that works almost exactly like the built in variables. It can be used to store data just like variables, or to temporarily store variables while they get used for something else. IE: &#8230;POKE 80,W0&#8230;then use B0 and B1 for something else then&#8230; PEEK 80,W1 to restore the previous B0 and B1 values.

There are probably several methods to do what you want. The best will depend on the rest of your code, but here&#8217;s some ideas off the top of my head&#8230;

-Add a small delay in your loop so that it ALWAYS takes exactly 5 seconds per loop. Then count the loops. 720 loops = 1 hour. (or 15 seconds per loop / 240 loops. Has the advantage of only using a byte variable)

-Each time your read the RTC, compare the time (min+sec) with a local value that does not change. They will be the same only once per hour. IE: when minutes = 00 and seconds = 00, then write your data.

-Or store a local copy of the RTC hour value. When they differ, it means the RTC clock has advanced to the next hour and you can then write your data and reset the local copy of the hour value.
 
Last edited:

westaust55

Moderator
dattalogging once per hour

The Programming Editor contains a Wizard for the Rev Ed AXE110 datalogger.

Have you had a look at that? You can set up the time intervals, etc in that Wizard.

While it is for a different (smaller) PICAXE, you can paste the code into the programming editor as an example showing how the AXE110 sets up intervals.

Access the Wizards from the PE toolbar with PICAXE / Wizards
then select the AXE110 datalogger.

==========
As you are using Programming Editor V5.1.5, you should also look to upgrading to V5.2.1 available for free under the software tab on Rev Eds website: http://www.rev-ed.co.uk/picaxe/
 
Last edited:

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum,

1200+ lines of code seems a lot for what you describe so there may be other ways to do it in less lines although it does depend upon exactly what you are doing. Early PICAXE programs are often more complicated than they need to be as tricks of the trade are still being learned, similarly with the first version of any program; it's getting it working which is more important than anything else, optimisation can come later.

One thing to have a look at is subroutines ( GOSUB, RETURN ) as these can often be used to save on repeating code which is common throughout the program.

Don't worry about repeated reads of Eeprom ( internal or I2C ). You have an infinite read ability, only excessive writing will wear an Eeprom out.

If you do want to improve your main loop timing ( 3-4 seconds ) the time taken is probably down to reading multiple DS18B20's each time through the loop. One technique is to read just one BS18B20 per loop. This will reduce the loop time although it does mean that some temperature readings held will be a few seconds older than the last taken. For a system where there won't be fast temperature changes this would probably be acceptable.
 

TravisH

New Member
Datalogging once per hour

@ibenson-

The memory table is awesome; it does pay to have a map when you are in unfamiliar territory!

I tried the @ptr and @ptrinc at first, but the editor complained that my firmware wouldn't let me do what I was trying to do; I'll try that again as I'm a little fuzzy on that whole idea;

@boriz-

Up to now I haven't used PEEK & POKE; guess that makes me a POKE virgin <g> but I like the idea of using RAM and staying out off eeprom unless I absolutely have to use it;

@westaust55-

Hadn't tried the wizards yet, but I wish I had; that thing is sweet, and if I'd seen some of that code last month it sure would have saved me some time; BTW thanks for your hard work on that memory map, in the past I've made up an excel spreadsheet to keep track of the variables I use but now I think I'll just print out copies of your map per each project and use that as SOP;

@hippy-

Yes, you are right. 1200 lines for the external set function is alot, and after reading everyone's comments I think I should use the on board eeprom to store the text for each screen as currently all that text is hard coded. The project is at the "does it work yet?" stage; I took a BASIC course in the late 1960's and the instructor stressed the 3 F's; no, not nasty words when your code doesn't work (but, or course, I use those, too), but "form follows function". Time enough later to put lipstick on my pig <g> Thanks for clarifying the eeprom read/write issue. I was aware of the overhead in trying to read 3 DS18B20's but just lived with it, but didn't think to read them sequentially. Good to keep in mind if I need to speed things up.

Thanks again to all. All these ideas will keep me busy for quite awhile,
Trav
 

BCJKiwi

Senior Member
@ Trav
There are a number of issues with @ptr and associated ptr functionality for A.0 rev firmware.

There are work-arounds for most of those issues and most were resolved at FW A.2 - now at FW A.5
 
Top