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 KingdomPosts: 512 |
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 KingdomPosts: 6798 |
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 KingdomPosts: 512 |
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 KingdomPosts: 6798 |
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: AustraliaPosts: 897 |
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. |
||||
Bleep Guru Joined: 09/01/2022 Location: United KingdomPosts: 512 |
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 KingdomPosts: 6798 |
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 |