![]() |
Forum Index : Microcontroller and PC projects : Closing #1 after power failure
![]() ![]() |
|||||
Author | Message | ||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
@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: AustriaPosts: 19 |
![]() 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 KingdomPosts: 10315 |
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 KingdomPosts: 1646 |
Very ![]() I think that I have a similar use for this ![]() |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
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 KingdomPosts: 1646 |
@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 StatesPosts: 159 |
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 KingdomPosts: 1646 |
Oh sure and don't forget Winbond |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Be there, done that, got the tee shirt... https://www.thebackshed.com/forum/ViewTopic.php?TID=11033&PID=129472#129472#129472 Jim VK7JH MMedit |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |