Tiva ware CCS Tm4c123gxl kit Boost Converter Feedback

Thread Starter

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
Voltage divider Vout (goes AD0reading into Tiva C) = Volt.

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

Thanks, in advance!



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 "driverlib/adc.h"
#include "pin/pin.h"


uint32_t DutyCycle;
uint32_t Value_of_ticks;
uint32_t ui32Value_adc;
uint32_t Desired_V_Value;

uint32_t CON_ui32Value_adc;
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.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0))
    {
    }

    //
    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);


    //
       // Enable the ADC0 module.
       //
       SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
       //
       // Wait for the ADC0 module to be ready.
       //
       while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
       {
       }


       //  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.
          GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

   
          //
          // Enable the first sample sequencer to capture the value of channel 0 when
          // the processor trigger occurs.
          //
          ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
          ADCSequenceStepConfigure(ADC0_BASE, 0, 0,
                                   ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CH0);

          //
          // Since sample sequence 3 is now configured, it must be enabled.
          //
          ADCSequenceEnable(ADC0_BASE, 0);

          //
          // Trigger the sample sequence.
          //
          ADCProcessorTrigger(ADC0_BASE, 0);
          //
          // Wait until the sample sequence has completed.
          //
          while(!ADCIntStatus(ADC0_BASE, 0, false))
          {
          }

    //
    // 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);


    // Read the value from the ADC.
    //
    ADCSequenceDataGet(ADC0_BASE, 0, &ui32Value_adc);


    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
    CON_ui32Value_adc = (ui32Value_adc * 100) / 3.6;

    if(CON_Desired_V_Value  > CON_ui32Value_adc){

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


    if(CON_Desired_V_Value  < CON_ui32Value_adc){

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


    PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);

    while(1){}

}
 
Top