# Tiva ware CCS Tm4c123gxl kit Boost Converter Feedback

#### IBO3252

Joined May 17, 2023
4
Hi guys,

I'm Trying to make a feed back with a Voltage divider for a boost converter that has the following parameters:
Vin = 6 to 10 Volts
Desired Vout (at load) = Constant 12 V

When Vin increases Vout increase too then as a result the Voltage divider Vout increases also

but Desired Vout should remain at 12 V (That is the application), so The code converts the 12 Volt to be out of 100 then read the new Vout value of the voltage divider AD0 at PE3 than convert it to be out of 100, then compare Vout Voltage divider to Desired Vout
if Desired Vout > Vout Voltage divider it should increase the pwm duty cycle
if Desired Vout < Vout Voltage divider it should decrease pwm duty cycle

But The problem is the code doesn't increase or decrease the pwm signal when Vin increases So could anyone help me plz

Boost Converter Feedback:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

#include "pin/pin.h"

uint32_t DutyCycle;
uint32_t Value_of_ticks;
uint32_t Desired_V_Value;

uint32_t CON_Desired_V_Value;
uint32_t Zero = 0;

// Constraint value function
uint32_t constrainValue(uint32_t DutyCycle) {
// Check if the value is within the specified range
if (DutyCycle < Zero) {
return Zero; // Value is below the minimum, constrain to minimum
} else if (DutyCycle > 100) {
return 100; // Value is above the maximum, constrain to maximum
} else {
return DutyCycle; // Value is within the range, no need to constrain
}
}

int
main(void)
{

//
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

//
// Set the PWM clock to the system clock.
//
SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

//
// The PWM peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

// Wait for the PWM0 module to be ready.
//
{
}

//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

//
GPIOPinConfigure(GPIO_PB6_M0PWM0);

//
// Configure the GPIO pad for PWM function on pins PB6 and PB7.
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);

//
//
//
//
{
}

//  ADC0 is used with AIN0 on port E7.
//GPIO port E needs to be enabled so these pins can be used.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

// Select the analog ADC function for these pins.

//
// Enable the first sample sequencer to capture the value of channel 0 when
// the processor trigger occurs.
//

//
// Since sample sequence 3 is now configured, it must be enabled.
//

//
// Trigger the sample sequence.
//
//
// Wait until the sample sequence has completed.
//
{
}

//
// Configure the PWM0 to count up/down without synchronization.
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN |PWM_GEN_MODE_NO_SYNC);

//
// Set the PWM period to 250Hz.  To calculate the appropriate parameter
// use the following equation: N = (1 / f) * SysClk.  Where N is the
// function parameter, f is the desired frequency, and SysClk is the
// system clock frequency.
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 320); // <-----------------

//Type the desired Duty cycle ***********************Very impresive

DutyCycle = 33;

//Claculates the reqired value of ticks to get the Specified Duty cycle

Value_of_ticks = ( PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) * (DutyCycle) / 100 );

//Sets the Pwm signal
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
Value_of_ticks );//

// Enables the counter for a PWM generator block.
//
PWMGenEnable(PWM0_BASE, PWM_GEN_0);

// Enable the PWM0 Bit 0 (PD0) and Bit 1 (PD1) output signals.
//
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

//

Desired_V_Value = 12;

//Convert 12 to 100 system
// So if the Vout increases the Voltage divider output w'll 'increase and measuring from there we can make a feedback
CON_Desired_V_Value = (Desired_V_Value * 100) * 12;

//Reads the other analog pin than covert the voltage divider value to 100

DutyCycle = DutyCycle +1;
DutyCycle = constrainValue(DutyCycle);
}

}