Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:24 28 Nov 2024 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 : Var Save very slow?

Author Message
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 512
Posted: 08:49am 24 Jun 2023
Copy link to clipboard 
Print this post

Hi,
I have a program running a 1 second loop, the code takes roughly 0.2S so I have a WatchDog timer set to 1500 (1.5Sec) however I was finding that the timer was timing out sometimes, I tracked it down to Var Save, every Var Save seems to take about a third of a second, first is this expected? second, if not any chance of a fix?
Sample code follows for a VGA, but it's the same on standard.
> option list
PicoMiteVGA MMBasic Version 5.07.07b32
OPTION SYSTEM I2C GP22,GP15
OPTION COLOURCODE ON
OPTION KEYBOARD UK
OPTION DISPLAY 60, 106
OPTION SDCARD GP5, GP2, GP3, GP4
OPTION AUDIO GP6,GP7, ON PWM CHANNEL 3
OPTION RTC AUTO ENABLE
OPTION DEFAULT FONT 7, 1
> list
Dim float a(1),b,c(2)
a(0)=42.42:a(1)=3.14159
b=6.9532
c(0)=4.59:c(1)=659.32
Timer =0
VAR Save b
Print Timer
Timer =0
VAR Save b,a(),c()
Print Timer
VAR Save b,a(),c()
VAR Save b,a(),c()
VAR Save b,a(),c()
VAR Save b,a(),c()
Print Timer
> run
391.639
393.078
1958.415
>

Any help appreciated.
Regards, Kevin.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 09:00am 24 Jun 2023
Copy link to clipboard 
Print this post

VAR SAVE was never really intended for heavy usage. The idea was to give somewhere where some variables could be stored through power off and then recovered next time the device was re-booted. It's probably ok on the Pico, but on some other platforms it uses relatively short lifetime flash and, in theory, it's possible to wear it out. Because of this usage pattern I don't think its speed has ever been of any consequence. The best way to save some variables on a PicoMite is probably to write them to a file. on A:.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 512
Posted: 09:16am 24 Jun 2023
Copy link to clipboard 
Print this post

I'm only saving once an hour, so this is not a problem, it' just the fact that it takes up quite a chunk of time, when I do use it, especially if I have to do 2 seperate Var Saves, which happens at midnight.
Regards, Kevin.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 09:26am 24 Jun 2023
Copy link to clipboard 
Print this post

I've never noticed it to be slow, but then again I've never used it in any other way. :). VAR SAVE is a flash write command so it may be stopping all interrupts until it completes. That might screw things up a bit.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 897
Posted: 11:02am 24 Jun 2023
Copy link to clipboard 
Print this post

Each time VAR SAVE is called its has to erase the 16K of flash allocated for saved variables, then write the actual variables to the flash. You could look at using RTC battery backed memory.

  The Manual said  
Saved Variables
Because the PicoMite does not necessarily have a normal storage system it needs to save data that can be
recovered when power is restored. This can be done with the VAR SAVE command which will save the
variables listed on its command line in non-volatile flash memory. The space reserved for saved variables is
16KB.
These variables can be restored with the VAR RESTORE command which will add all the saved variables to
the variable table of the running program. Normally this command is placed near the start of a program so that
the variables are ready for use by the program.
This facility is intended for saving calibration data, user selected options and other items which change
infrequently. It should not be used for high speed saves as you may wear out the flash memory. The flash used
for the Raspberry Pi Pico has a high endurance but this can be exceeded by a program that repeatedly saves
variables. If you do want to save data often you should add a real time clock chip. The RTC commands can
then be used to store and retrieve data from the RTC's battery backed memory. See the RTC command for
more details.


Latest F4 Latest H7
 
Bleep
Guru

Joined: 09/01/2022
Location: United Kingdom
Posts: 512
Posted: 06:14pm 24 Jun 2023
Copy link to clipboard 
Print this post

Hi, well if it is erasing the whole 16k block that might explain why it takes so long, but still 0.39 Sec per erase/save seems a very long time even to do that, though I'm unsure it's doing that because I'm doing 2 separate Var Saves, with different variables being saved, in separate parts of the program & I think they are all still present? if each Var Save erased first then only the latest set of Var Save variables would be preserved. I'll have to check that? :-(
I'm not using an RTC, I'm using the built-in Date/Time, its currently only gaining 2 seconds a day, which I'm correcting at midnight ;-) along with a Var Save of 5 bits of data. Total Wh, In/out, Daily Wh In/out and a current status integer & then later writing some current status info to a daily log file. I don't have an sd either so this is all going to internal flash, this is very minimalist, only a 2 line lcd, because it's running off solar/battery only 8mA display on or 5mA display off from 12V supply.
Regards Kevin.
Edited 2023-06-25 04:17 by Bleep
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 06:42pm 24 Jun 2023
Copy link to clipboard 
Print this post

VAR SAVE updates any existing saved variables of the same name and adds any new ones that have been listed. VAR RESTORE simply restores all saved variables.

If your program is running continuously it might be better to simply write changed data with the time to a log file every so often. If it hasn't changed since it was last written then don't write it again. The "every so often" might be a SETTICK interrupt every minute or something.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


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

© JAQ Software 2024