The Sunday Blog: Engineering with Nextion HMI
Power supply considerations
Designing a device containing a Nextion HMI, a microcontroller (MCU), and perhaps still a few other peripherals is more than just designing a nifty GUI, writing some Nextion code, and writing some code for the MCU. Often neglected, making sure that all components are well powered under all, even the worst conditions, can be crucial as our level 1 support team could recently see.
That’s why I decided to shed some light on some technical details which are important to know.
Regulated power, maximum current and inner resistance of a power source
Yes, I’m taking you back to school for a little moment. But it’s highly important to remember some basic concepts to avoid critical situations!
A regulated power supply is characterized by a constant output voltage and a maximum current which it can source while maintaining the output voltage constant, or at least within an indicated tolerance band. A USB phone charger for example, should output 5V +/-5%, which means something between 4.75 and 5.25V, independent of the amount of charging current actually drawn by the phone or any other load, at least as long as the maximum current of 1A (example of my iPhone charger) or 2.4A (example of my iPad charger) is not exceeded.
Within the allowed operating range, the inner resistance (dU/dI) of our power source is close to zero, huge variations of the load current will cause almost no variation of the voltage – the regulation does its job.
If you try now to draw more than the allowed maximum current, several things can happen, depending of the innards of our charger. Ideally, it would limit the sourced current to keep it below or at the maximum value, and it would do it by lowering the voltage. This means that the inner resistance would go up towards infinite because even a small excess of drawn current would cause a rather high voltage drop. At the same time, the charger’s power dissipation would have to go up, transforming the voltage drop times the fixed limited current into… heat! Not good!
From this, we learn that we should never try to draw more than the indicated maximum current from a regulated power source, because all the positive properties within the allowed operation area turn into the opposite when you try, willingly or unwillingly, to push the limits.
Now, let’s look at it from the other side
Our load, now not longer our iPhone or iPad but our Nextion HMI device, expects and requires the supply voltage to never drop below 4.75V as stated in the data sheet. Let’s assume for a moment the worst case, that our USB charger is already at the lower end of the tolerance band and delivers exactly the 4.75V, even when we draw the nominal current of 410mA which is the typical value taken again from the NX8048T050 data sheet. “Typical” means typical. That also means that the current actually drawn by our Nextion can be somewhat higher or lower for some time (we’ll see below why) but the average current will be 410mA. You see it already come, there are reasons why a power supply capable to deliver 1A or 1000mA is required.
But before we move on, there is another factor which we didn’t yet take into account: The wiring, or, more specifically, the cable between the charger and our Nextion. Let’s imagine that our cable is 1m (3ft) long, has perhaps already had a life and thus slightly corroded contacts, and thus is far from being a superconductor but rather has a still small resistance of 0.5 Ohms. Not much, you’ll say. But even at the nominal current of 410mA, we’ll have a voltage drop of 0.205V over these 0.5 Ohms. So, from our initially still sufficient 4.75V at the power supply, only 4.545V will arrive at the Nextion, which is below the minimum specification and which can lead to unstable and unpredictable behavior, or even damage the device (the famous brown out effect). Oooops…
And the dynamic side
Up to now, we have seen our Nextion as a constant load for our power supply, similar to a light bulb or a LED. But it isn’t:
First, there is a short but intense consumption peak when you power it on. It’s called the inrush current, needed to load all the capacitors on the PCB and the millions of MOSFET junction capacitances within the CPU, the LCD driver, and the RAM up to their initial values at boot time.
Second, there is the LCD backlight controller, a PWM controlled SMPS. That means, it will either draw the maximum current or none at all. The higher the display brightness is set, the longer these consumption peaks will be (and the pauses shorter), but there will be always peaks as long as the display brightness is not null.
Third, write operations from the CPU to the LCD driver chip, and read operations on the flash memory chip by the MCU are also more power demanding for short moments.
All this makes that if you trace the current consumption of a Nextion HMI with an oscilloscope, you’ll never see a flat constant consumption of the typical current, but a pattern of short and complex peaks and valleys around the average value.
And with these peaks and valleys, our previously mentioned cable behaves even worse, since besides the already discussed resistance, all cables have also a small but inherent inductance. Remember, inductance implies an impedance (similar to a resistance) which grows with the frequency. This makes that our voltage losses will be the more, the shorter the rise and fall times of our consumption peaks and valleys are. In extreme situations, this can even lead to ringing (the voltage swings ways over the theoretic maximum or ways under the theoretic minimum) with again a high risk of damaging your Nextion HMI.
And now that we understand all this?
As we have a good overview over all things which can happen, but which will not always happen, but which must not happen, let’s fix them one by one:
First, to remain within the allowed operation area of the power supply, take the typical overall current consumption of all components (for example Nextion 410mA, MCU 90mA, other peripherals 130mA, 2 extra LEDs 40mA), sum it up (670mA in our example) and, as a rule of thumb, multiply it by 2.5 (1675mA in our example). Next higher available value is 1800mA or 2A, both will be fine.
Second, now powering your assembly with this suitable supply, take an multimeter and check the voltage at the 5V input of each component (Nextion, MCU, other peripherals) and make sure that the voltage at the power supply’s output (should not be already at the lower end of the tolerance band) and the one which arrives at the components is within the required specifications from the respective data sheets. That’s the static part.
Third, the dynamic part requires an oscilloscope to make sure that the supply voltage at all component’s inputs never drops below the specified minimum voltage, even not for a nanosecond or you risk trouble. If you observe such voltage valleys, and be they very short, you’ll have to either shorten or thicken the power wiring (reduces resistance and impedance). If that is not sufficient, you should add an electrolytic capacitor (typical values are between 47 and 470uF) as a buffer close to the affected power supply input, so that its charge can jump in during short drops and it will fill up again (recharge) in periods of weaker consumption.
A note about USB powering in general
A USB port will deliver 500mA by default. The USB 3.x specification rises that to 1.5 or sometimes 2A. But not all USB 3.x ports behave the same. Some will simply deliver the higher current if needed without any special action. Others will continue to limit the current to strictly 500mA unless the connected device negotiates a higher current delivery by sending corresponding requests over the USB data lines. In ever case, the usual FTDI or CP2102 USB to TTL UART adapters won’t negotiate whatever power demand. So, don’t take higher currents than 500mA for granted and use preferably other ways of 5V power supply, especially for more complex circuits and devices.
The final word
Now that we have refreshed our basic knowledge and we have virtually gone through all possible highs and lows of powering circuits, we should not longer see unstable or unpredictable behavior, but our designs around a Nextion HMI should be rock stable.
Thank you for reading and happy Nextioning!