I'm road testing the Infineon Gate Driver with Truly Differential Input. It's a half bridge driven by a PWM signal. The firmware that comes with this kit always drives the half-bridge to 50%. I've changed it, so that you can control the duty cycle from 5 to 95 % with a potentiometer. |
I've started from the example that comes with the kit, and mixed the Dave ADC_MEASUREMENT_EXAMPLE_xxx with it.
The ADC example (downsized to only take one measurement) checks the value at pin P2.0.
I've connected a potentiometer to the XMC 2 Go controller board, one side to 3V3, one to GND and the wiper to P2.0
The ADC example works based on an interrupt and stores the measured voltage at P2.0. That represents the position of the potentiometer.
In the firmware, I calculate a % out of that position ( turned off being 0%, completely to the right = 100%).
The PWM settings (that are defined by constant values in the original example) is in my version calculated based on that potentiometer position.
I've attached the firmware to this post.
Working with the DAVE IDE
You can customise your firmware with DAVE APPS. An ADC and a PWM are example of such apps.
PWM
The standard program comes with 2 PWM apps. One for the high side and one for te low side signal.
They are linked., so that the second PWM fires when the first one's falling edge.
Here's how the standard program controls the PWM behaviour:
// PARAMETERS TO SET: FSW, D, T_D #define CLOCK_F 64000000.0 #define FSW 100000 // SET the PWM frequency FSW (Hz); #define FREQ (uint32_t)(CLOCK_F / FSW) #define D 0.50 // SET the duty cycle D for the PWM LS (Express D in [0,1] ); //#define D 0.08 // SET the duty cycle D for the PWM LS (Express D in [0,1] ); #define DUTY (uint32_t)((1-D)*FREQ) #define T_D 109 // SET the dead time T_D between the PWM LS and HS (Express T_D in ns) #define DEAD_TIME (uint32_t)((T_D*CLOCK_F*0.000000001)+0.5) PWM_CCU4_0.ccu4_slice_ptr->CRS = DUTY; // Duty cycle (PR-CRS) PWM_CCU4_0.ccu4_slice_ptr->PRS = FREQ; //Operating frequency PWM_CCU4_1.ccu4_slice_ptr->CRS = DEAD_TIME-5; //Dead time PWM_CCU4_1.ccu4_slice_ptr->PRS = DUTY-DEAD_TIME-5; //Duty-Dead time PWM_CCU4_0.ccu4_module_ptr->GCSS = PWM_CCU4_0.shadow_txfr_msk | PWM_CCU4_1.shadow_txfr_msk;
In my program, D is not a constant, but a function getDuty():that returns a value between 0 and 1 based on the sampled wiper position:
volatile uint32_t result_potentiometer = 0u; uint32_t getDuty() { float retval = ((4096 - result_potentiometer) * 1.0); retval /= 4096; retval = retval > 0.95? 0.95 : retval; retval = retval < 0.05? 0.05 : retval; retval *= FREQ; return (uint32_t) retval; }
This only slightly changes the PWM logic.
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0); PWM_CCU4_0.ccu4_slice_ptr->PRS = FREQ; //Operating frequency PWM_CCU4_1.ccu4_slice_ptr->CRS = DEAD_TIME - 5; //Dead time while (1U) { // PARAMETERS TO SET: FSW, D, T_D uint32_t duty = getDuty(); PWM_CCU4_0.ccu4_slice_ptr->CRS = duty; // Duty cycle (PR-CRS) PWM_CCU4_1.ccu4_slice_ptr->PRS = duty - DEAD_TIME - 5; //Duty-Dead time PWM_CCU4_0.ccu4_module_ptr->GCSS = PWM_CCU4_0.shadow_txfr_msk | PWM_CCU4_1.shadow_txfr_msk; }
ADC
I borrowed from the ADC_MEASUREMENT example available from Infineon. The example samples two pins and I only need P2.0, so I slimmed it down.
You can assign the pin used to sample via the Manual Pin Allocator:
In my code above, you can see that I declared the variable to hold the sampled wiper value as a global volatile one:
volatile uint32_t result_potentiometer = 0u;
In the ADC app, I declared the interrupt handler:
The handler is implemented in the firmware:
void Adc_Measurement_Handler(void) { /*Read out conversion results*/ result_potentiometer = ADC_MEASUREMENT_GetResult( &ADC_MEASUREMENT_Potentiometer_handle); /*Re-trigger conversion sequence*/ ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0); }
It samples, stores that value in the global variable, then re-arms the trigger.
Because the PWM loop runs forever (like an Arduino loop(), it picks up the last sample and adapts the PWM duty cycle.
The photo below shows the setup in action, at 66.5% duty cycle.
Turning the potentiometer from left to right regulates the bridge from low to high output.
A nice bonus is that on the Infineon evaluation board, the LEDs for both channels (both the input and power ones) dim and brighten along.
Top Comments