Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:03 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 : Closing #1 after power failure

     Page 2 of 2    
Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 07:45am 03 Jan 2022
Copy link to clipboard 
Print this post

@Chrisk,

What you could do is close the file after each write. That sooner or later will wear out the card (*). So to avoid this you could start a new log file each year (or each month). Use Date$ as part of your filename, and you can glue them together later in a word processor or excell.

Volhout
(*) the card has it's own microcontroller that does wear leveling. This means that it will write the new file after close in a new location before killing the old one. And it will do this so smart, that the card lasts very long. So opening a new file as described above, may not help for some cards since the card is smarter than us.
Edited 2022-01-03 17:48 by Volhout
PicomiteVGA PETSCII ROBOTS
 
rentner111
Newbie

Joined: 18/03/2014
Location: Austria
Posts: 19
Posted: 08:41am 04 Jan 2022
Copy link to clipboard 
Print this post


I keep having data that needs to be saved every minute. But I write them in the RAM of the Micromite. At regular intervals, e.g. B. every ten minutes, I then write from the RAM to an EEPROM or to an SD card. In the event of a power failure, the last data is saved in the micromite with VAR SAVE data (). When the power returns, the data is read out again with RESTORE and is available without loss.
The following simple circuit is used for this, which manages with a few components and without a battery. This circuit has also proven itself for years with the MM170, MM470.
The application with the PICOMITE is shown in the drawing. With these values, a data array from data (0) to data (16) with a content of 16 bytes can be safely stored. If you want to store more, you only have to enlarge the support cap.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 09:11am 04 Jan 2022
Copy link to clipboard 
Print this post

I'll fix this issue in the next release (V5.07.05RC7 now posted) by adding a FLUSH #fnum command. This will write anything in the file output buffer to the disk so even without closing the file the data won't be lost. Just execute FLUSH #filenumber after any critical writes
Edited 2022-01-04 19:46 by matherp
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:10am 04 Jan 2022
Copy link to clipboard 
Print this post

  rentner111 said  
I keep having data that needs to be saved every minute. But I write them in the RAM of the Micromite. At regular intervals, e.g. B. every ten minutes, I then write from the RAM to an EEPROM or to an SD card. In the event of a power failure, the last data is saved in the micromite with VAR SAVE data (). When the power returns, the data is read out again with RESTORE and is available without loss.
The following simple circuit is used for this, which manages with a few components and without a battery. This circuit has also proven itself for years with the MM170, MM470.
The application with the PICOMITE is shown in the drawing. With these values, a data array from data (0) to data (16) with a content of 16 bytes can be safely stored. If you want to store more, you only have to enlarge the support cap.


Very  

I think that I have a similar use for this  
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 10:28am 04 Jan 2022
Copy link to clipboard 
Print this post

If your main power is via USB you can read VBUS (i.e. that supply) using PIN(GP24).
If you now connect a reasonably sized battery (say 2 or 3 AAA cells or even a 3V coin cell) to VSYS via a schottky diode then you have an emergency backup. There's no current drawn from the standby supply normally as it's diode is reverse-biased.

Test GP24 to see if your main supply is healthy or not. If it isn't then read GP29 to check the on-load voltage of your standby battery (it reads VSYS/3). GP24 going low could trigger an interrupt to close files etc. You wouldn't need a lot of capacity or voltage from the standby supply as the Pico SMPS is happy down to 1.8V input.

It's quite possible to add an external Li-ion battery & charger to the Pico. It's also possible to switch the standby supply via a mosfet so that you have an even lower voltage drop than the diode.
Edited 2022-01-04 20:44 by Mixtel90
Mick

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

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 12:15pm 04 Jan 2022
Copy link to clipboard 
Print this post

@Mixtel90

I was considering the battery backup feature but all I need is to preserve production part-count. This capacitor device will respond to a power-outage and give me time to store the part count.
 
flasherror
Senior Member

Joined: 07/01/2019
Location: United States
Posts: 159
Posted: 12:37pm 04 Jan 2022
Copy link to clipboard 
Print this post

There is another option that might be a good fit here.

Microchip 47C04/47C16 I2C EERAM with capacitor backup and auto/manual power fail save to EEPROM. Looks like a I2C RAM (writing to it saves immediately to RAM and doesn't require usual "wait for EEPROM save to complete" time) but it can detect power failure and save RAM to EEPROM automatically (with use of a power reservoir cap). Pinout is mostly the same as standard I2C EEPROMs.

https://www.microchip.com/content/dam/mchp/documents/OTH/ProductDocuments/DataSheets/47L04_47C04_47L16_47C16_DS20005371D.pdf

This might allow you to get rid of the bulky 2200uF caps. You write once a minute to it and don't care afterward - when power fails it will save to EEPROM which can be read on power-up and allow you to retain count or whatever non-volatile data you need.
Edited 2022-01-04 22:50 by flasherror
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 12:50pm 04 Jan 2022
Copy link to clipboard 
Print this post

Oh sure and don't forget Winbond
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:00pm 04 Jan 2022
Copy link to clipboard 
Print this post

  Quote  There is another option that might be a good fit here.

Microchip 47C04/47C16 I2C EERAM with capacitor backup


Be there, done that, got the tee shirt...

https://www.thebackshed.com/forum/ViewTopic.php?TID=11033&PID=129472#129472#129472

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