# Category Archives: C2000

C2000 projects and tutorials

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

The video below shows the system set-up, allowing the Perturb and Observe algorithm to be tuned.  There is also 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.

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

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.

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.

## System Schematic

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

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.

# Microcontroller GPIO Protection Tutorial

Microcontroller GPIO protection is an essential element of any circuit design.

GPIO ports generally have maximum voltage and current ratings, if these are exceeded it can result in the microcontroller being damaged or completely destroyed.

Therefore it is important to use external circuitry to protect the ports from excessive voltage, or excessive current being sourced from a pin.

The principles used in this post are for the MSP430G2231, however they can be applied to Arduino, Raspberry Pi and other microcontrollers, by taking into account the voltage and current specifications for each microcontroller, then changing the zener diode and resistor value accordingly.

## Over Voltage Protection

This is fairly easy to achieve with some basic external components, to explain this a simple example will be used based on the Texas Instruments MSP430G2231.  The maximum ratings for the integrated circuit need to be determined, this information can be obtained from the devices datasheet, MSP430G2231 datasheet can be found here.

The image below shows an extract from the MSP430G2231 datasheet, the maximum voltage rating can clearly be seen as 4.1V, there is also a cautionary warning which should be noted.

Now lets assume we are using one of the ports as an ADC input for a sensor, the voltage range for the ADC input on the MSP430G range is 0V to 3V.  So now we know the operating range and the maximum voltage, we can design some simple interface circuitry to ensure the microcontroller is protected.

The schematic diagram below shows a basic circuit which could be used to protect against over voltage.

The main components here that provide the over voltage protection, are D1 and R3.  D1 is a 3V3 Zener diode, which clamps the voltage if it exceeds 3.3V.  R3 has a dual purpose firstly if the voltage exceeds 3.3V the excess voltage will be dropped across the resistor, as the diode will have 3.3V across it i.e. over voltage is 5V, R3 will have 1.7V across it and D1 will have the remaining 3.3V across it.  R3 also acts as a current limit resistor, and Ohm’s Law can be used to calculate the maximum current with a known voltage.  Something to note here is the zener diode will take approximately 5mA of current in normal operation, this is less than ideal for battery operated applications.

The other components R1, R2 and the opamp are here to simulate a dummy sensor input.  However by designing a circuit using a single rail to rail opamp, the output of the opamp cannot exceed it’s rail to rail voltage, so with a supply of 0 to 3.3V the output cannot exceed 3.3V.  Therefore using a rail to rail opamp in a configuration similar to the one shown, can eliminate the need for the zener diode altogether.

## Over Current Protection

Over current protection as with over voltage protection, is quite simple to achieve.  Again it is best to consult the datasheet for the device to determine the current ratings, as can be seen below in an extract from the MSP430G2231 datasheet.

So the maximum recommended current that can be sourced or sunk is 6mA, and the total maximum current for all ports is 48mA (MSP430G2231 has 10 GPIO pins in total).  There are some further graphs shown in the datasheet, these show that it is possible to source 8mA from a GPIO pin, but the voltage on this pin will drop to approximately 2.7V as a result of the high current.  I would not recommend placing a load which draws 8mA, especially not on more than 1 pin, I always try to keep the current drawn from a GPIO around 1mA in most circumstances.  We can also see the voltage from the GPIO pins will be 3V.

By placing a resistor directly connected to the GPIO pin before any additional circuitry, we can limit the amount of current being sourced from the pin.  This resistor can be calculated by taking the 3V provided by the GPIO pin, lets assume we want to limit the current to 1mA, this gives us a value of 3kΩ the nearest standard value (going up) is therefore 3.3kΩ. This calculation can also be reversed and used to prevent excessive currents being sunk by the microcontroller.

3V rated at 1mA is not going to give much scope for driving external circuitry i.e. an LED or a relay, so it is best to use this to drive a transistor, using the transistor as a switch.

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.