Or-ing circuit that allows battery charging

Hello
I'm working on a project where the system is powered by a 4 cells battery (with bms included) and solar pannel.
The battery is inside the device and the solar pannel is attach to it every time.
So, i want to power my system using the battery or the solar panell when needed but i also want that the battery is charged up from the solar pannel.

To improve system reliability i've included a 16V fixed tension regulator that trasform and keep constat the 20V of the solar pannel.

Than i have a voltage regulator setted at 5V to power the system.

Finally i have created an OR-ing circuit to switch between the two power sources (16V regulator and battery) before the 5V regulator.
To charge the battery i've added a line direct to it from the 16V regulator.

I know that it might not be the most efficent solution but i need something low budget and easy to create!

I'm running some tests, the system work fine, to emulate some power from solar pannel i'm using an external power supply fixet at 20V but when i connect the battery i can see the power supply throttling and i'm wondering what i've missed.

That solution can work?

(sorry for my bad english)

The normal way a solar system is built is the battery is at the center with the solar cells charging the battery and the battery feeds the inverter. You are showing a lot of parts but if I understand you all you need is a small board, either the Adafruit bq25185 in the voltage you need or a bq24704.

Ok thanks, I need to implement the electronics on my board, but I don't understand what's wrong... In a previous version of this project, the battery was connected in parallel to the solar panel and the system worked decently... I want to keep things simple... I can't figure out why I'm having this problem with the external power supply...

The circuit is incorrect. The correct circuit using the old parts is somewhere on the forum but the single chip solution I posted is the modern version.

What kind of battery?
You need a battery charger somewhere in your design.

a 4 cells battery mede up of 18650 whit a bms attched to it

Then you a Battery charger IC that can safely charge a 4s Li-ion battery.

Question1: does your BMS work as a charger or as over/undervoltage protection only?
Question2: where does that potentiometer fit in? (Show connected stuff.)

i'm using this BMS:

It's a BMS that allow to charge, discharge, protect 4 cels battery packs.

Regarding the potentiometer it' s only used to divide the voltage so that it can be read in the Arduino Nano Every or IoT ranges.

You still need a charger.
You can't just connect a voltage to a battery to charge it

ok, wat kind? i can't access to the single cels, thanks to the BMS i can only see the output voltage!
And theorically the BMS it self when sense tension on P+ P- will charge the cells (at least is wat the producer said)

Solar one. If you try with regular charger, your set charge current will never match the actual panel current.

Theorically that is true but it will charge until the batteries explode, the BMS burns out or the power source burns out.

Look for a solar charge controller

The charge current of your BMS is not defined, you need to measure that before you use it as a charger.
Taking a measurement after a pot makes it unreliable unless carefully calibrated.
At some position of the pot the current to the analog input pin is limited by the 120ohm resistor, you might blow that input.

Assuming your BMS works as a charger I get to this circuit:

Measure the voltage with INTERNAL 1V1 reference. It will give you an indication near full or near empty (when discharging), but not a percentage of charge.
It will not optimize the solar panel.

A BMS is not a battery charger. It is for protection of the battery against overcharge and overdischarge.

In either case it disconnects the actual batteries from the rest of the circuitry.

You will need a separate 4S battery charger for a 4S cell pack containing that BMS.

With a charger the circuit becomes this:

Of course there may additional components dependent on the specific charger.

If you see the charger as my LM2596, pratically is the same circuit, my external power is the solar pannel it self.

Running other tests i've found that i have to increase voltage out from LM2596 to charge up the battery, i need at least 16.8V to charge it but due to tolerances and other things i found that at P+ P- of the BMS i have 16.5V, after raising that up I managed to charge the battery a bit but the LM turn hot after a few minutes.

It certainly depends on the current draw the battery actually requires at the start of charging.
The battery is made up of 4 cells in series, so I sized everything to withstand up to 2A, but the initial demand is certainly very high.

I repeat, I know full well that what I'm doing isn't the best method, but I want the customer to have a battery pack that's easy to replace, and it needs to be simple for me to build, too. That's why I put the BMS directly in the battery pack, but perhaps I need to change the model to allow for proper charging.
In that case, would I still need to size a special charger?

In any case, I'd just like to see what's going on, since my previous colleague simply connected everything in parallel and the system worked. I just wanted to make that method safer!

Well you didn't. See post #13

perhaps I need to change the model to allow for proper charging.
In that case, would I still need to size a special charger?

Well that has been suggested several times. You must have the correct charger type to charge a Li-ion battery or you run the risk of fire or explosion!

You might consider the BQ25672 from TI

Thank you so much for your patience. This is my first time designing a battery pack and everything needed to manage it...

Now I'm going to study the component you recommended.

After some research, I also found the MP26124GR and BQ24650, whose datasheets I'm studying. What do you think? Can you confirm that I can simply install this before the BMS and be fine? Or do you recommend replacing the BMS as well?

Thanks again!

Should be OK as long as you don't exceed the battery maximum charging current or the BMS maximum current.