Remembering things between powerups

Started by FiveseveN, January 14, 2021, 04:14:30 PM

Previous topic - Next topic

FiveseveN

I've been thinking about something lately, not strictly pertaining to stompboxes but I'm sure the lovely people here can offer some insight:
The ability to save presets is one of the best things about digital control and maybe you've encountered the issue of wanting to load the last preset that was on before you unplugged your pedalboard. Saving things is easy enough for a microcontroller but it won't know when the session is over and it should save its state before it loses power. It's not like pedals demand to be shut down gracefully like computers do.
I suppose the proper way to implement it is a sort of brownout detector which instructs the system that shutdown is coming and it should do a save before the filter caps run out.
The dirtiest way would be to save every time the preset is changed, right? Might not be an issue with wear-leveling and today's ample amounts of storage.
Most commercial units I've seen use coin cells to keep some memory powered but I haven't looked at much or very recent stuff. Any thoughts on how this is usually / can be more elegantly achieved?
Quote from: R.G. on July 31, 2018, 10:34:30 PMDoes the circuit sound better when oriented to magnetic north under a pyramid?

potul

The usual approach is to save the state every time you change preset. You can implement some leveling to avoid saving always in the same memory address, but at the end you need to check what is the expected life of the eeprom/flash you use and see if it's really an issue with normal usage.

Rob Strand

QuoteThe dirtiest way would be to save every time the preset is changed, right? Might not be an issue with wear-leveling and today's ample amounts of storage.
Most commercial units I've seen use coin cells to keep some memory powered but I haven't looked at much or very recent stuff. Any thoughts on how this is usually / can be more elegantly achieved?
If you don't want to write each time it gets complicated.    You need to detect when the power has been removed, and write out the data.  The power reservoir needs to be large enough to allow you to write the data.    You can shut off power hungry parts of the circuit during that period.

However, if you think about the simple case of writing the settings each time,  there is a small window where the power could be pulled and you are writing data and that could corrupt the memory.

The whole data corruption thing is another level.   If you have a checksum then at least you know it's corrupt.   For a non-critical devices you can reset the settings.   You can have the last known good settings saved but that needs to be save without corruption!
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

hgamal

Some devices, such as Microchip PIC18, has a feature called HLVD (High Low Voltage Detection). This feature generates an interrupt when some lower (or higher) power voltage is detected. On this interrupt, the state can be saved to the EEPROM or flash memory. Once the energy is going down, it is advisable to maintain the quantity of state to be written low.

I think it is possible to create LVD (Low Voltage Detector) for devices without this feature, using some external circuitry and some available fast interrupt pin.
Haroldo Gamal

niektb

I think I would go with writing the current preset to an eeprom, not sure what the effects would be on lifetime. I suppose you could mitigate that with some circular buffer-ish approach. Always write to the next empty memory address. If the EEPROM is filled up, erase the contents of the memory and start again.

potul

What microcontroler are you using?

Atmel guarantees 100k write cycles in EEPROM. This gives you something like 50 preset changes per day during 5 years.... assuming you play every day.

One thing you can do at least is avoid writing to EEPROM when scrolling through presets. So, wait for some stabilization time before saving.

potul

Quote from: niektb on January 15, 2021, 07:32:06 AM
I think I would go with writing the current preset to an eeprom, not sure what the effects would be on lifetime. I suppose you could mitigate that with some circular buffer-ish approach. Always write to the next empty memory address. If the EEPROM is filled up, erase the contents of the memory and start again.
If you take this approach, you still need to know where to read from when you power up, so you need to keep a pointer somewhere in a fix place in EEPROM. Same issue... Maybe there is a creative way to do this in some other way...

potul

I found this application note explaninig a circular buffer approach to maximize endurance of EEPROM,

https://www.microchip.com//wwwAppNotes/AppNotes.aspx?appnote=en592140

Digital Larry

Quote from: potul on January 15, 2021, 08:40:04 AM
If you take this approach, you still need to know where to read from when you power up, so you need to keep a pointer somewhere in a fix place in EEPROM. Same issue... Maybe there is a creative way to do this in some other way...
Let's meet at the park.  If I get there first I'll make a chalk mark on the sidewalk.  If you get there first, erase it.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

potul

Quote from: Digital Larry on January 15, 2021, 09:09:51 AM
Quote from: potul on January 15, 2021, 08:40:04 AM
If you take this approach, you still need to know where to read from when you power up, so you need to keep a pointer somewhere in a fix place in EEPROM. Same issue... Maybe there is a creative way to do this in some other way...
Let's meet at the park.  If I get there first I'll make a chalk mark on the sidewalk.  If you get there first, erase it.
;D

pruttelherrie

Quote from: Digital Larry on January 15, 2021, 09:09:51 AM
Quote from: potul on January 15, 2021, 08:40:04 AM
If you take this approach, you still need to know where to read from when you power up, so you need to keep a pointer somewhere in a fix place in EEPROM. Same issue... Maybe there is a creative way to do this in some other way...
Let's meet at the park.  If I get there first I'll make a chalk mark on the sidewalk.  If you get there first, erase it.
But where's the park?


Anyway, here's some info (in German; I happen to live close enough to the German border to be able to read it without Google Translate) on how to lengthen the time for writing the EEPROM when a brownout is detected:
https://www.mikrocontroller.net/articles/Speicher#EEPROM-Schreibzugriffe_minimieren

By the way, depending on microcontroller, writes might be whole pages at once (looking at you, bluepill!). Something to think about.

niektb

Quote from: potul on January 15, 2021, 08:40:04 AM
Quote from: niektb on January 15, 2021, 07:32:06 AM
I think I would go with writing the current preset to an eeprom, not sure what the effects would be on lifetime. I suppose you could mitigate that with some circular buffer-ish approach. Always write to the next empty memory address. If the EEPROM is filled up, erase the contents of the memory and start again.
If you take this approach, you still need to know where to read from when you power up, so you need to keep a pointer somewhere in a fix place in EEPROM. Same issue... Maybe there is a creative way to do this in some other way...

No you don't! In my proposal the latest non-empty memory address is the read address (so that's the difference from a true circular buffer), and the write address is read_address+1  (the first empty address) :)
(And as mentioned, when the end of the eeprom is reached everything is erased and the write pointer starts at the first memory address :)

FiveseveN

Quote from: potul on January 15, 2021, 08:38:06 AM
What microcontroler are you using?
It was a general question. I am planning on using an ESP32 for something, and that has some quirks around storage. To be honest, when I first encountered the issue I thought it wasn't worth the hassle, since I could let the user pick a particular startup preset and that probably covers most needs. But using up a pin to detect loss of power isn't a big deal either.
Quote from: R.G. on July 31, 2018, 10:34:30 PMDoes the circuit sound better when oriented to magnetic north under a pyramid?

ElectricDruid

I've done this as a proof of concept on a PIC. Don't know how hard it is on other devices.

If you have a capacitor providing power to an ADC input, when the power dies, the value on that ADC input goes *up* (since it remains the same as the main power dies out). If you detect that increase, you can use it to trigger a EEPROM write of the current settings. That takes a couple of milliseconds, but it's not hard to arrange the capacitors on the *power* to give you 5-10msecs further power so you can be sure to get the EEPROM write done before the power goes down completely.

Ok, there's a little bit of thinking required to make sure that the ADC "power down" input stays up longer than the main power rail, and that the main power rail stays up long enough to do the write, but actually, it's not that demanding. It took me a morning to get it working on the breadboard. Unfortunately I've never used it since, but I've stuck it in the toolkit, I suppose!

This way, you only save the settings on actual *power downs* not *every time something changes* which obvious extends your EEPROM life out into "don't care, it's so long" territory.

I can probably dig out the code and post it if anyone is interested. The original scheme was suggested to me by Roman Sowa on the SDIY list, so I can't claim it as an original idea.

HTH,
Tom






anotherjim

If you use "real" physical panel controls and have the system sync up with them on power-up, you can have the real hardware experience with a digital system. The problem with this is that it doesn't suit having presets - the panel is the one & only preset. Well, unless you want to motorize everything. Still, it's the system I personally prefer.

If you don't want a load of pots and switches and only have a digital encoder, buttons & menu interface, at least use mechanical rotary switches for the presets. A pair of 10way switches can select 100 presets - then have it start-up with the preset the switches are pointing to!

Footswitch selection can't sync with mechanical preset switches on the device, those would have to be soft. In this case, it would be desirable to save the last used preset and store when it's been called for some time (a second or two maybe).

If you choose to save anything on power loss, the onboard brownout detector can be too late! Monitor the immediate DC power input, block it from benefitting from your supply caps with a diode so it drops fast and have plenty of capacitance to keep the CPU power up for long enough.  I think the brownout detector is to warn the system to NOT attempt EEPROM writes to avoid corruption.

Then there is MIDI control. This allows a setlist approach and multiple devices can be sent program change messages. Here the user doesn't care if the device can remember the last preset on powerup. Many commercial digital devices always powerup with a default preset and the users are used to having to call the right presets. Anway, serious pros will have UPS power for devices so only the power amps will drop out.




Sooner Boomer

Today, one might use a form on NV RAM such as an EEPROM. Another way is to use static RAM (like a Hitachi 6116), and a battery (with as a diode power supply switch).
Dan of  ̶9̶  only 5 Toes
I'm not getting older, I'm getting "vintage"

FiveseveN

Quote from: anotherjim on January 17, 2021, 05:17:23 AM
Monitor the immediate DC power input, block it from benefitting from your supply caps with a diode so it drops fast and have plenty of capacitance to keep the CPU power up for long enough.
Yes, that's the gist of it. When I manage to order some chips I'll give it a try.
Quote from: R.G. on July 31, 2018, 10:34:30 PMDoes the circuit sound better when oriented to magnetic north under a pyramid?

mauferra1527

Hi  another interesting way is to use  an eeram chip. It works like normal ram, but it backups / restores contents automatically at power up / down.

https://www.microchip.com/en-us/products/memory/serial-eeram

Regards

potul

Quote from: mauferra1527 on January 20, 2021, 03:03:36 AM
Hi  another interesting way is to use  an eeram chip. It works like normal ram, but it backups / restores contents automatically at power up / down.

https://www.microchip.com/en-us/products/memory/serial-eeram

Regards

Wow, I was not aware of these devices. This looks interesting... it's basically implementing what Tom was proposing, already included in the memory chip.


ElectricDruid

Quote from: potul on January 20, 2021, 08:17:57 AM
Quote from: mauferra1527 on January 20, 2021, 03:03:36 AM
Hi  another interesting way is to use  an eeram chip. It works like normal ram, but it backups / restores contents automatically at power up / down.

https://www.microchip.com/en-us/products/memory/serial-eeram

Regards

Wow, I was not aware of these devices. This looks interesting... it's basically implementing what Tom was proposing, already included in the memory chip.

Me neither, or I might not have bothered! Those look like damn handy little chips!!