Description of example project
==============================
This example implements a Buck Converter in Peak Current Control mode
for being used together with the XMC Digital Power Explorer kit. Visit www.infineon.com/xmc_dp_exp.
The project is implemented using XMC4200 digital power control card, housing a 32-bit ARM Cortex M4
based microcontroller with FloatingPoint Unit. In addition, it also has dedicated control peripherals
such as the HRPWM module, including CSG module. CSG is comprised of an analog comparator and a intelligent DAC
capable of creating negative ramps for best slope compensation. HRPWM peripheral in XMC4200 also provides the 
ability to generate high resolution PWM (150 ps resolution). A Versatile Analog-to-Digital (VADC) module for analog signal measurement,
is also included making XMC4200 suitable for applications that require fast calculation such as the Peak Current Control mode.

The current Control loop is implemented by a classic 2 poles 2 zeros filter using floating points values.
The provided filter coefficients has been selected to have the following controller characteristics:
 + Switching freq = 200kHz
 + Crossover freq = 10kHz
 + Phase margin   = 50 degrees
 + PWM            = 80MHz
 + ADC resolution = 12 bits 
 
VADC conversion is being continuously triggered by the Compare Match 2 of the CCU8 (set by default to the maximum, period value).
Once the output voltage has being measured by the VADC, an interrupt is generated. 
Inside the ISR, the 2 poles 2 zeros controller is applied and new value for the DAC slope start is set.

 ADC Trigger                        ADC Trigger
    ;                                   :
    ;_______                            :________
PWM |    <--|-->                        |     <--|-->
____|       |___________________________|        |_______
    ;                                   :
    ;                                   :
    ;   ADC                             :   ADC
    ;<--------> __________              :<--------> __________
ISR ;          | Filter + |             :          | Filter + |
    ;          |DAC Start |             :          |DAC Start |
____;__________|  update  |_____________:__________|  update  |_______

One instance of each of those DAVE 4 APPs have been used to easy the peripherals configuration:

HRPWM (High resolution PWM, generates the ADC trigger through the CCU8 peripheral and the HRPWM)
COMP_SLOPE_GEN (Includes Comparator and Slope Generator(DAC) Generates the reference and configures the comparator)
ADC_MEASUREMENT_ADV (Output Voltage measurement)
INTERRUPT (NVIC configuration)

Filter related APIs are implemented in the xmc_2p2z_filter_float.h file
while the PWM initialization and control ISR are implemented in the main.c.
   
Hardware Setup
===============
XMC4200 Digital Power Control Card + XMC Digital Power Explorer Kit
Vout P14.6
CCU8 direct output P0.4
CCU8 inverted output P2.15
HRPWM out0 P0.5
HRPWM out1 P0.2
Vin  P14.3 (not measured in project)

How to test the application
============================
a. Import the project into DAVE
b. Compile and flash the application onto the device (XMC4200)
c. Run the application. For hardware set up consult getting started document in www.infineon.com/xmc_dp_exp 
d. Check via oscilloscope the different test points available
   in the Digital Power Control Card.
   Vout is now controlled to be stable at 3,3 V independent of load switching
   LEDs next to load switches must turn on when that particular load is activated
f. If changes are needed in APPs configuration, make sure code is generated again before compiling