C2000 Solar MPPT Tutorial 4

C2000 Solar MPPT Tutorial Pt/4

In this fourth and final part of the C2000 Solar MPPT Tutorial, the system set-up and testing will be looked at.  This will involve the overall hardware set-up for testing, ADC calibration, reduction of noise on the ADC sampling, efficiency test and some improvements for future iterations.  The final C2000 solar MPPT tutorial C code is also downloadable at the bottom of the page.

System Testing

Once the hardware was calculated and designed, the PCB was laid out and then printed using the freeware version of EagleCad.  The PCB was then printed on a LPKF milling machine, the finished component side of the PCB can be seen in the image below.

C2000 Solar MPPT Tutorial PCBThe board was given a thorough visual check, it was noted some of the drill holes on the component side were marginally out of alignment.  This is due to a slight misaligned of the milling machine alignment pins, the bottom of the PCB is milled first and then flipped so the component side can be milled.  When the board is flipped the minor misaligned becomes apparent, it is not enough to cause an issue, but I manually make all my own footprints allowing for the small idiosyncrasies and tolerances of the milling machine.

The components used for the design were mainly sourced from the education institution stock, with only the INA138 being ordered in.  This reduced any unwanted lead times and also keeps costs down.  There are down sides to this which were found with the IRFI640G MOSFETs.  The mistake was made of soldering these directly onto the PCB without checking the MOSFETs first, they were sourced from a large bag of perhaps 500 or more IRFI640G, all previously reclaimed from other boards.  Once the board was constructed it was noted the power supply was going straight into over current protection, this was narrowed down to two faulty MOSFETs that were short circuit, between Drain and Source.  A quick on the fly test I used to check the MOSFETs can be seen in the image below.

C2000 Solar MPPT Tutorial MOSFET Testing

System Calibration

Once the board was working, the next step was to test the buck circuits under controlled conditions,  The test involved the C2000 being set-up to supply a fixed PWM output of 50% duty cycle on PWM1, with PWM2 180o out of phase.  A dummy load in the shape of a 100W potentiometer set to 50Ω was connected to the output terminal, with a 20V supply applied to the solar panel input pins.  A multimeter was used to then measure the output DC voltage, which was observed to be 10V, this confirmed the buck circuit was operating correctly, the 20V was adjusted down to approximately 15V and the voltage was observed to half on the output.

After this initial test the ADC values being sampled needed to be calibrated, this would involve measuring the input voltage and current as well as the output voltage and current.  To achieve this to a good accuracy the same test conditions were used and two Hewlett Packard 34401A multimeter’s.  Some constant values were calculated from the signal conditioning circuitry (see the second part of this tutorial here) used to sample the ADC values, these were calculated as follows.

C2000 solar MPPT Tutorial ADC Constant Equations

These values would then need to be adjusted to meet the tolerances of the circuit.  A laptop was also set-up running Code Composer Studio (CCS) and the calculated ADC variables were viewed, and then the constant calculations values altered until the accuracy was satisfactory. The actual ADC constant values used can be seen in the below code snippet

// Constants
const float ADC_12bit = 0.0008056;	// 12bit ADC voltage resolution
const float IP_Volt_Const = 0.0814;	// Calibrated constant input voltage
const float IP_Amp_Const = 4.31;	// Calibrated constant input current
const float OP_Volt_Const = 0.085;	// Calibrated constant output voltage
const float OP_Amp_Const = 3.6;		// Calibrated constant output current

Various test were carried out at this point to see how the ADC calibration and sampling was working, experimenting with sample and hold times, over sampling.  A useful tool is the graphing feature in CCS this allows trends to be observed in variables.  The original set-up used a timer to trigger the ADC sampling, however this generated more noise due to the MOSFET switching, so the PWM was used to trigger the ADC SOC.

The next image shows a screen capture from CCS, with the debug mode in operation.  The MPPT circuit was supplied with 17.5V from a regulated power supply, the load potentiometer was set to 40Ω, a PWM frequency of 25kHz (not 15kHz) with a 50% duty cycle was used in an open loop configuration.

C2000 Solar MPPT Tutorial 25kHz_25SH

What this graphed data shows is a 2 minute sample window (click the image to expand), the top graph is the input current with a variation of 2.4mA, and the bottom graph input volts with a variation of 10mV.  At the top right of the graph the ADC input variable values can also be seen, the two highlighted in yellow just indicates the value has just changed.

Efficiency Test

This basic efficiency calculation test was made by graphing the the input and output power under different power conditions.  The power efficiency fluctuated between 85~93%, with the greatest efficiency being achieved towards mid-range power.  The graphed data can be seen below with the input power at the top and the output power at the bottom.

C2000 solar MPPT Tutorial Power Efficiency Graph


This was a prototype design and the first attempt at a solar MPPT, as such there are some improvements that can be made for future iterations.

On the software side, the clock speed for the C2000 could be reduced as there is plenty of idle time, the processor could also be placed into a low power mode between timer interrupts, this would bring an overall reduction in power dissipation.  Additionally a battery charging statement machine could be easily added, with a further form of regulation to switch between full charge and float charge.  If the circuit did not require an interleaved design, the code structure and algorithm could be easily ported across to a lower power and less expensive microcontroller like an MSP430G series.

On the hardware, the MOSFETs are key components that could be changed making the system more efficient.  Greater use of surface mount devices would reduce the circuit trace lengths and noise.  An improved ground plan design would also help reduce noise.  The trace lengths for each circuit phase ideally need to be identical, this will help to balance the phases.  It is possible to sample the current in each phase, then use software to adjust the duty cycle to correct any imbalances, however this increases the overall systems complexity particularly the software.

C2000 Solar MPPT Tutorial C Code Download

The link below contains the zip file with the complete C code.

C2000 Solar MPPT Tutorial Full C Code

38 thoughts on “C2000 Solar MPPT Tutorial Pt/4”

  1. Hi Ant,

    Whenever I click on the code, I went to a website which is for just an advertisement. I cannot download the code. Can you please help.


    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

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

    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

  2. Good evening. Your tutorial was really inspiring. However, the battery parameters were not checked from your code, so why did you need to measure them? Thanks.

    1. Hi,

      Thanks, the intention was for this to be a part of a battery charging system as the end goal, so a 12V lead acid cell was used as an example. However, it was never in the scope of this first initial project to incorporate a battery charging circuit, as there simply wasn’t enough time and this was my first attempt at a solar MPPT.

      The battery example is also a good example as to why a MPPT can improve the efficiency of system.

      I have made a second MPPT now, still not with battery charging but just not had time to post the details.

  3. Hello Ant,
    Your C code is simply awesome. Thank you. However, is there a way I can use it for a PSOC 5 kit? If there is please help me ASAP. Thanks again.

    1. Hi,

      Thanks and hope it proves useful. The code is written in C so the P&O algorithm is easily ported, as well as the code structure, the over sampling method etc. You will need to setup the PSOC ADC, Timers, PWM and GPIO, as well as taking into consideration your own electronics.


  4. Hello there,

    thanks for the awsome mppt tutorial. I’m new to code composer studio, i want to know how do i compile the c code i downloaded from you website. Thanks!

    1. Hi,

      I ran into issues running some example codes on the C2000 when I first started using the micrococontroller and had to make some custom changes to some of the settings in Code Composer Studio.

      Creating a new project in CCS then copying and pasting the code may not create all the necessary settings for correctly compiling and loading the code onto the C2000, it will likely flag a few errors although the code was error free with possibly a few warnings when I posted up here.

      Pending on the errors you get I would work through them systematically a good source of information is the EE forums on TI. But sometimes copying and pasting into Google will flag up an issue with a linker file that someone else had a resolved.

      I can try and help pending the issue, but using CCS is a very broad subject!


      1. Hi Ant,

        It is a good learn curve, and thanks for the recommedations. I’m getting 1 error #195 cannot open source file “DSP28x_Project.h” I located that header file on my drive C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_common\include
        I right click and used add files and added that header file and i’m still getting the same error msg. Can you please help big thanks!!

  5. hi
    thanks so much for your effort in this project
    I just want to ask you what I have to change if my solar power =100 w
    and I want to buck boost convertor ?

    1. Hi,

      Well you need to take into consideration the following parameters:
      1) Input voltage and current range, which is determined by your solar panel
      2) Output voltage and current range form the system
      3) What frequency you want the PWM to run
      4) What is the load and do i need to further regulate the voltage

      With these you can then calculate the basics for the buck, if its a buck boost you want then you have a different circuit. If you search on Google you will find Buck Boost literature, but you need to carry out some research as I don’t have any links to hand.

      Things like inductor size, shunt resistor size will all increase with 100W of power, as well as ensuring the MOSFETs are suitable for your voltage and current ranges.


        1. Hi,

          You need to research MOSFETs that can take the power requirements you require, as well as inductors and the other associated components.


  6. hie found your tutorial very useful but i have got a question…can you use this code on a pic 16f877A ???if not what variable must i change or what section of the code must i edit so that the code runs on a my pic 16f 877/ 16f877A

    1. Hi,
      The MPPT algorithm is portable but the rest is probably not. Some of the principles with regards to code structure maybe similar, but I am not familiar with the pic16f series and its internal peripherals.

      For example:
      1) The ADC sampling trigger, you may need to use a timer on the PIC, but in the C2000 case I used the PWM signal to trigger a sampling sequence.

      2) The speed of the over sampling and the algorithm update frequency will be some what dependent on the processors clock rate and ADC register settings. If you used the same amount of over samples I used, then the averaging code could be ported.

      You can do it I am quite sure, but takes a bit more thought than changing a few bits of code.


  7. Hi Ant!
    How it is possible that the bootstrap works properly with battery voltage at VS pin of IR mosfet driver? Did You have problems with reverse current from battery, through inductor and low side mosfet to gnd at light load?


    1. Hi Dominik,

      The VS pin is connected between the MOSFETs and the output inductor and there was no battery on the output as I used a larger variable resistor as a load. The MOSFET driver is configured as per International Rectifiers datasheet.

      My intention for the future is to have a battery charging circuit after the MPPT, but this is not in this project at this time.


  8. Great article. I’ve never heard of MPPT until I see this write up. Very nice.
    You mentioned about MSP430, but they usually only have 10-bit ADC, do you think it’s good enough? I guess it’s good enough since we don’t really actively need a stable or flat output as we would with a voltage regulator, right?

    1. Hi Thanh,

      Thanks. The MSP430 is definitely possible and even on the value range, it’s something I want to work on sometime. The biggest issue will not be the resolution of the ADC, but the noise on the samples due to the switching of the MOSFETs. Filtering this possibly through oversampling etc will have a knock on effect of slowing the rate you can update the duty cycle to account for changes in irradiance.

      So I would say the C2000 is far better suited for control applications like this as you can can have the ADC sample time triggered to the PWM switching, this allows a far more predictable point of sampling. An MSP430G version will however be cheaper and should also be simpler on the coding side.


      1. Hi Ant

        Thank you very much for the reply and for the info. Seeing you update the MPPT at the rate of 10Hz I think it should be fine with using MSP430 with oversampling to filter out the noise. I was able to get 500Hz update rate from a F2274 ADC with oversampling to get 12-bit resolution (MCLK ran at 8MHz).

        I need a MPPT charger soon. So I think I will give the MSP a chance. Need to source the components. Seeing the charge going to 12v battery at 4.5A with a 100W pannel in the middle of the day kind of hurts 🙂

        I was doing this to charge my LiFePo4 battery packs. Not a pretty solution for sure. I needed a boost converter that offers CC/CV and can be programmed



        1. Hi Thanh,

          The update rate of the MPPT which basically equates to the duty cycle being updated doe#s not necessarily need to be that fast. I am not sur what current commercial inverters update this at but when I used to design photovoltaic systems (4 years ago) the inverters only updated at 2Hz.

          You can even design the system electronics to have a specific output voltage and duty cycle for a specific solar panels MPPT, then use a PID algorithm to hold the output voltage at a steady rate that has a duty cycle matching the system electronics calculations and tests. A PID used in this way can be over 90% efficient and is less likely to be confused by fast changing irradiance. It may however not give as much power efficiency over the entire range of power produced by the solar panel, this is something I want to investigate in the future.

          Sounds like an interesting project, the LiFePo4 are impressive and seem very robust when charging, not so cheap though. Li-ion is another option but more care has to be taken with the charge circuit.


    1. Hi,

      The link works 100% (just checked with Chrome) and I have had over 60 downloads this month already, please check your browser and ensure there are no add blockers or try a different browser. The Adfly link takes 5 seconds and helps me pay towards the hosting costs for the site, all the other work I do is completely free.


  9. hello…Thank you for your reply…I have downloaded the c code. I am implementing MPPT using nxp’s max board. I have working code of ADC & PWM .I have 3 questions..please help me to sort it out:
    1.in your schematic, what is RP51 & RP52 connected between pv_up & pv_dwn as well as vout_up & vout_dwn?
    2.how can I decide the calibrated value of voltage & current in my case as you shown in your c code?
    3.Can I use another mosfet driver instead of IRS2003?
    will be obliged if i got the solution of these questions.

    1. Hi Kinjal,

      1) RPS1 and RPS2 are two 1 Ohm resistors in parallel, when measured these were read at 0.47 Ohms. The same is true for RPS3 and RPS4, all these resistors act as shunt resistors and form the high side current measurement circuit.

      2) Use an accurate bench multimeter and do real time measurements in your IDE at the same time, then adjust calculation variables to bring them in-line with the multimeter.

      3) You can use other MOSFET drivers, I don’t have any that spring to mind as this is what was in stock at the time. International rectifier make a number of drivers, as do Texas Instruments, Analog Devices etc. If you browse Farnell.com and look up half bridge drivers, then you will find many that are suitable, it’s just a question of cost and stock then.


  10. It was a great article…thank you for sharing it..please help me to download the zip file which contains the complete C code. I could not download it..

    1. Hi Kinjal,

      Happy you found it useful, the download definitely works, there is a small advert page via Adfly that you have to wait 5 seconds. Its possible you might have an ad-blocker active in your browser?

  11. Hey Ant,

    Thanks i could download it now, recently launchpads have landed in my college(10 of them), your documentation is very easy and efficient way to get started. Keep up the good work to help the beginners like me.

    1. Hey Sachin,

      Glad you got it down ok. I had intended to write more C2000 tutorials but just not had time of late, will get them up soon I hope.

    1. Hi Sachin,

      The download is working you go via a small Adfly (advert link) takes about 5 seconds, then the download will start. The lnik has been tested and there has been over 20 downloads this month already. I have the adverts as it helps me to pay towards hosting, please insure you are not using an ad-blocker and maybe try another browser.

      Best regards,

Leave a Reply