Shop OBEX P1 Docs P2 Docs Learn Events
P2-Based Solar MPPT Charger — Parallax Forums

P2-Based Solar MPPT Charger

On a whim I decided to see how much smoke I could make creating a P2-based MPPT solar charger. Nothing huge or fancy, just an amp or two at <30 volts input with 12 volts output using "perturb and observe" tracking.

Has anyone walked this path before and has code to share? If not, I'll roll my own and eventually post it, but I figured I'd ask before I started melting expensive parts. :)

Comments

  • I used this on the P1. I was actually surprised how easy it was to add MPPT. There is another control loop that adjusts the duty cycle to regulate input or output voltage, whichever is on the wrong side of the setpoint. The board has an expensive hall effect current sensor. I'm migrating this to the P2, hope it will be done soon.

    You may want a diode on the output for testing, to prevent the battery from feeding current into the circuit. In fact, I think an output diode is required unless the code has some checks to make sure the converter doesn't run in reverse and boost battery voltage to something very high. Otherwise, a solar charger is not likely to melt because the solar panel is current limited. A current limited lab supply works as well, but transition from constant voltage to constant current is sharper than a PV panel and this causes some trouble with the MPPT algorithm.

    The MPPT algorithm runs every ~half second.
    ' Ipv, Vpv : input  mA, mV
    ' user_vpv : output  1/17 Volt per lsb, needs to keep value between runs
    
             Ppv := Ipv*Vpv/1000  ' mW 
             if plc.Get_Do_Mppt
                ' Incremental Conductance, microchip AN1521
                if (||(Vpv-lastVpv))<1     '  no delta V
                    if (||(Ipv-lastIpv))>1 ' yes delta I
                        if Ipv>lastIpv      ' pos delta I
                            user_vpv+=2
                        else
                            user_vpv-=2
                   
                else           
                    if (||(Ppv-lastPpv))>1     ' yes delta P
                        if  Ppv>lastPpv          ' pos delta P         
                            if Vpv>lastVpv       ' pos delta V, 
                                user_vpv+=2      ' pos/pos
                            else
                                user_vpv-=2      ' pos/neg     
                        else
                            if Vpv>lastVpv       ' pos delta V, 
                                user_vpv-=2      ' neg/pos
                            else
                                user_vpv+=2      ' neg/neg
                                                
                                                
                if Ipv<10                         ' no current, we are above Voc
                    user_vpv-=1   
                    
                if user_vpv < 9*17
                    user_vpv := 9*17
                
                if user_vpv > 36*17
                    user_vpv := 36*17
                plc.Set_Vmppt(user_vpv)
                    
                
             lastIpv:=Ipv
             lastVpv:=Vpv
             lastPpv:=Ppv
    
  • Wow. That is *definitely* useful! Thank you @SaucySoliton! I need to retreat to the Man Cave, pour myself an adult beverage, and digest all of that. Good stuff indeed. Looks like input is constrained to <36 volts, which fits my case very nicely.

    For anyone who comes along later, Saucy's code references Microchip AN1521. That document is a goldmine for anyone who wants to play with MPPT. It's located here: http://ww1.microchip.com/downloads/en/Appnotes/00001521A.pdf

    Thanks, SaucySoliton!
  • Cluso99Cluso99 Posts: 18,069
    Many interesting projects, so little time :(
  • But it just so happens that I'm about to start an MPTT project for a customer so that appnote came in handy.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2020-12-02 06:05
    I've used the LT3652 2 amp solar battery charger chip, which Linear Tech dubs MPPC, rather than MPPT. ("control" rather than "tracking"). It implements a simpler algorithm that holds the panel voltage near the preprogrammed maximum power point, which for most 12V nominal panels is near 16 or 17 volts. It's not a bad assumption. A control loop inside the chip chokes back the output current if the panel voltage falls due to output loading. I added a simple control via i2c from the P1 to switch the control voltage between 15 and 17 volts. The lower voltage allows it to catch the first sun in the morning, or to get as much as it can on a dark day. A second control loop in the LT3652 regulates the battery charging, basically delivering whatever current is available, up to a maximum, but then when the battery is fully charged, it cuts off charging lets the solar panel float, until the battery again falls below the turnaround point to resume charging. The point is, regulation of the solar panel and the battery are tightly interwoven.
  • You can and should adjust the parameters to meet your needs. The hall effect current sensors have offset and noise that could affect the algorithm. So it can treat small differences as 0. The slow update rate compared to the application note was to allow more filtering of the signals and allow the algorithm to run in P1 spin. A nice side effect was the ability to monitor MPPT tracking operations over the serial port. It just happened that my ADC produced 17 steps per volt. So I used that same range for the controls. I already had code to convert the ADC measurements to mV/mA for monitoring purposes so I just used the output from there. Although the code should be fairly insensitive to the scaling of the input measurements.


    The lab supply doesn't really have a smooth dP/dV derivative, but I've found the code to work ok with it after some tweaking. I added that feature: if the current is too low, reduce operating voltage. No harm there if the source is current limited. The operating voltage can't go lower than battery voltage. It would work like a non-MPPT controller in that case. It should still deliver 80% of max power or so. But having the operating voltage stuck too high is much worse because then there will be no power output. This is also the reason for the voltage constraints. Since I know the my array, I've set the constraints tight to ensure that it will generate some power even if the algorithm malfunctions.
  • Today I hooked my P2Eval board up to a homebrew MOSFET buck converter that was being fed from a 15 volt 2 amp solar panel. Just tinkering around with this I learned a bunch. To keep the voltages/currents small I ran the output into a little VRLA battery that I stole from a binned UPS. No smoke (yet!) and my inductor isn't even close to optimal, but it works. It's amazing how little it takes on the P2 side of things to make this work. It took about 30 lines of FlexBASIC code to get it running as a simple CV charger. Tomorrow I'm hoping for sunshine and will start making it more like an MPPT.

    MOSFET question: In the data sheets, NMOS enhancement mode FETs are almost always used (at least in saturation mode) with a grounded source. (Ie, the load goes between Vcc and the drain pin). Is there a reason the drain cant go directly to Vcc and the load put between the source and ground, as long as:
    1). The gate voltage doesn't exceed Vgs, and
    2). The gate voltage is at or near Vcc

    This would imply a pretty low system Vcc (ie, under 20 volts, which is the Vds max for this particular device), but it seems like it should work. Am I milking without a bucket here?

  • jmgjmg Posts: 15,173
    JRoark wrote: »
    MOSFET question: In the data sheets, NMOS enhancement mode FETs are almost always used (at least in saturation mode) with a grounded source. (Ie, the load goes between Vcc and the drain pin). Is there a reason the drain cant go directly to Vcc and the load put between the source and ground, as long as:
    1). The gate voltage doesn't exceed Vgs, and
    2). The gate voltage is at or near Vcc
    The reason grounded source is used, is that gives lowest saturation, in the simplest circuit.

    You can use Drain to Vcc, but then VGS needs to go above Vcc to saturate the FET, and to 0V to turn off the FET.

    Designs can do that, look for Bootstrap caps in SMPS designs that use 2 N-FETS for examples.

    Note that Bootstrap cap designs cannot run 100% duty cycles, to achieve that you need to have a charge pump on the upper FET gate driver.

  • @jmg Thanks for that. A light bulb went on in my head after you explained it.

    Off to figure out how those bootstrap caps work now...
  • evanhevanh Posts: 15,916
    edited 2020-12-04 06:56
    200+ Volt motor drives also solely use final stage N-channel (IGBT usually) and make particular use of multiple floating supplies - one for each high-side power transistor. Needless to say, each high-side driver circuit also has isolated signalling.

    Huh, I just noticed that IGBTs functionally swap Collector with Emitter labelling. I hadn't noticed that before ... which explains why I had trouble reconciling the non-saturating feature they boast. At first glance they resemble a darlington structure but it's really more like an emitter follower structure. EDIT: Err, that's a bad comparison too. It's just a tad weird how it's the BJT emitter that's being treated as a collector - and even named as such in the IGBT. I wouldn't be surprised if it's something that came from op-amp designs.

  • evanh wrote: »
    Huh, I just noticed that IGBTs functionally swap Collector with Emitter labelling. I hadn't noticed that before ... which explains why I had trouble reconciling the non-saturating feature they boast.
    Note that the equivalent circuit for an N-channel IGBT shows a PNP transistor.
  • evanhevanh Posts: 15,916
    Yeah, that's part of the label swapping I just noticed. I've never used an IGBT so had only ever skimmed over them prior. Certainly intriguing that the final power junction is PNP. That wasn't an expected factor when I went looking.

  • JRoarkJRoark Posts: 1,215
    edited 2020-12-07 01:54
    I've been playing a bit, mostly to keep my sanity, because our household is currently in a 2-week lockdown. Oops.

    So after closing up shop (but leaving everything on the test bench running), I found absolutely everything from 160 to 20 meters was utter covfefe on my Elecraft K3S. Nothing but a roar and birdies everywhere, and we're nowhere close to anything like a sunspot period. So I went hunting...

    It turns out I did indeed make a passable (sorta-sorta) 12 volt MPPT battery charger today. But in the process I made one a HECK of a broadband noise generator!

    Jeeze Louise...

    Edit: In hindsight, it is not really an MPPT yet, but I did get the buck converter working and the P2 is driving it, so maybe tomorrow.
    w.bmp 1.1M
Sign In or Register to comment.