Sep 302018
 

I was originally thinking of one monolithic board which would have everything it needed.

There was provision for the lot, including a separate ATTiny24A so that you could omit all but one of the MOSFETs, swap the remaining MOSFET for a P-channel, drop the MOSFET drivers, one of the INA219s, and the ATTiny861, and you’d have just a monitoring board with a (low-speed) PWMable switch.  It’d plug into the same place and use the same host interface.  The one board could be made into just a boost, or just a buck.  Flexibility.

There was just one snag.  That’ll work for small power supplies with maybe up to 5A capability (~100W) but not for the 50A version.  The MOSFETs will fit, but the tracks will need to be huge, the board will be hideously expensive to make, and they don’t make inductors big enough.

Looking around for inductors, I did see these.  They’re not massive like the 10uH one I saw, and they’re not expensive.  The downside is they’re about 10% of what I really need.  I guess I’ll just make do.  They’re also not PCB-mount (mind you, a 40kg inductor doesn’t PCB-mount either).

Thus, it may be more sensible to separate the MOSFETs and high-power stuff from the controller.  Now here’s the rub.  We’re dealing with sub-15ns pulses.  PWM.

Years ago for my industrial experience, I did work on an electric harvester platform.  The system ran 48V.  The motors were rated at 20kW, and were made in house using windings wound from 5mm diameter enamelled copper wire and neodymium magnets.

We had loads of issues with MOSFETs blowing.  The MOSFET driver was mounted close to the MOSFETs, as I’m proposing to do here, but between DSP and driver, was a long-ish run of ribbon cable. @Bil Herd posted this article covering the challenges involving inductance on PCB layout.  That same problem applies to “long” cable runs too.

10 years ago when we were working on this project, I remember asking about if we had considered maybe using coax cable instead of a ribbon cable.  The idea was rubbished at the time.  Given we were PWMing 400A, I think there might’ve been something in that suggestion.

That ribbon (10~20cm of it) would have had a lovely inductance all of its own, and while I have no idea what frequency the PWM was running at (I might have the code somewhere but I can’t be stuffed digging it up), and we were fundamentally driving a single-ended signal over a fairly long distance.  Yes, ground was close, but probably not enough, a twisted pair would have been better, but even then not perfect.  We blew many MOSFETs on that project.  Big TO-263s!

An earlier article on differential signalling got me thinking: why not use LVDS for the PWM?  A quick search has revealed this receiver and transmitter (Mouser says two receivers on it, but I think that’s a typo).  The idea being that I send the PWM down a differential pair using LVDS.  155Mbps should be plenty fast enough (the ATTiny861 can only do 64MHz) and these parts will run at the 5V needed for fast switching.  In fact they require it.

Using twisted pairs, the inductance should cancel.  I’ll make a MOSFET board that just has these signal pairs:

  • +12V (for the MOSFET driver) and 0V
  • +5V (for the LVDS receiver) and 0V
  • High side PWM + and –
  • Low side PWM + and –

There’s a ground-loop I need to be wary of between the 12V and 5V rails, really it’s the same 0V rail for both.  I suspect they’ll still need to be connected at both ends.  Add in more of those screw terminals to take the input and output power off-board, and I think we should be set.

Similarly, the INA219 should probably be a separate board, with scope for having a chassis-mounted current shunt.  The connection to the current shunt’s sense output is a low-power connection, so no issue there.  You want to keep it short for accuracy reasons, but a simple twisted pair will work fine.

Sep 292018
 

So, I’ve been pondering doing a more capable power controller for the purpose of enhancing or even outright replacing the solar controllers I have now on the Solar-powered cloud computing cluster.

The idea started as a straight DC power meter with a Modbus interface, as there’s pretty much nothing on the market.  Lots of proprietary jobbies, or display-only toys, but nothing that will talk an open protocol.  I started designing a circuit.  I thought: it’d be handy to have digital inputs and outputs.

Lots of mains energy meters have them, and they’re handy for switching loads.  My remote reset facility when porting the mainline kernel to the TS-7670 was a digital output on the CET PMC-519.  If I crashed the TS-7670, I basically fired up ipython, loaded pymodbus, connected to a Modbus/TCP gateway, then issued a few write-coil commands to power-cycle the TS-7670.

Often the digital inputs are hooked to water or gas pulse meters to meter usage: you get a pulse every N litres of water or every N cubic metres of gas.

A meter with digital I/O that’s programmable would be just perfect for the job my little power controller is doing.

I could make the channels PWMable, thus be able to step down the voltage.  Put an INA219 on there, and I’d have current measurement and power control.  The idea evolved to putting the INA219 and a MOSFET on a board, so it was a separate module: just to make board layout easier and to reduce the size of the boards.

For a buck converter, you just add an inductor and a few smoothing capacitors.  Better yet, two INA219s and a MCU would let me measure power in, out, and have localised brains.  Thus the idea of a separate, smart module, was born.  For kicks, I’m also adding the ability to boost as well by tacking a boost converter to the end.

The principle is really quite simple.  A buck converter has this topology (source, Wikipedia):

If you swap out that diode for another MOSFET, you get a synchronous buck converter, which looks like this (same Wikipedia article):

It’s worth noting that a MOSFET switch has a body diode that might be exploitable, I’ll have to check.  You drive the two switches with complimentary outputs.  Both these circuits will step down a voltage, which is what I want to do 99% of the time, but it’s also useful to go up .  A boost converter looks like this (source: Wikipedia):

Again, that diode can be replaced with another MOSFET.  This will step up a voltage, but not down.

There are a few options that allow going both ways:

  • Flyback : which uses a transformer and provides galvanic isolation.  The downside is the secondary must take all the output current, and finding a transformer that can do 50A is EXPENSIVE!  So scratch that.  (And no I am not winding my own transformers… tried that back at uni when a lecturer asked us to build a flyback converter.  Bugger that!)
  • SEPIC is basically a boost plus a buck-boost.  Efficiency is not their strong suite apparently, although there are ways to improve it.  I’m not sure the added complexity of two boost converters sandwiching a buck converter is worth it.
  • Ćuk is no good here because it inverts its output, unless you want an isolated one, which is going to be $$$$ because of the transformer needed.  Yes, I’m chickening out!
  • Split-Pi looks real interesting, in that it’s bi-directional.  In the event I ever decide to buy a front-wheel motor for my bicycle, I could use one of these to do regenerative braking and save some wear on my brake pads.  I haven’t seen many schematics for this though, just generalised ones like the one above.
  • Zeta also looks interesting, but it’s pretty unknown, and has a higher parts requirement.  It could be worth looking at.  It’s a close relative of the SEPIC and Ćuk.

The route I’m looking to try first is the 4-switch buck-boost, which looks like this:

The goal will be to have a simple microcontroller-based switch-mode power supply module with the following characteristics:

  • Up to 50A current switching capability
  • 9-30V input voltage range
  • 12-15V output voltage range
  • 250kHz switching frequency

99% of the time, conditions will be:

  • input voltage: 18~20V
  • output voltage: 13.8~14.6V

So I’m thinking we design for a buck converter, then the boost just comes along for the ride.  There’s a handy primer here for designing a buck converter.  For a 20V input and 14.6V output, their formulas suggest a 33µH inductor should cut the mustard. One of these which can handle >50A is not a big or expensive component.

In the above system, we need to be able to drive up two pairs of complementary outputs at high speed.  We can forget the hacker darling ATTiny85, as with 5 pins, it barely has enough to do the SPI interface, let alone talk I²C and drive four MOSFETs.

A good candidate though is the chip I used for the #Toy Synthesizer — the ATTiny861 .

This chip has the same high-speed PWM, and I already know how to drive it.  It doesn’t have a lot of brains, but I think it’ll do.  The challenge will be in-circuit programming.  There are just 3 PWM outputs that don’t clash with ICSP.

Don’t be fooled by the presence of two DI/DO/USCK pins, it’s the one UCI interface, just you can switch which pins it uses.  That’ll be handy for talking I²C, so I’ve earmarked those pins in purple.  The nRESET pin is marked in green, the PWM pins in blue.  When nRESET is pulled low, PB[012] switch to the functions marked in red.

This doesn’t matter for the toy synthesizer as I only need two PWM channels, and so I chose OC1B and OC1D.  Here, I need nOCID (no problem) and nOC1B (uhh oh).

During run-time, I could put my SPI interface on PA[012] and bit-bang the I²C, but I don’t want MOSFETs chattering when flashing new firmware.  Thus, when in reset, I need to inhibit nOC1B somehow.

The other way of doing this is to just forget about nOC1B altogether.  Consider this:

  • When stepping up: SW1 will be held on , SW2 will be held off , and the PWM will drive SW3/SW4.
  • When stepping down: SW3 will be held off , SW4 will be held on , and the PWM will drive SW1/SW2.

We’re only PWMing two MOSFETs at a time, so could get away with just one complementary pair, OC1D/nOC1D.  We ignore OC1B and can now use it for something else.  We just need a means of “selecting” which pair of MOSFETs we’re driving.  A PWM output with 8-bits resolution and 250kHz cycle frequency has a minimum pulse width of about 15ns (1/64MHz).

A SN74AHC244 tri-state buffer will do nicely.  We can use two GPIOs to control the two enable pins to switch the OC1D/nOC1D and a pair of other pins for manual control.  Perhaps PA[01] to select where the PWM signals get routed, and PA[23] to control the non-PWMed MOSFETs.

Due to switching speed requirements, we will need to run the ATTiny861 at 5V.  So maybe make some room for some level shifting of the SPI interface to support 3V master interfaces as this is much lower speed than the PWM output.

This leaves PB3, PB6, PA1 and PA3 free for GPIOs to use however we wish.  Two of these should probably be made part of the host interface, one for chip select (PB3 seems a good choice) and one for an interrupt (maybe PB6).  Add the 5V/0V power rails, and nRESET, and the same interface can be used for ICSP too.

The idea looks doable.  The challenge will be making the control algorithm work within the constraints of the ATTiny861, but given what people have done with the ’85 which has the same core, I’m sure it can be done.

Sep 272018
 

So, the last few days it’s been overcast.  Monday I had a firmware glitch that caused the mains supply to be brought in almost constantly, so I’d disregard that result.

Basically, the moment the battery dropped below ~12.8V for even a brief second, the mains got brought in.  We were just teetering on the edge of 12.8V all day.  I realised that I really did need a delay on firing off the timer, so I’ve re-worked the logic:

  • If battery drops below V_L, start a 1-hour timer
  • If battery rises above V_L, reset the 1-hour timer
  • If the battery drops below V_CL or the timer expires, turn on the mains charger

That got me better results.  It means V_CL can be quite low, without endangering the battery supply, and V_L can be at 12.8V where it basically ensures that the battery is at a good level for everything to operate.

I managed to get through most of Tuesday until about 4PM, there was a bit of a hump which I think was the solar controller trying to extract some power from the panels.  I really need a good sunny day like the previous week to test properly.

This is leading me to consider my monitoring device.  At the moment, it just monitors voltage (crudely) and controls the logic-level enable input on the mains charger.  Nothing more.  It has done that well.

A thought is that maybe I should re-build this as a Modbus-enabled energy meter with control.  This idea has evolved a bit, enough to be its own project actually.  The thought I have now is a more modular design.

If I take the INA219B and a surface-mount current shunt, I have a means to accurately measure input voltage and current.  Two of these, and I can measure the board’s output too.  Stick a small microcontroller in between, some MOSFETs and other parts, and I can have a switchmode power supply module which can report on its input and output power and vary the PWM of the power supply to achieve any desired input or output voltage or current.

The MCU could be the ATTiny24As I’m using, or a ATTiny861.  The latter is attractive as it can do high-speed PWM, but I’m not sure that’s necessary in this application, and I have loads of SOIC ATTiny24As.  (Then again, I also have loads of PDIP ATTiny861s.)

The board would expose the ICSP pins plus two more for interrupt and chip select, allowing for a simple jig for reprogramming.  I haven’t decided on a topology yet, but the split-pi is looking attractive.  I might start with a buck converter first though.

This would talk to a “master” microcontroller which would provide the UI and Modbus interface.  If the brains of the PSU MCU aren’t sufficient, this could do the more grunty calculations too.

This would allow me to swap out the PSU boards to try out different designs.

Sep 222018
 

So, I’ve gotten back to this project having spent a lot of my time on work, the Yarraman to Wulkuraka bike ride and the charging controller #Solar-powered cloud computing — just to name 3 things vying for my attention.

In the test board, I had wired up some LEDs for debugging, dead-bugged 0805s, which were hooked between the output of the octal latch and 0V.  I omitted the series resistor, as I presumed that, given the output was PWMed with a maximum duty cycle of ⅛, the LEDs shouldn’t burn out.

Turns out I had forgotten a property that all diodes exhibit, that is the desire to clamp the voltage across them.  Today I was testing the board, and wondering why some channels were dim, others didn’t work at all, but one worked so much better.  Did I accidentally put the wrong current limiting resistor in series with the drain?  No, all checked out as about 12 ohms.

I put a program on the MCU that just turned a channel on when the button was pressed.  No music, no fancy PWM stuff, just turn on a LED when the corresponding button was pressed.  Measuring the gate voltage showed about 2V.

Even with the PWM output forced low, the output was still 2V.  Moreover, I was using my new bench supply, and with nothing running, the circuit was drawing ~300mA!  Why?

Turns out, the LEDs I had dead-bugged in, were trying, and succeeding, in clamping the output voltage.  2V was just barely enough to trigger the output MOSFETs, but clearly this was borderline as some worked better than others.  I was likely in the linear region.

Snip out the common connection for the LEDs to 0V, and the problems disappeared.  I’ve dead-bugged a 1kOhm resistor in series with the lot, and that’s got my debug LEDs back and working again.  The MOSFET outputs now work properly.

The bigger chunkier MOSFETs I bought by mistake could have worked just fine: maybe I was just driving them wrong!

Two prospects have crossed my mind:

  • Getting the MOSFET board made professionally
  • Getting a board that combines all components onto one PCB made professionally

The version that is shown was really designed for the home PCB maker to be able to produce.  The traces are wide and the board is fundamentally single-sided: when etching, you just etch one side of the board and leave the other side unetched.  When drilling the holes, you just countersink the holes a bit on all pins not connected to 0V.

A smaller board with everything in one would be worth making now that I’ve proven the concept.  Not sure there’s a good reason to go to SMT at this stage: I still want to make assembly simple.  The thinking is the all-in-one would have some headers so you can conceivably break things out for other projects and just omit parts as required.

This could theoretically be entered into the #The 2018 Hackaday Prize as part of the musical instrument contest, as that’s what it is: it’s a musical instrument for the severely physically handicapped.  There is a video of a slightly earlier prototype in this post .

Code wise, I’ve done little.  The basic functionality is there, it makes noises, it flashes LEDs, that’s about what it needs to do for now.  I did have to increase the start-up delay so that the buttons were detected properly, as without this, if I used my bench-top supply, it would fail to see any inputs.  People aren’t going to notice 100ms boot-up delay vs 1ms, but it makes a difference if the power supply is a little slow.

Sep 012018
 

Well, I’ve been tossing up how to control the mains charger for a while now.

When I first started the project, my thinking was to use an old Xantrex charger we had kicking around, and just electrically disconnect it from the batteries when we wanted to use the solar power.  I designed a 4-layer PCB which sported a ATTiny24A microcontroller, MOSFETs (which I messed up) and some LEDs.

This was going to be a combined fan controller and power management unit.  It had the ability (theoretically) to choose a supply based on the input voltage, and to switch if needed between supplies.

It didn’t work out, the charger got really confused by the behaviour of the controller.  I was looking to re-instate it using the Redarc solar controller, but I never got there.  In the end, it was found that the Redarc controller had problems switching sources and would do nothing whilst the batteries went flat.

We’ve now replaced both ends of the system.  The solar controller is a Powertech MP3735 and integrates over-discharge protection.  The mains charger is now a MeanWell HEP-600C-12 (which has not missed a beat since the day it was put in).

Unlike my earlier set-up, this actually has a 5V logic signal to disable it, and my earlier controller could theoretically generate that directly.

Looking at the PCB of my earlier power controller attempt, it looks like this could still work.

Above is the PCB artwork.  I’ve coloured in the sections and faded out the parts I can omit.

In green up the top-left we have the mains control/monitoring circuitry.  We no longer see the mains voltage, so no point in monitoring it, so we can drop the resistor divider that fed the ADC.  This also means we no longer need the input socket P2.

Q2 and Q7 were the footprints of the two P-channel MOSFETs.  We don’t need the MOSFETs themselves, but the signals we need can be found on pin 1 of Q2.  This is actually the open-drain output of Q1, which we may be able to hook directly to the REMOTE+ pin on the charger.  A pull-up between there and the charger’s 5V rail, and we should be in business.

In yellow, bottom left is the solar monitoring interface.  This is still useful, but we won’t be connecting solar to the battery ourselves, so we just keep the monitoring parts.  The LED can stay as an indicator to show when solar is “good enough”.

In purple, occupying most of the board, is the controller itself.  It stays for obvious reasons.

In red, is the fan control circuitry.  No reason why this can’t stay.

In blue is the circuitry for monitoring the battery voltage.  Again, this stays.

The main advantage of doing this is I already have the boards, and a number of microcontrollers already present.  There’s a board with all except the big MOSFETs populated: with the MOSFETs replaced by 3-pin KK sockets.

How would the logic work?  Much the same as the analogue version I was pondering.

  • If battery voltage is low, OR, the sun has set, enable the mains charger.

What concerned me about an analogue solution was what would happen once the charger got to the constant-voltage stage.  We want to give it a bit of time to keep the battery topped up.  Thus it makes sense to shut down the charger after a fixed delay.

This is easy to do in a microcontroller.  Not hard with analogue electronics either, it’s fundamentally just a one-shot, but doing it with an MCU is a single-chip solution.  I can make the delay as long as I like.  So likely once the battery is “up to voltage”, I can let it float there for an hour, or until sunrise if it’s at night.

May 072018
 

So, I was rummaging around on the table (which looks like a bomb hit it… yes I have hoarding tendencies) and I managed to find the packet of MOSFETs I originally used to make the earlier prototype I/O board.

These are Toshiba 2SK4017 s, probably not the best pick but at 70c a pop, they were cheap.  They worked for the original version, and at 5A drain current, are more than sufficient for the task.

Above is the re-built board.  I literally cut away the old MOSFETs (hey, should still be able to dead-bug them, but sod it, I’ve got 42 of them left), cleaned up the board a little, inserted these smaller MOSFETs, and soldered them in.  I had to replace two 0805 1k resistors which got damaged due to the end of the resistor overlapping the hole for the gate… but whatever, I’ve got nearly 5000 of those kicking around too.

In short, it works.  I didn’t try it with full power, but rather used a series resistor with 9V, but I could light up a button and detect a press on every single channel.

I’ll have to order some more MOSFETs.  Not sure whether to go with these same ones again, I think they’re obsolete … but now I have a couple of datasheets to compare against since I now know what does work, and what doesn’t .

Apr 282018
 

So, I’m learning now to read datasheets a little more carefully.

Finally got around to testing that board, and at first, I had some shorted connections to deal with and one dry joint.  No problem, a bit of scoring with the knife and a tap with the soldering iron, and we’re in business.

Apply 9V to the GPIO pin, and ~3V appears at the output.  Good enough, the AVR will recognise that.

Now for the MOSFET, applying 5V to the input, switches the MOSFET.  Great.  Try it on the actual synth… sure enough I can make noise, but nothing lights up.  What gives?

In this prototype I’m using Fairchild FQI4N80s, which I bought a tube of 50 of them.  Turns out these MOSFETs have 40ns turn-on delay, and a 100ns rise time.

Doesn’t seem like much, but then consider this: our PWM clock is 64MHz.  That means the pulse time can be as low as 15ns.

They also can have a gate threshold as high as 5V… so borderline for this application.  Never mind, I’m sure they’ll be useful in other projects.

I have a couple of options in mind, both by Infineon: the IPS70R900P7SAKMA1 and the IRLU120NPBF .  Out of those two, the latter sounds like the better bet, I seriously don’t need 700V Vds!

It is tempting though to design a board based on the prototype though, as I think if I make room for a TO-220 or TO-251 (IPAK; not to be confused with the larger I²PAK), there are actually a lot of choices out there, and much of the time, the choice is not critical.

If I do that, I’ll be spacing out the KK connectors a bit, as that’s another point: the plugs are just a wee bit wider than the sockets, so I need to make room for that.

Jan 212018
 

So last week, some more parts arrived for this project.  Crucially, some capacitors, and some MOSFETs.

Turns out, the MOSFETs I got last time were not I²PAK … I thought that’s what I ordered last time, but clearly not, because that’s what these are, and they’re bigger than the previous ones.

No matter, lean them back like dominoes and they still fit.  I’ve got a tube of 50 of them.

I was able to put the pull-down resistor in, and I basically fitted the MOSFETs along a track, scoring the track between the legs so they didn’t short out.  For the 12ohm resistor to the drain, I’m doing half-veroboard-PCB, half-point-to-point construction to link the drain pin (annoyingly in the centre) to the outside world.

I’ll need to rustle up a 2-pin KK to act as the power input, and that board is done.  I might add two in parallel on here so a short lead can link from here to the mainboard to supply +12V.  This will go on the right-hand side (lower photo) just past where that jumper connects.

After that, the next step is wiring up the buttons and switches.  The use of 4-pin connectors should greatly simplify the wiring since everything we need is on the one connector.

Dec 252017
 

So some spare time today… I decide to construct a new I/O module to fix up the mistakes made with the previous iteration.  Mainly:

  • the TVS diodes… going for one with a higher clamp voltage so it doesn’t smoke when 12V is applied
  • switching to a 4-pin connector on the output side, with pins for 0V, GPIO, DRAIN and +12V
  • fixing the pin-out on the input side so it matches the PCB.
  • rather than having jumper leads to make the boards separable, we’ll make one monolithic board that plugs into all 8 channels simultaneously with one long connector.

For the TVS diodes, I ordered some TPD2E007 in SOT23… thinking those would be a reasonable size for hand-soldering.

00

Now… how the bloody hell am I going to solder these little tiddlers?  I had thought SOT-23 was about twice that size.  Never mind, can’t un-buy them.

The circuit is pretty much identical to what came before.  My MOSFETs and 4.7nF capacitors seem to have gone walkies, not sure where.  No doubt the arrival of replacements will summon them back.  I decided to use SMT for many parts on this build.

0805 resistors and veroboard aren’t a bad combo really, just have a sharp blade handy to cut the track where needed, and the resistor can straddle the gap made.

For the TVS diodes, the common pin is to ground, so I made a bus bar running vertically down the PCB and scoring the tracks either side.  The common pins could be soldered to that, and the two I/O pins would straddle the division between each track.  Aside from me getting some parts off-by-one at first, this went well.

The zener and schottky diodes of course, being through-hole, went on the other side of the PCB.

I still have to locate where my MOSFETs have gone, and I think I found some 12 ohm resistors (through-hole).  I can use some 0805 1k resistors for the MOSFET gates.  So that’s some MOSFETs and 4.7nF, probably 0805 size capacitors that need ordering in the new year.

Sep 172017
 

So we’ve got a free weekend where there’ll be two of us to do a solar installation… thus the parts have now been ordered for that installation.

First priority will be to get the panels onto the roof and bring the feed back to where the cluster lives.  The power will come from 3 12V 120W solar panels that will be mounted on the roof over the back deck.  Theoretically these can push about 7A of current with a voltage of 17.6V.

We’ve got similar panels to these on the roof of a caravan, those ones give us about 6A of current when there’s bright sunlight.  The cluster when going flat-chat needs about 10A to run, so with three panels in broad daylight, we should be able to run the cluster and provide about 8A to top batteries up with.

We’ll be running individual feeds of 8-gauge DC cable from each panel down to a fused junction box under the roof on the back deck.  From there, it’ll be 6-gauge DC cable down to the cluster’s charge controller.

Now, we have a relay that switches between mains-sourced DC and the solar, and right now it’s hard-wired to be on when the mains supply is switched on.

I’m thinking that the simplest solution for now will be to use a comparator with some hysteresis.  That is, an analogue circuit.  When the solar voltage is greater than the switchmode DC power supply, we use solar.  We’ll need the hysteresis to ensure the relay doesn’t chatter when the solar voltage gets near the threshold.

The other factor here is that the solar voltage may get as high as 22V or so, thus resistor dividers will be needed both sides to ensure the inputs to the comparator are within safe limits.

The current consumption of this will be minimal, so a LM7809 will probably do the trick for DC power regulation to power the LM311.  If I divide all inputs by 3, 22V becomes ~7.3V, giving us plenty of head room.

I can then use the built-in NPN to drive a P-channel MOSFET that controls the relay.  The relay would connect between MOSFET drain and 0V, with the MOSFET source connecting to the switchmode PSU (this is where the relay connects now).

The solar controller also connects its control line to the MOSFET drain.  To it, the MOSFET represents the ignition switch on a vehicle, starting the engine would connect 12V to the relay and the solar controller control input, connecting the controller’s DC input to the vehicle battery and telling the controller to boost this voltage up for battery charging purposes.

By hooking it up in this manner, and tuning the hysteresis on the comparator, we should be able to handle automatic switch-over between mains power and solar with the minimum of components.