Computers crash if they do not have enough voltage.
Li-Ion batteries could explode during charging if they were deeply discharged.
How can we prevent such events?
We need so-called voltage supervisors.
Cheap parts with a big effect, which usually do their job in the dark.
Let’s tear them to the light and protect your ESP32 or Arduino from not booting correctly
and your Raspberry from a crash.
Grüezi YouTubers.
Here is the guy with the Swiss accent.
With a new episode and fresh ideas around sensors and microcontrollers.
Remember: If you subscribe, you will always sit in the first row.
All electronic parts have a maximum voltage, and many parts also have a minimum voltage.
Above the maximum voltage, they are usually destroyed, and below the minimum voltage,
they do no more work properly.
No more properly can mean that: - They just switch off.
This is not a big issue.
- Or they start to oscillate.
This can create issues in other parts of the circuit, like excess currents or overvoltage.
Not good - Or, and this is often the case with MCUs,
they do unpredictable things because they are very complex
Today, we will focus on the third application.
Instability because of low voltage even is exploited by hackers.
They manipulate the supply voltage of computers to make the MCU disclose “secrets.”
These attacks are called “power glitch attacks As normal users, we want to avoid such things
as much as possible.
The ESP32, as well as the Raspberry Pi, run on 3.3 volts.
The ESP is rated for a minimum voltage of 2.3 volts.
I did not check the datasheet of the MCU used in the Raspberry.
But the Raspberry 4 automatically switches off if the USB power is below 3.5 volts.
This is done to make sure the MCU of the Raspberry never is on with voltages below 3.3 volts.
After this video, you should know how they do it.
The voltages below 2.3 volts for the ESP32 should be avoided because of the negative
effects mentioned before.
We have to distinguish two cases: 1.
At power-up where the voltage starts at 0 volts and ends around 3.3 volts.
During this surge for sure, it passes the range below 2.3 volts
2.
When operating with battery power.
If the battery discharges, the MCU gets less and less voltage and, if the battery has no
under-voltage protection, slowly enters the unsafe area.
If you use a voltage regulator, this effect can start at a voltage as high as 3 volts.
Let’s focus on the first case: If we power our devices up, the voltage takes some time
to rise from zero to 3.3 volts.
During this time, the processor passes areas where it easily can become unstable.
This instability can stay even if the 3.3 volts are reached, and the MCU does not work
unless you reset it.
You all saw this behavior once in a while on your Arduinos or ESPs.
It is quite easy to create such a situation.
I use a standard blink sketch and a ESP32 WROOM module powered by this power supply
which is set to 0.2A max current.
If I switch the power supply on, it starts to blink.
As expected.
Now I add a capacitor between Vcc and ground.
Like that, VCC takes longer, around 40 ms, to rise to the 3.3 volts.
If I switch the power supply on, it does not blink.
The ESP32 seems to be somehow on.
At least it consumes 16mA.
I would say, it is in a limbo state.
This situation can happen all the time.
Usually we switch off and on, or we press reset and everything is ok.
But if this device is in a remote location, this is not an easy situation.
To show you what happened, I start with 0 and slowly increase the voltage for the WROOM
module.
At about 1.5 volts, it starts to produce gibberish.
Later, it produces this error messages because it cannot read from the flash chip, because
the ESP32 chip starts to work at a lower voltage than the flash chip.
These are exactly those unforeseeable situations we want to avoid in our designs.
An easy way to stop all this instability is keeping the reset, sometimes also called enable
pin, to 0V until a stable 3.3 volts is reached.
Then we avoid all these problems.
Often, engineers use a simple trick: They delay the voltage increase at the reset pin
compared to Vcc by adding a capacitor and a resistor.
Like that, the capacitor is charged slowly, and the reset pin stays low until Vcc is stable.
Let’s check if the WROOM module also uses this trick.
I connect the yellow channel to VCC and the green to the enable pin.
And really, we see the expected behavior.
The reset rises after Vcc.
And if we see in the diagram of the WROOM module, we see the capacitor.
For many cases this is sufficient.
Let’s now look at case two.
If you completely switch your computer off, usually you create no problems because the
MCU stops working very fast.
If your project is battery powered, the battery voltage is reduced very slowly, and your MCU
can get in this unstable area.
This is particularly true for solar-powered projects, where the battery can later charge
up, and your MCU stays in this unstable situation and needs manual intervention.
How can we avoid this?
If we manage to keep the reset pin always low when Vcc is in unsafe areas, the processor
should never get into such instable situations.
No matter how they are produced.
This is exactly the purpose of voltage supervisors.
For obvious reasons you find them in many professional applications because they improve
the reliability of a device.
But how do they work?
Because they have to react at a fixed voltage, they need a voltage reference.
Then they have to compare the actual Vcc with this reference voltage and set the reset pin
to low as long as Vcc is lower than the reference.
Because these voltage supervisors are connected to Vcc, they have to work also at low voltages.
Here I have a few of those parts.
Often they look like transistors and have three legs.
Internally, they look very similar: A voltage reference, a comparator, and an “open collector
transistor.
The input pin is dual purpose.
Its first purpose is the power supply for the voltage reference and the comparator.
And second, usually, via a resistor network, it is connected to the positive input of the
comparator.
Why the two resistors?
Because voltage references usually do not exactly produce the voltage you need.
And maybe also, because the manufacturer can use a very similar design to produce several
parts with different voltages, as we see here.
I assume they use a 2.5-volt reference and add the needed resistors.
Sometimes the trimming of the resistor value is done during production using lasers.
Like that, they can change the production output easily to different voltages.
BTW: We see that those KA75xxx chips are obsolete.
But I still like them for breadboard usage, because they are through hole.
I have here two versions: One for 3.3 volts and one for 4.5 volts.
So, let’s check them out.
Their usage is very simple.
Connect pin 1 to Vcc and pin 2 to GND.
A resistor to VCC is needed on pin 3 to pull the open collector up.
The size of the resistor is not very important for our usage.
I used 22k because I have lots of them in my assortment.
To test them out, I connect a varying Vcc produced by my signal generator to both chips.
Its minimum voltage is 0 volts, and its maximum is 5 volts.
The frequency is 0.1 Hz.
So we simulate a supply voltage which is slowly switched on and off once every 10 seconds.
Yellow is Vcc; green is the curve at the output of the 3.3-volt version, and magenta the output
of the 4.5 volts version.
We see that the 3.3-volt version switches at around 3.3 volts.
We also see a small hysteresis, which means that it switches on at a higher voltage than
off.
Such a hysteresis is used to prevent uncontrolled oscillations.
Very good.
The 4.5 volts version has a similar behavior but at 4.5 volts.
We also see that both switch on below a level of roughly 0.7 volts.
But then the MCU is already powered off.
So they do what we expect.
They are not very expensive, 20 cents for the 3.3 volts version, and 70 cents the 4.5
volts version.
Unfortunately, I did not find versions for below 3 volts on Aliexpress.
But LCSC has other voltages, and also other brands.
You see, these parts are quite common.
Here I have a newer chip for the same purpose: The TPS3839.
It also has three pins with a similar function.
If we connect it to the same signal, we see that is switches very similar to the values
of the KA75330.
One difference is that it does not need a pullup resistor.
Another difference becomes visible if we increase the speed of Vcc to 1 Hz.
The TPS3839 switches around 200 ms later than the KA75330.
This is to give the MCU enough time to settle everything.
Definitively an advantage.
Let’s now connect the TPS3839 to the enable pin of the ESP32 and see how it behaves.
First, the ESP blinks also with the slowly increasing Vcc.
If we have a closer look, the reset stays low for 200 ms after the ESP is powered up.
The rise of the voltage at the reset pin is very steep.
And if we power the ESP at 3 volts, the reset pin stays low and the ESP is in reset mode.
Even Espressif requests to use such a supervisor if you use battery power on the ESP32.
And, if you, for example, use a 3 volts supervisor for your Li-Ion battery-powered ESP32, it
resets the ESP below 3 volts.
If we consult the datasheet, we see that the ESP32 only uses a very small current in this
state.
So your battery automatically is protected against deep discharge.
Of course, only if you have no other parts consuming current.
Otherwise, we have to use a p-channel FET like the IRLZ44N I use here.
This FET switches your whole device off if the battery voltage is below 3 volts.
A simple and cheap battery protection.
Of course, you can use a smaller transistor.
If you are subscribed to this channel you for sure remember video #310 where we looked
at how we find transistors which fit this purpose.
We can use these devices for a different purpose.
If I connect an LED with a current limiting resistor to the output, we can create a battery
indicator.
The KA75330 and the KA75450 switch on when the battery level is too low.
Maybe not a very good idea for many applications, because the LED drains the battery even if
the processor is off.
The TPS3839 can be used to indicate that the battery is good or needs recharging.
But it only can source 8mA max.
BTW: You also get parts that set the output to high for low voltage situations.
One of those could be used in conjunction with a p-channel FET to get the same result
as before with the n-channel FET.
We can also connect the output of such a supervisor to GPIO3 of the Raspberry Pi.
As shown in video #273, it then shuts the Raspberry down when the voltage is low.
If we add two super caps, our Raspberry is protected against power loss because it safely
shuts down if the input voltage becomes lower than 4.5 volts.
Cool.
Summarized: - We discovered a class of parts which is
often used in professional devices, but not well known to the general public
- We saw that the ESP32 does not like low voltages and easily can get into a limbo state
- This can also be true for other MCUs like Arduinos
- We learned that hackers use such states to attack servers
- We learned that voltage supervisor chips are built to solve this problem
- We know now how voltage supervisor chips work
- Even Espressif requests such a supervisor for battery-powered systems
- Because MCUs use much less power if reset such a device is a simple protector against
the deep discharge of your Li-Ion batteries - If we need more, we can add a FET and power
our whole project off at low voltages and switch them safely on again.
This is especially important for solar-powered projects
- We saw a possibility to prevent computers like the Raspberry to crash
- And we created useful voltage indicators for other projects using the same chips
I hope, this video was useful or at least interesting for you.
If true, please consider supporting the channel to secure its future existence.
You find the links in the description.
Thank you!
Bye
https://www.wired.com/story/plundervolt-intel-chips-sgx-hack/ https://www.pcmag.com /encyclopedia/term/glitch-attack
https://wiki.newae.com/V4:Tutorial_A3_VCC_Glitch_Attacks