Part Number: TMS320F28335
Other Parts Discussed in Thread: SYSCONFIG
Hello all.
I would like to ask a question about my related work.
I am trying to build an SMPS circuit and instead of using an IC for generating a PWM and controlling the output voltage, I am using TMS320F28335 because I want to develop my embedded and software skills. My goal is to rectify the grid voltage as an input voltage and transform it with a Flyback transformer (KA5038) and having an output voltage of 14.7V and 2.7A of current.
According to my calculations, I need to have a PWM signal with around %23 duty cycle and I generated the code successfully from the examples of the TI.
Right now I want to control my output voltage with digital control. I bought a Voltage Sensor (MAX471) to sense the output voltage and from my understanding, I am going to put the output of the sensor (3.3V) to one of the ADC pins.
But I am stuck with the software part of the work. I would like to change the duty cycle ratio according to the output voltage and this time I couldn't find any specific examples to play on from the Resource Explorer.
I look forward to your suggestions and help.
Best of regards. ( I also added the code which is written in the Example_2833x_ePWMDeadBand )
#include "DSP2833x_Device.h"
// external function prototypes
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
extern void InitCpuTimers(void);
extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);
Uint16 PWM_Duty;
// Prototype statements for functions found within this file.
void Gpio_select(void);
void Setup_ePWM1A(void);
interrupt void cpu_timer0_isr(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
{
int counter=0; // binary counter for digital output
InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c
EALLOW;
SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog
EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64
DINT; // Disable all interrupts
Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output
// to 4 LEDs at Peripheral Explorer)
Setup_ePWM1A(); // init of ePWM1A
InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c
InitPieVectTable(); // default ISR's in PIE
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
InitCpuTimers(); // basic setup CPU Timer0, 1 and 2
ConfigCpuTimer(&CpuTimer0,150,100000);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0
// LED BLINK
while(1)
{
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
SysCtrlRegs.WDKEY = 0x55; // service WD #1
EDIS;
counter++;
if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;
else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;
else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;
else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;
else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;
}
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active
GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O
GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O
GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O
GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O
GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O
GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9
GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11
GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34
GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49
GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs
EDIS;
}
// PWM SETUP
void Setup_ePWM1A(void)
{
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode
EPwm1Regs.AQCTLA.all = 0x0006; // ZRO = set, PRD = clear
EPwm1Regs.TBPRD = 576; // 65KHz - PWM signal
EPwm1Regs.CMPA.half.CMPA = (Uint16)((0.23 * EPwm1Regs.TBPRD) * 2 ); // Set compare A value, duty cycle
EPwm1Regs.AQCTLA.bit.CAU = 1; //count up active
EPwm1Regs.AQCTLA.bit.CAD = 1; //count down active
EPwm1Regs.CMPCTL.all = 0x0002;
EPwm1Regs.TBCTL.bit.SWFSYNC = 1;
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
EALLOW;
SysCtrlRegs.WDKEY = 0xAA; // service WD #2
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//===========================================================================
// End of SourceCode.
//===========================================================================