Need help on switching battery to a charger using MOSFETs - Page 1
Forum section: electronics / projects

author: jb82
author_rank: Contributor
timestamp: May 18, 2025, 04:41:06 pm
content: I'm currently stuck at a bigger project. I have a general idea how to approach it, which might as well be impossible to do. But from the start...What I'm trying to doI have an array of 49 upward facing poles, arranged in a 7x7 pattern. A 6s LiPo battery (~24V) can be connected to any two poles. My goal is to design circuitry that detects these poles and connects them to a battery charger that will charge with a current of around 10A. I'm currently struggling with switching the actual charger connection.The naive approach would be an army of mechanical relays that can switch each pole to + or - on the charger, but, for economical, spatial and maintenance reasons, I'd like to use MOSFETs instead. However, the gate-source and drain-source voltages need to be referenced to the same potential. I would probably tie system ground and battery negative together, but I'd need to do this before the MOSFETs can switch on, at which point I don't have a connection to the battery. It's a chicken-and-egg problem.More detailed description of what I've done so far:The following schematics show my general idea for the positive and negative connection (designed with four poles only for brevity):The positive and negative circuitry each are connected to all poles, so each pole can be switched to either the positive or negative battery charger terminal.TheCHG_N/Plines go to the contacts of the battery charger.CHRG_N/P_SWis the gate signal for the MOSFETs. The CD74HC4067M is a bidirectional multiplexer that forwards the signal to the correct MOSFET to save GPIOs.Gxx_N/Pare the switched gate signals, and lastly,PADxx_N/Pare the connections to the 49 poles, of which two connect to the battery.So, my question is: How to supply the signalCHRG_N/P_SWto the MOSFET gates (Vgs). Any signal coming from my circuitry would be referenced to the system ground of my circuitry (SYS_GND), but Vds of the mosfets would come from the battery and thus would have a different reference.Also, If my approach simply doesn't work, I'm open for different approaches altogether.(Optional) Some context about what I'm trying to doThe array of poles is part of a hangar for an autonomous drone. The drone can land on this array and contacts in the drone's landing gear will make contact with any two poles. The contacts on the drone are then connected to the battery and serve as charging ports. In the end, these poles should connect the drone's battery to a charger to initiate an autonomous charging cycle.

author: Buriedcode
author_rank: Super Contributor
timestamp: May 19, 2025, 12:07:00 am
content: If I understand the project correctly - you have a connector mounted to a drone facing down, and a static connector, facing up. These have an array of 49 pins/contacts aranged in a grid 7x7. On one of those connectors, a battery is connected across "any two poles" ? Is this random? or different for each drone? (edit: I wrote this before I read the last paragraph of your post!)I understand the issue with switching mosfets - you can't reference your circuit to GND first, because you don't know whether that is connected to a battery positive or negative - but that could be corrected by trying every combination using a multiplexer (and current limiting resistors, because thats quite a high voltage for analogue muxes, so limit the current and the clamp didoes will hold the voltage to VDD + 0.6 and VEE - 0.6). Until the output is a voltage across a load. That is a complicated but "doable" problem - requires 4x 8 to 1 Muxes, and a micro to automate it.Once you know which poles have a voltage across them - and also the polarity, you can then connect a back-to-back N channel MOSFET to the negative side - so it is referenced to your system/charger ground, then you can connect the positive pole to the charger + with P channel - given your system is now referenced to the battery's negative, and the P channel is referenced to the battery positive pulling its gate low will turn it on, connecting it to your charger positive.But.. this requires a N channel and P channel MOSFETfor every pole. Likely it will have to be a double MOSFET because the body diode will conduct in different combinations. Thats 49 x 2 (back to back) x 2 (P and N) = 196 MOSFET's. 92 SOIC dual switches.I think it's a solvable problem with electronics, but a complicated and expensive one.Alternatives would be a mechanical approach - if my original assumption about the application is correct, why not design a connector that can only fit one way? And only a few contacts? And self-corrects alignment? I don't know why you would need 49 poles, unless it's about alignement? Also, why would the battery be connected across two random contacts? Surely you connect the battery across just two, and the landing pad has say 64, with half of one side as one pole, and half the other, that way you just need to know the polarity.

author: Peabody
author_rank: Super Contributor
timestamp: May 19, 2025, 03:31:21 am
content: It appears you want the drone to be connected no matter where it lands or its orientation.I wonder if there's a way to set up your pole array in a seemingly scrambled way so that 24 squares are A squares and 24 squares are B squares, and all the As are connected together and all the Bs are connected together. Then with the drone's battery terminals a set distance apart, they would never both connect to A or both to B. Then you could have 14 switches instead of 49. But I kinda doubt that's possible. I don't even know what kind of problem that is, or how you would brute force code it.Well whether you're multiplexing 7x7 or 1x49, you could connect all possible pairs one at a time to an optocoupler, which would notify the CPU that the plus and minus poles have been identified.Edit: Let me start over on the grid layout. It turns out that 9x9 will work. So you would have a grid of 9x9 poles, with each pole on one of 9 lines, connected like this:Code:1 2 3 1 2 3 1 2 34 5 6 4 5 6 4 5 67 8 9 7 8 9 7 8 91 2 3 1 2 3 1 2 34 5 6 4 5 6 4 5 67 8 9 7 8 9 7 8 91 2 3 1 2 3 1 2 34 5 6 4 5 6 4 5 67 8 9 7 8 9 7 8 9All the 1s are connected together, and all the 2s, etc., so there are just nine separate lines.The battery terminals are a bit less than one square apart, so they can bridge one square either adjacent or diagonally. With this setup the two terminals can never fall on the same line where they would be shorted.So you would connect one line number, theoretically as positive, to the anode input of an optocoupler through a high value resistor, and test the other 8 lines one at a time as the negative. Then test the next line the same way. At some point the optocoupler will turn on, and that tells you you have identified the positive and negative poles.

author: twospoons
author_rank: Frequent Contributor
timestamp: May 19, 2025, 03:56:14 am
content: This might be a good application for wireless power transfer (there aren't many) . Replace your array of poles with a suitable transmit coil, and put a receive coil on your drone. It should cope with a reasonable amount of lateral misalignment, and any rotation. No need for a monster array of switches. Many of the Qi charging chips can drive several transmit coils, picking the one with the best coupling.

author: jb82
author_rank: Contributor
timestamp: May 19, 2025, 12:45:53 pm
content: Thanks for all responses so far!Quote from: Buriedcode on May 19, 2025, 12:07:00 amThe drone is supposed to perform landing with RTK-assisted GPS. Depending on the signal, and with unpredictable winds before touchdown, it can be considerably off from the perfect spot in any direction and with notable skew. We want to build a large area on which the drone can land as badly as it wants and still make contact. This company seems to pursue a similar approach, by the way:https://www.skycharge.de/drone-charging-pad.Of course there are also different approaches altogether. We currently use assisted landing with optical markers and exactly two charging pads. That works too, but also has it's drawbacks. This project is merely an attempt to evaluate a new possibility.Quote from: Peabody on May 19, 2025, 03:31:21 amThat's a great idea. I originally wanted every contact to be independent, but I'll probably have to make concessions. I'll definitely give this some thought.Quote from: twospoons on May 19, 2025, 03:56:14 amInteresting thought, that never crossed my mind... But will the solution deliver enough power? The drone batteries have up to 17Ah, so this might take a while with the standard phone chargers. Also, if the drone doesn't exactly land in the middle of a pad, won't that influence the coil's inductivity, messing up the resonance in the transmission circuit?

author: Peabody
author_rank: Super Contributor
timestamp: May 19, 2025, 02:54:48 pm
content: Quote from: jb82 on May 19, 2025, 12:45:53 pmI was wrong about using a grid of squares. If you land diagonally, the terminals would fit into one square, which you can't have. I think it would have to be a grid of circles, with the dead spots between the circles being raised steeply so the drone couldn't land there, and it would instead slide down into two of the circles. The battery terminals would be slightly farther apart than the diameter of the circle, but only just barely, otherwise you could completely skip the adjacent circle. It might be necessary to have raised dead spots where the circles touch so a terminal could not get really close to the edge of the circle. Well, I may be wrong about this. It may not be possible to have the drone always land in two different adjacent or diagonal circles. But if it can work, it would certainly reduce the parts count.

author: Peabody
author_rank: Super Contributor
timestamp: May 19, 2025, 05:05:23 pm
content: No, I was wrong about being wrong about using squares.If you make the distance between the drone's battery terminals about 1.8 times the length of the side of a square, then the terminals can never fit into the same square. But now the terminals can stretch between three squares, skipping one in between. But it turns out that no number in the grid is repeated in less than three squares, so everything works.But you do need to prevent one or both terminals coming to rest on the border of a square. So there would need to be a very narrow, raised, non-conductive bead of material covering each border. Maybe teflon. Then have the drone yaw back and forth gently to make sure its terminals are on pads, not borders.

author: Buriedcode
author_rank: Super Contributor
timestamp: May 19, 2025, 05:28:02 pm
content: Also note, having a batteries terminals exposed /connected directly to external pins is asking for potential accidental shorts - relying on built in protection circuits is janky. There should be some kind of protocol to switch the battery terminals to the connector once it has landed/docked/connected and the connections are known. This could also help with working out the orientation - instead of having the battery connected to fixed pins on the connector, the drone can connect it to different "zones" (groups of pins), and the docking station can also connect the charger to different zones. Between them it should cover most cases of misalignment.This way you split the job between the drone and the docking station. Shouldn't be too complicated so the drone won't have any significant extra circuitry ( = weight). Ideally of course all the complicated stuff should be on the docking station since its stationary, isn't battery powered, and no real limit on size.

author: Peabody
author_rank: Super Contributor
timestamp: May 20, 2025, 03:52:13 am
content: Edit: This circuit would not work. In the Detection circuits, there's no return path to ground for the GPIO lines. Film at 11.Following up on the nine-line idea, below is a schematic of how one pole's circuit might look. There are two connections for charging, and two connections for detection, all controlled by 5V GPIO pins, which of course could be off-loaded to an analog switch or shift register.So first everything would be turned off. Then the detection process would involve enabling each possible pair of lines, one at a time, with one set as the high detector and the other as the low detector. If my math is right, there are 36 possible pairs. If nothing happens on GPIO5, then everything off again, then invert those two enabling bits. If still nothing on GPIO5, everything off, then go to the next pair. Eventually one pair will pull GPIO5 low, and that tells you which pair is connected to the drone's battery, and which poles are positive and negative. It is assumed that the charger and the control MCU have a common ground.In the circuit, R1 through R4 must be chosen so the base current alone, without GPIO3 being enabled, will not turn on the optocoupler. An optocoupler is used because it actually requires some current to flow to turn it on, but voltage levels are not so important.In a circuit like this it's difficult to account for all the possibilities of how things actually are versus what you're testing for. I think I've done that, but you guys get the big bucks while I'm just a hobbyist, so there may be errors. Anyway, I think this whole thing should certainly be doable. The grid and landing issues will probably be the hard part.

author: jb82
author_rank: Contributor
timestamp: May 20, 2025, 03:03:25 pm
content: Quote from: Peabody on May 19, 2025, 05:05:23 pmExactly. The distance between the drone's contacts is 30cm, so I should be good with 20x20cm squares. If I'm not completely wrong, it should even be possible to land between two squares, making contact with both. You should still not be able to reach another square of the same net.Quote from: Buriedcode on May 19, 2025, 05:28:02 pmThe charger has builtin short-, reverse-, and overcurrent protection and the drone is equipped with a BMS. I always felt that this is "as safe as I can possibly make it". Is there anything else I could do?Quote from: Buriedcode on May 19, 2025, 05:28:02 pmI'm not sure I understand. The drone would have multiple connectors (e.g. two more on the other landing gear leg) which can be switched to any battery pole or disabled entirely?That would mean a lot of additional complexity. What would be the added benefit over the solution with all logic on the landing pad side?Quote from: Peabody on May 20, 2025, 03:52:13 amThank's very much for the effort. I think this is the way to go. With 18 MOSFETs in total, it starts to get realistic again. For the detection circuit, I always thought of the following (the ISOM8711DFFR is an optocoupler):It has a minimal BOM count and the primary side relies purely on the battery. I might also move to a smaller microcontroller. Now that there are only few contacts left, I don't need that many GPIOs anymore.BTW., don't get the impression that I'm a professional engineer. I'm actually a computer scientist and although this is a project for work, I'm just a self educated hobby maker in the electronics field.

author: Peabody
author_rank: Super Contributor
timestamp: May 20, 2025, 05:56:48 pm
content: I've reworked my schematic. I changed Pole references to Line. And I revised the Detect High circuit. I had wanted to avoid dropping a lot of voltage across the transistor, but in this case it's only a couple milliamps for a very short time, so it doesn't really matter. And I added a ground reference for the GPIOs in the Detect circuit. Finally, I added some resistor values that actually work. I don't have a 4N25, but tested it with a 4N45 and a 12V battery, plus of course 5V GPIOs, and it worked fine.

author: Peabody
author_rank: Super Contributor
timestamp: May 20, 2025, 06:32:12 pm
content: Quote from: jb82 on May 20, 2025, 03:03:25 pmPlaying with a printed out grid, I found 1.8x to be easier to deal with. At 20cm, your contacts are only about 1mm beyond the diagonal distance of a square.QuoteI have the same question about your multiplexer that I had about my original circuit. Until you actually connect the charger to the battery, the battery is galvanically isolated from the processor and the multiplexer. I just don't know if the multiplexer will pass the current of an unrelated circuit, particularly if the battery voltage is far above the Vcc of the multiplexer. I'm probably not saying it right, but maybe one of the EE jocks will understand what I'm worried about, and opine on this. Anyway, I would suggest that you test your circuit before you finally decide what parts you will be using. Or you could just test a CMOS analog switch and a separate battery to make sure it works.

author: NiHaoMike
author_rank: Super Contributor
timestamp: May 21, 2025, 12:07:00 am
content: It would be much easier if you put a rectifier or at least a blocking diode on the drone.

author: Peabody
author_rank: Super Contributor
timestamp: May 21, 2025, 04:26:43 pm
content: The closest I have to your HC4067 is a CD4053. I connected a line from Vcc to a channel input pin, and then connected the same channel's output pin through a green LED and 2.2K resistor to ground. With the channel selected, the LED lit up, and the current was 1.38mA.Then I switched the channel's Vcc and ground connections to the plus and minus of an 18650. The LED was still lit up, but current was 0.88mA. I'm not sure how it works, but it does, at least well enough.But the problem is that for your 4067 the voltage on any I/O pin cannot exceed Vcc. So I don't think you can switch 24V with Vcc at 5V.Edit: That's re the high side. But I think you can use the 4067 on the low side if you add a diode to each channel blocking any high voltage.

author: jb82
author_rank: Contributor
timestamp: May 21, 2025, 05:19:41 pm
content: Quote from: Peabody on May 20, 2025, 06:32:12 pmNo, you're right. I completely overlooked that the multiplexer needs to be powered too. This missing ground problem is so absolutely mind numbing...Quote from: Peabody on May 21, 2025, 04:26:43 pmYou mean the multiplexer was powered by the battery but the input pin still ran on another power supply?I'd guess the potentials of the two grounds were close to each other then (the power supply's one being a little lower), allowing at least a small voltage to appear. Of course, this wouldn't be a safe foundation for a working solution.It might get even worse. We're using the NPB-450-24 by Mean Well as a charger. After powering on, it tries to start charging immediately. If this fails, it goes into an error state, which, afaik, can only be cleared by powercycling the charger (switching it off and on). So I don't even know if I have the proper charger ground all the time.I guess I'll simply try your approach and if the charger doesn't play along, I can either replace the MOSFET's with 18 relays or build a simple charger myself.

author: Peabody
author_rank: Super Contributor
timestamp: May 21, 2025, 06:11:53 pm
content: Quote from: jb82 on May 21, 2025, 05:19:41 pmNo. The multiplexer was always supplied by 5VDC. But the analog path was: B+ to analog input, to analog output, to LED, to resistor, to B-. So the entire analog path was completely separate from the power circuit of the multiplexer. I expected it not to work, and I still don't understand why it did, if only half-assed. But I agree, for a commercial product, it can't be half-assed. And of course the 24V issue would still be there.QuoteYeah, you want to identify the drone battery terminals and turn on the mosfets before starting the charger. I assume the charger, when off, will not sink current from the drone.One alternative for keeping the processor pin count down is to use daisy chained HC595 shift registers instead of the multiplexers. You could use five of them, driven by just three processor pins. You shift out all 5 bytes anytime anything changes, then latch everything to their output registers at the same time. That would provide all the "GPIO" pins in my circuit. But of course then you would need the NPNs and other parts in the detect circuits.

author: Peabody
author_rank: Super Contributor
timestamp: June 05, 2025, 09:43:52 pm
content: I'm curious what happened with this project. Any update?

author: Peabody
author_rank: Super Contributor
timestamp: June 06, 2025, 04:00:48 pm
content: Well, thinking further about the 9-line landing pad, if the drone's battery contacts are 30cm apart, and the squares are 17cm x 17cm, then you don't have to take any steps to prevent a drone contact from resting on the line between two squares, or even at a four-corners, and thus making contact with both, or all four, squares. So the detection algorithm would go through all 72 possibilities, find all the lines which work as positives and all that work as negatives, and then you would turn on the appropriate charging connection to all members of each set. There appears to be no way a drone's battery could be shorted out, no matter where it lands, and no way the charger's output could be shorted.So then the isolation gaps beteen the squares could be very narrow, and would require nothing on top of the gaps to prevent the drone from landing on a gap or corner.

author: NiHaoMike
author_rank: Super Contributor
timestamp: June 07, 2025, 03:51:01 am
content: https://github.com/MachineryEnchantress/JLCPCB-Drone-Charging-PadDesign is open source, I think simplifying the drone side to just a blocking diode would minimize the weight and having the charging pad alternate polarity until it detects a current flow would be quite easy.

author: Peabody
author_rank: Super Contributor
timestamp: June 07, 2025, 02:32:16 pm
content: Yes, if you can require correct drone orientation on the pad, and somehow provide for a do-over if you land on a line or corner, things become much simpler.The other thing is the location of the charger. If her drone has a microUSB port, then the charger is inside the drone. The landing pad contacts aren't connected directly to the drone batteries, but to the charger inputs. So landing the wrong way doesn't put the batteries at risk. The OP's project is a bit more industrial, with a 24V charger feeding into the landing pad.Still, it would be nice to find a way that requires fewer than 9 lines that still works no matter where or how you land.

author: NiHaoMike
author_rank: Super Contributor
timestamp: June 08, 2025, 02:01:04 pm
content: Quote from: Peabody on June 07, 2025, 02:32:16 pmWith a blocking diode on the drone, nothing will happen if the charger connects in reverse polarity. Then the switching circuit reverses polarity and detects the current flow, telling it to keep that polarity.

author: Peabody
author_rank: Super Contributor
timestamp: June 08, 2025, 02:19:50 pm
content: A blocking diode might mess up the charging. But I guess you could design your own charger that would provide for the extra voltage drop and still fully charge the batteries.

author: Terry Bites
author_rank: Super Contributor
timestamp: June 09, 2025, 04:10:07 pm
content: Relays are low maintenance and likely will outlive this project.Isolated gate drive seems to be a must here and a PV driver may be just the thing.Littelfuse make some cute one's, I think Panasonic and Vishay have similar parts.Add a pair of back to back mosfets and you've got yourself a low cost solid state relay.I was thinking that an array of ready polarised conical electrodes could made to be self aligning and give you plenty of contact area.You can even put a cheap proximity detector, a microswitch say, at the bottom of the hole so that only the appropriate sockets are energised.You'd have to work out a mechanical or electrical method of short circuit protection inside such a socket. Many ways to skin a cat here.As long as you dont pretend it's your original idea it could be a good solution. Food for thought.Viz