C2000 Solar MPPT Tutorial C code Perturb and Observe algorithm

C2000 Solar MPPT tutorial Pt/1





C2000 Solar MPPT Tutorial final prototype PCB



  • Final set-up, testing and tuning

Maximum Power Point Tracking


C2000 Solar MPPT Tutorial solar panel power curve




System Overview

The image below shows an overview of the final system

C2000 Solar MPPT Tutorial Prototype System Diagram




Interleaved Synchronous Buck Converter



C2000 Solar MPPT Tutorial buck converter circuit





10W Solar Panel


C2000 Solar MPPT Tutorial 10W panel front

C2000 Solar MPPT Tutorial 10W panel back

System Schematic

C2000 Solar MPPT Tutorial hardware schematic



31 thoughts on “C2000 Solar MPPT tutorial Pt/1”

  1. Wonderful article, Very well written. I actually stumbled upon it while looking for something else and after reading it I have a couple questions.

    Do you have a source of information about interleaved synchronous buck converters thats NOT for engineers? My google foo is pretty much just returning things that look like quantum mechanics. I am currently drawn to the idea that multiple buck converters can increase current capacity. I have a client and i was building them the most awesome BMS/ Automatic Transfer Switch, and then i seen this and i may update it to include a PV controller, they have no idea how big of a system they will end up with so they are drawn to the idea that i can upgrade it for them without really changing much but the handling capacity.

    From my stand point however i would rather do a one and done method. So, do you suppose it would be possible to Interleave enough phases to harness 100A @ 100V input? i have also been reading (here and other places) that higher frequencies will reduce the component size into the realm of real world parts VS theoretical ones.

    And lastly, all the components for the buck converter should be rated to the maximum input voltage + 10% if im not mistaken?

    1. Hi Travis,

      There is quite a bit of information on multiphase or interleaved SMPS circuits, but appreciate some of this information is not easy to digest. Look up “Benefits of multiphase buck converter” by David Baba, which is an extracted PDF from a Power Management guide.

      The power and voltage ratings you are looking at should not be an issue, but correct component selection is always critical. You maybe better using a higher frequency in this case due to component sizes as you correctly pointed out, you can vary the frequency and then do some cost benefit calculations based on component sizes and prices verses any trade-offs with efficiency. As far as overrating I would probably leave a greater margin than +10%, this also depends on the input and output circuitry protection and any potential transients that maybe generated when switching the load in and out, as well as current surges from the battery if no soft start or precharge is employed.


  2. Hello, I replicated this for my university project with some adjustments. I’ve been studying it and very clear and concise. I can’t thank you enough. This has been a huge help for me to understand MPPT and converters.

  3. I was considering a similar design by cascading more buck converters for more current and to reduce the load on the FETS. What are your thoughts on this?

    1. Using the FETs in interleaved or multiphase is one option, makes the design a little more complex but I think it’s a good solution. Look out for IGBTs as these are more suitable for higher current and voltages and are better suited to lower frequency applications than FETs offering a few advantages. They use IGBT’s in solar inverters and wind turbines for this reason, however they can be more expensive.

  4. Thanks for this article, I finished up a solar panel installation on my sailboat today and to be honest I was disappointed in the output. Its way off like 50% of what it should be, I did a bit more digging into the charge controller and its just a simple PWM dumping into the battery circuit.

    I was going to roll-my-own circuit similar to what you have here (I am an analog electrical engineer by trade) but this is a great start.

    Its disappointing the crap charge controllers thats out there, I have other systems on my boat by the same manufacture so I went with Xantrex. Its going back.

    1. Hi Guy,

      That is a pretty poor effieciency and think this is case with many of the cheap chargers. Well if you have an analog electrical background that puts you in a great position, ideal some knowledge of control systems will really help as well. You can build a purely analog MPPT, in fact they use them is space as a digital system would completely fail and be a single point failure.

      I am not a control engineer but a good knowledge of this area would be very helpful as well. I will be happy to help with your project and best to drop me an email through the site contact form.



      1. Analog would be a good choice… but then you have to deal with temp and component differences. A digital solution is fine and I can track the power / efficiency curves to an inexpensive TFT. I have a prior project I used an arduino with a TFT that had a simple serial interface for drawing primitives to.

  5. Hello, thanks for your very detailed guide.

    I do have a really dumb question though (I did read through the whole thing a couple times, but probably missed it): if the peak-power is ~30V across all irradiance, why do we have to vary the duty-cycle of the buck? Shouldn’t we just set it to 30V then be done with it?

    From the perspective of maximum power transfer, where we want to have the output impedance match the input impedance (I could be totally screwing this up, it’s been a while…) it makes sense, but then, shouldn’t current be in the X-axis and voltage be at the Y-axis? I guess in the end what’s throwing me off is the graph and what the independent and dependent variables are.

    Thanks in advance for your help.

    1. Hi Eric,

      The peak power for the panel is stated on the datasheet but that is under ideal conditions, the main factors that influence the panels voltage and current are solar irradiance and temperature. Solar irradiance will cause the panel current to vary and to a lesser extent the panels voltage, whereas the panel temperature will have a greater effect on the panel voltage. I used to design commercial photovoltaic systems in the UK and make select panels and inverters, design string layouts among other things. A string of panels has to be carefully matched to the inverter to ensure the maximum efficiency, but also to ensure that you avoid an over voltage condition due to the geographical temperature extremes of the site location. A panel may have a Vmpp of 30V at 25C, but if the temperature is at -10C that voltage could increase to 34V, an increase in temperature will have the reverse effect (temperature coefficient parameters for a given panel can be found on the datasheet).

      The MPPT algorithm is necessary as it needs to track the solar panels fluctuating power output, due to the these environmental factors. Now it is possible to use a PID algorithm to track an ideal panel voltage using it as a setpoint, but you won’t get the maximum efficiency; I have seen MPPT algorithms obtaining 98-99% efficiency whereas a PID based system might obtaining 90-95%.

      Not sure which graph you are referring to? The ones I generated where limited to the capabilities of CCS, the one from the solar panel datasheet shown in the first part of the tutorial can look a little confusing but I thought it presented the information quite nicely. You can search Google for other datasheets as often presented in different formats, it is good to see it from a different perspective sometimes.


      1. Man I’m an idiot for completely forgetting about environmental effects, so that makes plenty of sense now.

        I was referring to the Current-Voltage and Power-Voltage graphs. But now that I think more about it, I’m even more confused. From what I recall from my classes years ago, in a buck, frequency dictates voltage, and duty-cycle dictates impedance. In the 10W panel example, you’re fixing the output to 12V, right? So in that case, you’re ignoring the Vmpp of the panel, and just adjusting the impedance to always track the Impp, correct? Or there’s something else I missed about the 12V choice?

        1. I’m totally off again: I have no idea what frequency does (assuming an ideal circuit). It seems like the on-duty-cycle is the one that dictates output voltage (since this is the time that you’re charging the inductor, and to “buck” the input down, you want less than 100%).

          But I think I finally understand what’s happening now. The output voltage of the panel will ideally swing between Voc (of the panel) and our target Vout of the buck over temperature, irradiance…etc. By monkeying with the duty-cycle, we don’t actually care what the voltage of the panel is, because the panel’s voltage actually also depends on the load, so looking for maximum current, we’re by proxy also pegging the panel to it’s Vmpp.

          So I guess my confusion came from there seeming to be only one equation, but two unknowns. It turns out, there really only is one unknown, and that’s current. Get the right current, the right voltage naturally follows.

          Maybe my brain runs ass-backwards, but in this case, having current in the X-axis and voltage in the Y-axis makes more sense to me because we’re changing the output impedance, which implies both current and voltage, but this circuit really only measures current.

          I don’t know if any of this rambling makes sense. But I think it does to me!

          1. Hi Eric,

            The panel parameter Voc is only when there is a no load condition, as in Voltage Open Circuit, under normal conditions and assuming the MPPT is working the panel will not increase much above its stated Vmpp.

            The voltage and current are both unknowns, the P&O algorithm checks the power (V*I) and the voltage to determine the next duty cycle value. Look at the flow chart and walk yourself through it.


        2. Hi,

          I don’t fix the output to 12V, the 12V is used in the calculation to determine the buck converter inductor and capacitor size, the actual output voltage will vary around 12V.



  6. Hello,Ant
    Thank you that you share your ideas with people.May I ask a question to you?
    I see that you using two IRS2003 drivers and EPWM1A,EPWM2A outputs from DSC.
    Do you know how,these DSC outputs behave while you are connecting LaunchPad XL in emulation mode to the Code Composer Studio.Does any possibility exist that in emulation mode, EPWM1A,EPWM2A set active high or active low to the gate drivers?
    Can we destroy MOSFETs or IGBTs when we are connecting our XDS100 v2 to the TMS320F28027PTT for emulation debug? In what states are EPWM1A,EPWM2A initially?

    1. Hi Andrey,

      Sorry for not replying sooner just been away for a few weeks.

      As far as I remember the GPIO states after reset on the C2000 default to hi-impedance inputs, so the MOSFETs will be effectively off. As far as the PWM peripheral you will probably need to setup the peripheral registers and just not enable the PWM until you need to, maybe implement some error check to only enable the PWM peripheral if the state is false.

      As far as destroying MOSFETS or IGBTs it is possible pending on your implementation of the electronics and how the software controls that in certain conditions. There are many application notes on the subject regarding common errors with MOSFET or IGBT designs. My circuit is relatively simple and I had a controlled resistive load, a PFC system I made prior to this did have an issue upon switch on with high inrush currents, due to the MOSFETs being energised, but that was my fault with the circuit design and a software fixed worked around the issue (not ideal)….lesson learned!



  7. Hi, I am also trying to impiment MPPT using MATLAB. Have either of you made progress on this?


    1. Hi,

      Not used MATLAB to simulate an MPPT, something on my list of this to do just don’t have access to MATLAB at the moment.

      I think I have seen some videos on YouTube though, so maybe worth a look.


  8. Hi,

    I notice that you use the GUI from code composer to graph some variables with the program running. Can you explain more how you did that or perhaps link some references.


    1. Hi,

      IRS2003 and ULN2003 are completely different so don’t be fooled by the similarities in the part number!

      The ULN2003 would be a novel way to drive a MOSFET and it may work, but not as effectively as a dedicated driver IC. Power MOSFETS gates have a high instantaneous current when charging, which decreases as the gate capacitance charges, some dedicated gate drivers can deliver 4 or more amps, you also need to take into account discharging the gate as this is equally important. How much current is required is down to the circuit layout, mosfet used, gate voltage etc. The quicker you can turn the mosfet on an off can reduce losses and give better system performance (especially for high frequencies), the ULN2003 may work for lower frequencies but I would not recommend this and you might even damage the IC for this application, it states 500mA rated outputs.


  9. Hello, I am implementing MPPT with nxp’s lpx800 max board in which adc is not inbuilt so I connect the adc chip PCF8 591T with lpc800 via i2c bus using lpcxpresso version 7. Now, I am having working adc code & pwm code. Now i have to combine both the codes. I found your tutorial very professional & useful & saw your complete c code. My question is that how can i decide the constant calibrated voltage & current values in my case as you have shown in your c code??
    thank you….

    1. Hi Kinjal,

      The constants were calculated by using the values used for sampling the voltages and current. For example the voltage sampling potential divider uses 15k and 150k resistors, now using the formulae for a potential divider like this 15k/(15k + 150k) = 0.091, this can then be used as the basis for the constant as it needs further tuning and calibrating. I calibrated this by using a very accurate bench multimeter, then tweaked the constant value until an accurate reading was generated across the voltage range. For the input current this was simply 0.47 resistor and the gain used for the INA138, therefore 0.47 * 7.8 = 3.67, then the sample was then calibrated in the same way as for the voltage.


    1. Hi,

      I have not really used MATLAB so not something I have created, MATLAB is however something I want to learn just not had the time. I can possibly assist you in this and learn something about MATLAB at the same time.

      If your interested you can drop me an email with further details via the site contact page.

      Best regards,

  10. Hi,
    I am am working on my bachealor student project and I need to realize the MPP algorithm, I am not good enough in programming and my initial task is to uderstand the MPP using CCS tool, for this I need a sample C/C++ code that I can use to run in the CCS. Can you please suggest where I can get the basic source code (C/C++) for MPP.﻿

    1. Hi Sanjay,

      I couldn’t actually find any direct code and read quite a few articles from several universities as well as other source material. I did however find various flow charts and from these I formed my own code, which you can download and are free to use.


Leave a Reply