Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:39 12 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MICROMITE DATE CALCULATION

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 12:58pm 30 Jul 2014
Copy link to clipboard 
Print this post

I will put this one to the TBS thinktank. I am trying to keep a track of date using the VAR SAVE and VAR RESTORE to cover the case when the solar power supply may dip too low and cause a reset. At midnight I test the date and if the date is newer than that saved it should be updated. The problem is the code I am using is taking too much memory and crashing regularly. Can anyone think of a more efficient way to do this? This is the error that appears:

[73] DATREV$=Right$(Date$,2)+Mid$(Date$,4,2)+Left$(Date$,2)
Error: Not enough memory


This is the snippet of code that's checks:

If Time$="00:00:10" Then 'UPDATE LAST KNOWN DATE
ALARM1=0 'RESET ERROR COUNTER
DATREV$=Right$(Date$,2)+Mid$(Date$,4,2)+Left$(Date$,2)
DATNVM$=Mid$(INFO$,19,2)+Mid$(INFO$,14,2)+Mid$(INFO$,11,2)
If Val(DATREV$)>Val(DATNVM$) Then
INFO$=Left$(INFO$,10)+Date$
VAR SAVE INFO$
Print "NEW NVM INFO$ SAVED ";INFO$;
EndIf
Print " ERROR COUNTER RESET TO ";ALARM1
Pause 600
EndIf


GM
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 01:59pm 30 Jul 2014
Copy link to clipboard 
Print this post

You could try using all MID$
If Date$ is dd/mm/yyyy then
[code]
DATREV$=Mid$(Date$,9,2)+Mid$(Date$,4,2)+Mid$(Date$,1,2)
[/code]
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 01:06pm 01 Aug 2014
Copy link to clipboard 
Print this post

Bob, I wasn't sure if changing to Mid$ would make a lot of difference but I am not aware of how both functions operate within MMBasic. I did give it a whirl.....

[60] DATREV$=Mid$(Date$,7,2)+Mid$(Date$,4,2)+Mid$(Date$,2,2)
Error: Not enough memory


Still same result

BTW here are the memory stats just prior to the Error

Flash:
16K (82% of 20K) Program (625 lines)
28b ( 1% of 1536b) 1 Saved Variables

RAM:
19K (85%) 62 Variables
1K ( 2%) General
2K (13%) Free
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:16pm 01 Aug 2014
Copy link to clipboard 
Print this post

Graeme, I don't know the internals of MMBasic but here is a guess. Your problem is the last status line of RAM. 2K free. If I recall correctly, strings are 256 bytes each and in that line of code you may be allocating 4 of them even if only temporary. Try splitting that line up into 2 or 3 concatenations. Use your original code if you want.
[code]
DATREV$=Mid$(Date$,7,2)+Mid$(Date$,4,2)
DATREV$=DATREV$+Mid$(Date$,2,2)
[/code]
or
[code]
DATREV$=Right$(Date$,2)
DATREV$=DATREV$+Mid$(Date$,4,2)
DATREV$=DATREV$+Left$(Date$,2)
[/code]Edited by BobD 2014-08-03
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6220
Posted: 02:33pm 01 Aug 2014
Copy link to clipboard 
Print this post

Do you need to do the test at all?
Why not simply update Info$ whenever the time is right.
It should have changed but if not, no harm done.

If Time$="00:00:10" Then 'UPDATE LAST KNOWN DATE
ALARM1=0 'RESET ERROR COUNTER
INFO$=Left$(INFO$,10)+Date$
VAR SAVE INFO$
Print "NEW NVM INFO$ SAVED ";INFO$;
Print " ERROR COUNTER RESET TO ";ALARM1
Pause 600
EndIf


It reminds me of a program I wrote to fix a year 2000 bug in some customers PCs.
They were too tight to upgrade the hardware.

JimEdited by TassyJim 2014-08-03
VK7JH
MMedit
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2400
Posted: 04:04pm 01 Aug 2014
Copy link to clipboard 
Print this post

too many strings in your code - with the advent of the micromite it might be a good time to ask geoff to revisit the notion of being able to set the length of regular strings (as opposed to only arrays of strings). either globally, or via static declarations.

but as things stand, you can either use far fewer strings in your code, and recycle them wherever possible, or use arrays of strings, where the length of the strings in an array can be fixed at something much less than 255 characters each.


cheers,
rob :-)
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 09:57pm 01 Aug 2014
Copy link to clipboard 
Print this post

  Quote  Do you need to do the test at all?
Why not simply update Info$ whenever the time is right.
It should have changed but if not, no harm done.


I have been thinking since your post Jim, and haven't convinced myself why I should keep the test for a newer date. Possibly the only reason would be if corruption of the instruction to update the clock throws things out of wack. I like to keep things as simple as possible and will go with your thought of just save the new date anyway and see how it goes.

Thanks for your input
GM
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025