anlog input pin powering Arduino Nano?

Hi,
I am performing tests with the circuit diagram shown in the attachment.
D4 is used as a PWM output.
A7 is used to measure the voltage at the drain of the MOSFET.
The MOSFET is used as a high side switch charging the accu via R2.

When the USB connection is removed but the external 5V supply still is connected the LEDs on the Nano are lighting up.
When the connection to A7 is removed the LEDs are off.
The accu seems to power the Nano via R2.

The Atmel description of Atmega328 does not give me enough details to understand how the analog input can power the controller.
Usually in my tests, at first I am switching off the external 5V and then disconnect USB. But there are many tests, and sometimes I forget to switch off external 5V.

Up to now the controller survived and still is working.
But can it be dangerous for the controller chip when it is powered via A7?

In a future circuit not only the charging circuit but also the Nano shall be powered via external 5V using the pin "+5V" on the Nano. From the schematic of the Nano this should be no problem.
Is this really ok?

SupArdu

schematic_1.JPG

SupArdu:
The Atmel description of Atmega328 does not give me enough details to understand how the analog input can power the controller.

Yes it does - chapter 18 - I/O ports describes the protection diodes between the pins and Vcc/gnd, and shows them schematically in figure 18-1. Furthermore, Table 32-1 Absolute Maximum Ratings specifies that the voltage on any pin must not exceed Vcc by more than half a volt - when the unit is not powered, Vcc is 0, but you're putting 5v onto an I/O pin. Like most digital IC's, each pin has an internal diode between it and Vcc and Gnd, to prevent the voltage from exceeding Vcc or being lower than ground - in your case, you were backpowering it through that protection diode - a diode meant to handle only very low current.

Up to now the controller survived and still is working.
But can it be dangerous for the controller chip when it is powered via A7?
Yes, it is the easiest way to blow a pin.

In a future circuit not only the charging circuit but also the Nano shall be powered via external 5V using the pin "+5V" on the Nano. From the schematic of the Nano this should be no problem.
Is this really ok?

Yes if it's a nano or pro mini (thanks to the diode and simple power circuit). Boards without the diode, that use some other power supply circuit, like the Uno/Leo/Mega, will often damage the 16u2 serial adapter if you plug them into USB while external 5v supply is connected (the clones use other serial adapters that are less susceptible to this, but they can still be damaged).