![]() |
Forum Index : Microcontroller and PC projects : MICROMITE DATE CALCULATION
Author | Message | ||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 982 |
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: AustraliaPosts: 935 |
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: AustraliaPosts: 982 |
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: AustraliaPosts: 935 |
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] |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6220 |
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. Jim VK7JH MMedit |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2400 |
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: AustraliaPosts: 982 |
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 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |