Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:46 02 Aug 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 : an alternative to VAR SAVE

     Page 2 of 2    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 06:08pm 25 Jan 2019
Copy link to clipboard 
Print this post

  lew247 said  ... its storing with trailing zeros

Post your current code.
Edited by lizby 2019-01-27
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:49pm 25 Jan 2019
Copy link to clipboard 
Print this post

The only differences to the code on page 1 is I'm not using the same doing "do/Loop and doing the following instead

[code]CONST SRAMsize = 512 ' size of 47x04

secs2 = 0 'Value for first power up
r = setup() ' we only have to do this once for each chip
r = writeDATA(10,"00000")
z$ = readDATA$(10,5) ' 5 bytes starting at address 10 (any address will do)
print "Sram Check "+z$

secs=(Val(Left$(Time$,2)) Mod 12) * 3600 + Val(Mid$(Time$,4,2)) * 60 + Val(Right$(Time$,2)) ' total clock's seconds past midnight
DO
fast
LOOP UNTIL secs = secs2


SUB fast
for g = 1 to secs
print secs, " Seconds since 12:00:00" 'so we know the number of to catch up to the current time
secs2 = secs2 +1
t$=time$
r = writeDATA(10,str$(secs2)) 'Update Sram
z$ = readDATA$(10,5) 'read Sram
print secs2 'Secs2
print z$, " Z$" 'Print Sram data SHOULD BE TRAILING ZEROS and should be identical to Secs
END SUB[/code]Edited by lew247 2019-01-27
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 08:09pm 25 Jan 2019
Copy link to clipboard 
Print this post

Can't say that I can see anything obvious in this or the prior code, other than that something ("END"?) needs to follow LOOP to prevent falling through into SUB fast, and "NEXT g" is needed before END SUB.

If you simplify so that you write one fixed value and try to read it back in, are they the same?

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:24pm 25 Jan 2019
Copy link to clipboard 
Print this post

try
r = writeDATA(10,str$(secs2,5,0," ")) 'Update Sram

or
r = writeDATA(10,str$(secs2,5,0,"0")) 'Update Sram

That will right align the number and either spaces before or zeros.
Either way should work.

JimEdited by TassyJim 2019-01-27
VK7JH
MMedit
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:35pm 25 Jan 2019
Copy link to clipboard 
Print this post

Thanks Jim
Very very close, you gave me enough info to solve it thanks
[code]r = writeDATA(10,str$(secs2,5,0,"0")) 'Update Sram[/code]
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 10:48am 26 Jan 2019
Copy link to clipboard 
Print this post

I've found one last problem I cannot solve

When the program is 1st booted up the Sram is empty and it shows the following if read




When the program is running normally I check on power up and read the value in the Sram and then use that value in the program

However on 1st boot the value is nonsense and the program stalls

I "could" give the Sram a value of "00000" on first power up but then the program is no use after the 1st power up because it will always write to "00000" to the Sram overwriting what the correct figure is

Is there any way that anyone knows to tell the program that if it returns the "garbage" shown above on 1st power up then write to the Sram but if the value is a number from 0 to 43000 then don't write "00000" ?

Reading that back I can't put what I see in my head into simple words

I think the best way to describe it is

Is there any way to read the Sram and if the returned value is not a number then tell it to do one thing
and if it's a number do something else?

 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:55pm 26 Jan 2019
Copy link to clipboard 
Print this post

Once you have used the chip once, it should NOT be 'empty'
I just fired my setup up after 2 weeks and the old shutdown time was there as expected.

You have to configure the chip before use so you could put a known value in there at that time.

In you sub, you are writing to the ram and immediately reading from it.
Why?

Can you post your current code - complete.

What chip do you have and do you have the capacitor installed. Without it, the backup won't work.

Jim
VK7JH
MMedit
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:24pm 26 Jan 2019
Copy link to clipboard 
Print this post

  TassyJim said  
In you sub, you are writing to the ram and immediately reading from it.
Why
Jim


I wanted to find a way that should the MM crash and reboot then when the program starts instead of writing the figure "00000" which is the figure written into the Sram on 1st power up
it will ignore this part of the program and just used the value stored in the Sram

The only way I can think of is to run a short program that writes "00000" to the Sram and then load the proper MM program aftewards without writing to the Sram on power up
IE as you say don't use a blank SramEdited by lew247 2019-01-28
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:45pm 26 Jan 2019
Copy link to clipboard 
Print this post

OK
With a new unused chip the memory is full of chr$(255)
you could check for that with
z$ = readDATA$(10,5)
print asc(z$)


if asc(Z$) is 255, then this memory location has not been written to yet.

Unless you have a shipload of disposable chips, I don't see the need.

Jim

VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:00pm 26 Jan 2019
Copy link to clipboard 
Print this post

Lew,
If you are trying to tell the difference between a power failure/restoration and the user switching off and on,
I suggest that you check for a button being pressed during startup.
If the button is pressed, skip the correction routine.
I assume that it is the clock you told me about earlier in which case, you can use one of the existing buttons.

I am still concerned if you are seeing chr$(255) on a chip that has been used.

Jim

VK7JH
MMedit
 
     Page 2 of 2    
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