![]() |
Forum Index : Microcontroller and PC projects : Volatile RAM. Thinking DS1307 without battery.
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
I need to set a flag that persists when I stop and restart (or load) the program but that resets in the event of a power-down. We don't have a RAM feature that does this, right? I have played with the DS1307 without battery and it works great but I keep missing so many PicoMite capabilities/features that I thought I'd ask, first. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9512 |
Ages ago I put in something like this but no-one expressed any interest so I think it got lost at some stage. I could resurrect it. Something on the lines of SAVE PERSISTENT n% ? mm.info(PERSISTENT) |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9512 |
UPDATE Just tested and it works for CPU RESTART or watchdog reset but not for pressing reset button |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4527 |
Hi Phenix, Any R/W device that is connected could be used (when not reset by the driver). In example an LCD display that can be read (MISO/MOSI) as long as you do not clear the screen at start of your program, but first read it. Make a pixel red, and read it back. Volhout PicomiteVGA PETSCII ROBOTS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9512 |
UPDATE Works on RP2040 for both H/W and watchdog reset but only watchdog on RP2350. Have raised an issue with RPi as it should work for both |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
Perfect ![]() @Volhout: Yeah but it's nice no to have to add bits. ![]() I know you don't like this but the PIO quadrature counter persists even after re-initializing it by starting the MMBasic program. I have done this countless times and it never fails ![]() |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
But if power is removed from the RP2350? |
||||
twofingers Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1364 |
Just a reminder: The DS3231 RTC chip has 7 bytes that are actually intended for alarms. These could be used to remember states beyond power off. Michael causality ≠ correlation ≠ coincidence |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2098 |
this is a great tip! one caveat, the registers store BCD and are not fully 8 bits (bit 7 of each register means something) so you need to be attentive that any values written conform. I have just tried here writing &h7F, and it got munged into some weird value I have yet to interpret. Mine come from 99p modules off ebay so are probably chinese knock-offs so ymmv. Stick to a few flags in the bottom couple of bits and you should be fine. Edited 2025-01-22 07:23 by CaptainBoing |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2281 |
From DS1307 datasheet. So with no battery and Flag% stored there that should ensure the flag is only erased on power fail and not Reset. n%=54321 > SAVE PERSISTENT n% Error : Expected a string > SAVE PERSISTENT "n%" Error : Expected a string > ? mm.info(PERSISTENT) Error : Syntax > > option list PicoMiteVGA MMBasic RP2350A Edition V6.00.02b1 Another option if the Flag doesn't get updated too often. RTC GetTime If Val(Right$(Date$,4)) > 2024 Then VAR RESTORE Else Flag% = 0 EndIf RTC SetTime ....2025 '..... If InfrequentCondition Then VAR SAVE Flag% EndIf Edited 2025-01-22 10:18 by phil99 Footnote added 2025-01-22 21:59 by phil99 Late entry Beta2 has now been released with SAVE PERSISTENT added and as noted by @btwolf a few posts below this, some form of error test may be needed. He suggests a checksum. If that is 8 bits you still have 56 to play with. Though if the number saved is always less than say 32 bits a simple IF MM.INFO(PERSISTENT) < 2^32 Then ... or whatever will do. SAVE PERSISTENT 54321 > ? MM.INFO(PERSISTENT) 54321 > cpu restart > ? MM.INFO(PERSISTENT) 54321 PicoMiteVGA MMBasic RP2350A Edition V6.00.02b2 'reset button Copyright 2011-2024 Geoff Graham Copyright 2016-2024 Peter Mather > ? MM.INFO(PERSISTENT) 8695604412579392460 'random data after reset PicoMiteVGA MMBasic RP2350A Edition V6.00.02b2 'reset button Copyright 2011-2024 Geoff Graham Copyright 2016-2024 Peter Mather > ? MM.INFO(PERSISTENT) 4081666594875190157 > |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
Yeah, you won't have it because Pete only just reactivated it to test. ![]() |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7106 |
Hmmm... There's usually a hardware answer. :) Put a series resistor and capacitor on a GPIO pin. Put a diode from the top of the cap to 3V3, so that it's reverse-biased. Use SETPIN GPn DOUT / PIN(GPn)=1 to charge the capacitor (then SETPIN GPn OFF to isolate it if you want to). Even a small cap will stay charged for some time. When you boot the pin will be set as input by default so just use a%=pin(GPn) to read the status. When the power goes off the cap will discharge through the collapsing 3V3 rail so the flag will reset. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4527 |
Mick, Does not work with 2350 due to the GPIO bug. But I admit, it is simple. On the other hand, a 74HC74 flipflop can do similar (may require 2 resitors) on one GPIO pin. But if you (just) want to distinguish between reset due to power loss, and reset due to watchdog/internal failure there may be simpler solutions. Volhout Edited 2025-01-22 20:13 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
bfwolf Newbie ![]() Joined: 03/01/2025 Location: GermanyPosts: 26 |
Silly question: Why not use a dedicated RAM area and store different values there (depending on the desired state) with a CRC or "checksum" above them? Then "destroy" these values after the evaluation. After power-on, there are very likely random values in this RAM area and the CRC or "checksum" would then be incorrect and you would recognize this. You can also ensure that in "startup" after reset or watchdog the values are "destroyed" or overwritten by other defined values with the correct CRC or "checksum" and thus recognize that something like this was happening. You just have to find a RAM area that has a fixed address and is not affected by MMBasic. bfwolf |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4527 |
Mick, Simple idea: whenusing a original picomite, the Vbus is checked though GPIO24. Vbus is your input voltage. Vsys is the voltage that runs the RP2040. When you add a larger capacitor (supercap ?) to Vsys, the RP2040 keeps running for seconds to minutes (depending the size of the supercap) during which period you can sample Vbus, record the power fail, save the power fail (including date-time) in your filesystem... and then go down controlled. Just one e-cap or supercap, and a few lines of code. Volhout PicomiteVGA PETSCII ROBOTS |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
Some good info, here. Glad I brought it up ![]() |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2281 |
SAVE PERSISTENT and MM.INFO(PERSISTENT) added in b2. See footnote in my previous post. |
||||
bfwolf Newbie ![]() Joined: 03/01/2025 Location: GermanyPosts: 26 |
@PhenixRising, @Volhout: Did nobody notice my above post? ![]() It wasn't ment as a joke/hoax! I sometimes used this method e.g. to communicate between a bootloader and an application and vice versa! I's a simple method and takes no additional special hardware! The only thing to find is a RAM area (some bytes) which isn't affected by e.g. the startup-code. Some microcontrollers even have a seperated RAM area which is small and difficult to use as "common application RAM space". |
||||
Frank N. Furter Guru ![]() Joined: 28/05/2012 Location: GermanyPosts: 902 |
@PhenixRising: Please don't forget to put a diode in front of the capacitor from Volhout's idea. Then the capacitor cannot be discharged externally. This is how I have implemented it in the past and it has always worked well... Frank |
||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1024 |
It was the reason for the start of the thread. Before going for a hardware solution, I wondered if there was some sort of persistent-memory-while-power-was-applied that I was unaware of. Pete had already done this in the past but there was no interest and so it was disabled. Now it has been reinstated and works perfectly for my needs. See phil99's posts from earlier. Edited 2025-01-23 17:43 by PhenixRising |
||||
Page 1 of 2 ![]() ![]() |
![]() |