C2000 Solar MPPT Tutorial C code Perturb and Observe algorithm

C2000 Solar MPPT tutorial Pt/1

This series of four posts will cover a project build for a C2000 Solar MPPT Tutorial.  The Maximum Power Point Tracker (MPPT) circuit is based around an interleaved synchronous buck circuit topology.  The microcontroller used is the Texas Instruments (TI) C2000 family, the C2000 Launchpad is used which has a TMS320F28027 chip on-board.  Considerable research was carried out on this project, as there was no prior knowledge of the C2000, all the relevant peripherals were tested separately and then brought together and tweaked for the final code.  TI provides all the documentation required, which can be found here and for this tutorial the ADC, ePWM and the F2802x Peripheral Driver Library Users’ Guide were referenced.

The C2000 solar MPPT tutorial can also be used as a guide if designing a circuit for other microcontrollers such as Arduino, as the electronic principles and some of the code is transferable to any platform.

The image below shows the final prototype MPPT PCB with the C2000 Launchpad secured on top via the header connections.

C2000 Solar MPPT Tutorial final prototype PCB

The video below shows the system set-up, allowing the Perturb and Observe algorithm to be tuned.  There is a second video demonstrating the algorithm tracking the maximum power point of the solar panel, this can be found on my YouTube account and will be embedded in the final tutorial.

In this part a basic overview of the hardware design will be covered, further tutorial parts will cover the following areas in greater detail:

  • Buck circuit calculation, a look at MOSFET efficiency, current and voltage sampling and circuit design and layout
  • Software approach including phase shifted PWM, ADC sampling and the Perturb and Observe algorithm
  • Final set-up, testing and tuning

Maximum Power Point Tracking

Maximum power point tracking is employed, to ensure the maximum power is extracted from a solar panel.  In order to understand this further we first need to look at the power curve characteristics of a solar panel, the image below shows a Suntech STP230-20Wd (230W panel) power curve.

C2000 Solar MPPT Tutorial solar panel power curve

The maximum power point (MPP) of a solar panel lies at the knee of the current and voltage curve.  Reading the datasheet on the Suntech panel tells us that Vmp (voltage at maximum power point) is 29.8V and Imp (current at maximum power point) is 7.72A, locating the intersection point of these two values, it can be seen that the MPP is at the knee of the curve. The graph also illustrates that the voltage variation is much less compared to the current only with differing irradiance, however the current varies linearly with solar intensity.  Temperature also affects the power output from a panel, current increases slightly with an increase in temperature, whereas voltage decreases with an increase in temperature.  As the voltage is affected by temperature more than the current, voltage calculations need to be considered when large string arrays are used, to ensure the system meets the requirements of the inverter used.

The panel has an internal resistance which changes dynamically with differing irradiance levels.  So if a static load is connected directly to a panel and its resistance is higher or lower than the panels internal resistance at MPP, then the power drawn from the panel will be less than the maximum available.  Taking a simple example under bright midday sun, say we connected the Suntech STP230-20Wd directly to a 12V lead acid battery, the panel voltage would be dragged down near to the load voltage of the battery as the batteries resistance is lower than the panels.  With a quick calculation the panel is now outputting 12V and 7.72A, therefore 93W, this equates to a loss of 137W or 60%. Obviously this is an extreme example, but even using a 24V battery would still equate to a 20% loss, which is far from efficient.

This is where MPPT comes into play.  MPPT circuits can be based on various switch mode power supply (SMPS) topologies, they generally have a fixed frequency but varying duty cycle.  The duty cycle is controlled via an algorithm so as to track the changing MPP, the output power is determined by the efficiency of the circuit and usually closely matches the incoming power within 3-10% (typical losses).  The output voltage and current will not necessarily be fixed under changing irradiance conditions depending on the system employed, so further circuitry maybe required or a more elaborate algorithm.

System Overview

The image below shows an overview of the final system

C2000 Solar MPPT Tutorial Prototype System Diagram

The solar panel in the diagram will be represented in real life by a 10W panel purchased from Ebay, this has a Vmp of 17.2V and an Imp of 580mA.  Four ADC inputs and 2 PWM outputs will be used on the C2000.  The input voltage and current and output voltage and current will both be monitored, so the input and output power can be determined.  A pair of half bridge driver integrated circuits (IC) will be used to drive the four N-Channel MOSFETs. There is also an auxiliary supply, this was used to power a 12V linear regulator which powered the half bridge drivers.  The 12V regulator could also be powered directly from the panel, which was used in testing under bright sun conditions.

The chosen SMPS topology will be based on a synchronous buck converter circuit, there will be two of these in parallel forming an interleaved design.  Using an interleaved approach is over kill for the 10W panel prototype, but it gives the system scalability for future iterations.  The synchronous buck design was chosen as it offers a higher efficiency, these design choices will become clear as the tutorial progresses.

Interleaved Synchronous Buck Converter

The buck converter circuit will be over viewed as this forms a large part of the system design, this will naturally lead into the advantages of the synchronous and interleaved design chosen.  A boost circuit could quite easily be implemented in place of buck design, but in this case the target output voltage was 12V.

A buck converter is basically a small DC to DC converter.  The main principle at work in a buck converter, is the tendency for an inductor to resist changes in current.  A buck converter output voltage will always be lower or the same as the input voltage.  A simplified schematic of a buck converter can be seen in the below image.

C2000 Solar MPPT Tutorial buck converter circuit

A buck converter relies on a switch to change or reduce the current flowing through the inductor, the switch usually takes the form of a MOSFET (Q).

  1. When the MOSFETs gate is saturated effectively closing the switch, current flows through the inductor (L) in a clockwise direction into the load (R) and also charging the output capacitor (C).  At this point the voltage on the cathode of the diode is positive, therefore the diode (D) is blocking any flow of current and is said to be reverse biased.  The Instantaneous current flow into the load from Vin is slow, as energy is stored in the inductor as it’s magnetic field increases.  So during the on phase of the MOSFET, energy is loaded into the inductor.
  2. When the MOSFET is switched off, the voltage across the inductor is reversed.  The inductors magnetic field begins to collapse, this collapse releases the stored energy allowing current to flow from the inductor into the load.  The diode now has a negative voltage on the cathode so becomes forward biased.  Therefore the inductors discharge current flows in a clockwise direction through the load and back through the diode. Once the inductors energy has fallen below a certain threshold, the load voltage falls and the capacitor becomes the main source of current, ensuring the load is still supplied until the next switching cycle begins.  To ensure Continuous Conduction Mode (CCM) the inductor must not be fully discharged before the MOSFET is switch on again, and the cycle repeats.

Now that the basic concept of a buck converter has been explained the synchronous design can be covered.  The synchronous design simply replaces the diode with a second MOSFET, this eliminates the losses incurred by the forward voltage drop across the diode, thus making the circuit more efficient.  This is slightly more complex to implement, as the second mosfet switching needs to be carefully timed with the switching of the first mosfet.  It is essential to ensure that both are never on at the same time, or the current will have a direct path to ground, effectively causing a short circuit.  The MOSFET switching is effectively 180 degrees out of phase, with a short delay period between each transition referred to as a Dead-Band.  A dead-band is usually a common feature of most half bridge drivers, the C2000 also allows for the dead-band to be programmed in and tuned, so in reality with modern microcontrollers this is quite simple to implement.

The interleaved design simply takes two synchronous buck circuits and places them in parallel, the main components MOSFETs and inductor are individual to each circuit, but they share a common input and output as well as the same input and output capacitors.  Using an interleaved design reduces the current ripple by half, as each interleaved phase shares the total current.  The shared current allows smaller inductors and capacitors to be used, which can also reduce system size and cost.  Additionally this systems PWM frequency was chosen to be 15kHz as it reduces the switching losses in the MOSFETs, but increases the current ripple and also the inductor size.  By using the interleaved approach it then helps to negate these factors.  These trade-offs will be covered in more detail in the hardware section of this tutorial, where MOSFET losses will be covered.

10W Solar Panel

As mentioned previously the solar panel was purchased from Ebay for around £20.  It’s a polycrystalline panel, which is encased in an aluminium frame and comes with 2 large croc clip leads and a small diode box.  The panel seems pretty good quality and appears to be weather proofed, the diode box is not sealed very well but as it sits under the panel I don’t believe there would be any issues.  Have enclosed 2 shots of the panel, and I can probably dig out the links to the company if anyone is interested.

C2000 Solar MPPT Tutorial 10W panel front

C2000 Solar MPPT Tutorial 10W panel back

System Schematic

C2000 Solar MPPT Tutorial hardware schematic

The next part of this tutorial will go more in-depth into the circuit calculations and schematic design.

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

  1. Great work! Did you read AN1521 (Practical Guide to Implementing Solar Panel MPPT Algorithms) ?? In this application note, the buck converter uses two mosfets and also two coils, but in a different configuration from your circuit. Could you please tell me what is the purpose of the second coil? Thank you!

    1. The intention is to have multiple phases that share the current, these are out of phase with the original which helps to reduce thew current peaks and troughs, think of a half wave and full wave rectifier as rough analogy when look at the current waveform.

      The more phases you have the smoother the power delivery for the secondary circuit, PC motherboards often have 8 or more phases for the CPU and RAM power.

    1. Hi,

      I don’t have a MATLAB/Simulink model I’m afraid and this may not be the best place to ask. I would suggest you go onto the MATLAB forums and see if there are any specific forums for MPPT or C2000 as possible they can be exported or adapted.
      Thanks, Ant

  2. Your MPPT project is interesting & it is very helpful to me. Thanks.
    I have one doubt that out put voltage of buck converter is considered as 12V while designing but battery can be at 13.8V or at more voltage. What is the reasons for selecting output 12V? thanks one again for wonderful project.

    1. The 12V was simply used as an example, agreed if you wanted to charge a lead acid battery 13V or more would be more suitable.

    1. I have now removed all Adfly links so everything is directly downloaded from the Coder-tronics website, sorry this has taken so long but been pretty busy

  3. Hello!

    Thank you for very nice and practical article. I gave one question about buck converter presented on the system schematic. Why you did not use the diode that appears on the simplified buck converter schematic?

    Andrew

    1. Hi Andrew, well over due reply and sorry for such a long delay. There will be a voltage drop across the diode so this will equate to power losses in the circuit, by using a suitable MOSFET you can reduce those losses significantly

  4. 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.

      Cheers,
      Ant

  5. 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.

  6. 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.

  7. 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.

      Cheers,

      Ant

      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.

  8. 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.

      Cheers,
      Ant

      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.

            Cheers,
            Ant

        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.

          Cheers,

          Ant

  9. 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!

      Cheers,

      Ant

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

    Thanks,
    Josh

    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.

      Regards,
      Ant

  11. 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.

    Thanks

    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.

      Regards,
      Ant

  12. 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.

      Regards,
      Ant

    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,
      Ant

  13. 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.

      Cheers,
      Ant

Leave a Reply