Sie sind auf Seite 1von 14

#include "DSP28x_Project.

h"

// Device Headerfile and Examples Include File

#define w_dt
0.01570796327
// ADC start parameters
#if (CPU_FRQ_150MHZ)
// Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.
0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x1 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.
0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/2*ADC_CKPS = 25.0MHz/(1*
2) = 12.5MHz
#define ADC_SHCLK 0xf // S/H width in ADC module periods
= 16 ADC clocks
#define AVG
200 // Average sample limit
#define ZOFFSET
0x00 // Average Zero offset
#define BUF_SIZE 256 // Sample buffer size
#define BUF_SIZE1 256 // Sample buffer size
/*#define BUF_SIZE2 256 // Sample buffer size
#define BUF_SIZE3 256 // Sample buffer size */
int p=0;
float32 I_b=0.0;
float32 I_b1=0.0;
float32
float32
float32
float32

I_pv=0.0;
I_pv1=0.0;
I_pv_n=0.0;
I_pv_n1=0.0;

float32
float32
float32
float32
float32
float32
float32
float32
float32
float32

V_pv_n=0.0;
V_pv_n1=0.0;
Vr_n=1.0;
Vr_n1=0.0;
Vpvref=0.0;
Vpv_error = 0.0;
Vpv_error1 = 0.0;
Vpv_er_n1=0.0;
kp_vpv = 0.01;
ki_vpv = 0.04;

float32
float32
float32
float32
float32
float32
float32
float32
float32

ILstar = 0.0;
ILref = 0.0;
IL = 0.0;
ILer = 0.0;
IL_error = 0.0;
ILstarmax = 5.0;
ILstarmin = -7.0;
ki_iL = 0.08;
kp_iL = 0.01;

float32
float32
float32
float32
float32
float32

del_Ir=0.0;
del_I=0.0;
del_V=0.0;
y=0.0;
x=0.0;
dc_off;

float32 Dpv = 0.0;


float32 Dpv_limit = 0.0;
float32 kp_ipv =0.0001;
kp_ipv = 0.001;
float32 ki_ipv = 0.007;
l ki_ipv = 30.0e-6;

//2.1e-5 changed by sp to 0.05 :original


//2.2e-7changed by sp to 1.0e-6 :origina

float32 Io_ref=0.0;
float32 Ib_ref=0.0;
float32 Ib_error=0.0;
float32 Ib_er_n=0.0;
float32 Ib_er_n1=0.0;
float32 Db = 0.0;
float32 Db_limit = 0.0;
float32 kp_ib = 0.001;
float32 ki_ib = 40.0e-6;
float32 Ib_ref_limit = 0.0;
float32 Vdc_ref=200.0;
//High voltage DC refere
nce
float32 Vdc_ref1=0.0;
//temporary variable for
DC bus soft start
float32 V_dc=0.0;
float32 V_dc1=0.0;
float32 Vdc_error=0.0;
float32 Vdc_error1=0.0;
float32 Vdc_er_n=0.0;
float32 Vdc_er_n1=0.0;
float32 kp_vdc =5.0e-6;
//6.0e-7;1.2e-7 changed
by sp to 0.05 :original kp_ipv = 0.001
float32 ki_vdc =3.0e-5;
//3.5e-8 changed by sp to 1.0e-4 :origin
al kp_ipv = 1.0e-6
float32 V_out1=0.0;
//added by SP
float32 V_out2=0.0;
float32 V_out=0.0;
float32 I_inv1=0.0;
float32 I_inv=0.0;
float32 ch_offset;
//AC Voltage variable
float32 Vac_ref=0.0;
float32 V_ac=0.0;
float32 I_ac_ref=0.0;
float32 I_ac=0.0;
float32 Vac_error=0.0;
float32 I_ac1=0.0;
float32 Vac_er_n=0.0;
float32 Vac_er_n1=0.0;
float32 kp_vac = 0.0001;
float32 ki_vac = 0.005;
float32 Iac_error=0.0;
float32 Iac_error1=0.0;
float32 Iac_er_n=0.0;
float32 Iac_er_n1=0.0;
float32 kp_iac = 0.08;
float32 ki_iac = 0.005;
//float32 kp_iac =0.3; //1.0e-3;
//float32 ki_iac =0.3; //10.0e-3;
float32 V_alpha_r=0.0;

//must be always zero

//1.0e-3;1.0e-4
//2.0e-5;7.5e-3

float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32
float32

V_beta_r=0.0;
V_alpha=0.0;
V_beta=0.0;
Vd=0.0;
Vq=0.0;
Vd_r=0.0;
Vq_r=0.0;
Vd_error=0.0;
Vq_error=0.0;
kp_vd = 0.05;
ki_vd = 0.005;
kp_vq = 0.05;
ki_vq = 0.005;
Vd_er_n=0.0;
Vd_er_n1=0.0;
Vq_er_n=0.0;
Vq_er_n1=0.0;
Id_ref=0.0;
Iq_ref=0.0;
I_alpha_r=0.0;
I_beta_r=0.0;

float32
float32
float32
float32
float32
float32
float32
float32

sin = 0.0;
cos = 1.0;
mi = 0.8;
M = 0.0;
M_limit = 0.0;
counter=0.0;
counter1=0.0;
test2=0.0;

float32 t_s = 50e-6;


float32 dc_off;
float32 k = 0.05;
float32
ak
float32
float32
float32
float32
float32
float32

Vac_peak=150.0;

//for deciding output voltage pe

Vac_peak1=0.0;
Vac_p=0.0;
Vac_i=0.0;
Iac_p=0.0;
Iac_i=0.0;
Vac_i1 = 0.0;

//temp variable for soft start

float32 hi_ref = 0.0;


float32 lo_ref = 0.0;
Uint16 i;
Uint16 adc_int16;
Uint32 adc_int;
float32 adc_float;
float32 adc_float1;
//temp
float32
float32
Uint16
float32

dc_float1;
dc_float2;
dc_int16;
test=0.0;

float32
float32
float32
float32

Id_p=0.0;
Id_i=0.0;
Iq_p=0.0;
Iq_i=0.0;

float32 Id_i1=0.0;
float32 Iq_i1=0.0;
Uint16 i;
Uint16 PWMPRD_dc=5000, PWMcmp1=0, PWMcmp2=0, PWMcmp3=0,PWMPRD_ac=2500;
void Gpio_select(void);
interrupt void cpu_timer0_isr(void);
interrupt void cpu_timer1_isr(void);
void InitEPwm1(void);
void InitEPwm2(void);
void InitEPwm3(void);
void main(void)
{
InitSysCtrl();
// Specific clock setting for this example:
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
//EALLOW;
GpioCtrlRegs.GPAMUX2.all=0x00000000;
GpioCtrlRegs.GPADIR.all=0xFFFFFFFF;
GpioCtrlRegs.GPAQSEL2.all=0x00000000;
ier values
//GpioCtrlRegs.GPAPUD.all=0xFFFFFF000;
//EDIS;
GpioDataRegs.GPASET.all =0x00C00000;
GpioDataRegs.GPACLEAR.all =0x00C00000;

// GPIO PORTs as output


// Set GPIO input qualif

// For this example use the following configuration:


Gpio_select();
//
//
//

InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm3Gpio();
DINT; // disable CPU interrupts
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:


IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitAdc(); // For this example, init the ADC

// Specific ADC setup for this example:


AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 0x1;
// 1 Cascaded mode
AdcRegs.ADCTRL3.bit.SMODE_SEL = 0x1;
//Simultaneous sampling mode
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1;
AdcRegs.ADCMAXCONV.all = 0x0007;

// Setup continuous run

EALLOW; // This is needed to write to EALLOW protected registers


PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.XINT13 = &cpu_timer1_isr;
EDIS;
// This is needed to disable write to EALLOW protected registers
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
InitEPwm1();
InitEPwm2();
InitEPwm3();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
InitCpuTimers();

// For this example, only initialize the Cpu Timers

#if (CPU_FRQ_150MHZ)
ConfigCpuTimer(&CpuTimer0, 150, 50);
ConfigCpuTimer(&CpuTimer1, 150, 2.0e5);
#endif
CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit
= 0
CpuTimer1Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit
= 0
// Step 5. User specific code, enable interrupts:
// to CPU-Timer 2:
IER |= M_INT1;
// M_INT1 = 0x0001
IER |= M_INT13;
//M_INT13 = 0x1000
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// interrupt generated by timer0
is map on line 1 , INT7 of pie vector table
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
for(;;);
}

// ********************************************** MPPT Algorithm ***************


***********************************************************
interrupt void cpu_timer1_isr(void)
{
del_I = I_pv_n1 - I_pv_n;
del_V = V_pv_n1 - V_pv_n;
del_Vr = 0.15;
if(del_I==0)
{
if(del_V==0)
Vr_n1 = Vr_n;
else
{
if(del_V > 0)
Vr_n1 = Vr_n + del_Vr;
else
Vr_n1 = Vr_n - del_Vr;
}
}
else
{
y=(del_I/del_V);
x=(-I_pv_n/V_pv_n);
if(y==x)
Vr_n1=Vr_n;
else
{
if(y>x)
Vr_n1 = Vr_n + del_Vr;
else
Vr_n1 = Vr_n - del_Vr;
}
};
//

Ipv_ref = Ir_n1;
I_pv_n = I_pv_n1;
V_pv_n = V_pv_n1;
Vr_n = Vr_n1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}
// ------------------------------------------------------------- controller code
------------------------------------------------------------interrupt void cpu_timer0_isr(void) // 50 uS
{
// Start SEQ1 (SOFTWARE START TRIGGER - DIPANKAR)
AdcRegs.ADCTRL2.all = 0x2000;
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for
interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT0;
A0 conversion for zero voltage channel offset sense
adc_float = adc_int;
adc_float1 = (adc_float*3.0)/4095.0;

//ADC Channel

ch_offset = adc_float1;
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wai
t for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT1;
adc_float1 = adc_int;
adc_float1 = (adc_float1*3.0)/4095.0;
V_pv_n1 = (adc_float1)/(0.05);
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {}
// Wait for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
//ADC Channel B0 conversion for PV Current sense
adc_int = AdcMirror.ADCRESULT2;
adc_float = adc_int;
adc_float1 = (adc_float-ch_offset)*(3.0/4095.0);
I_pv_n1 = (adc_float1/(0.25))*(1000.0/(56.0*1.0));
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wai
t for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT3;;
adc_float = adc_int;
adc_float1 = (adc_float)*(3.0/4095.0);
V_dc1 = adc_float1/(15.0/4000.0);
V_dc = V_dc1;
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for
interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
//ADC Ch
annel B1 conversion for DC offset sense used in circuit
adc_int = AdcMirror.ADCRESULT4;
adc_float = adc_int;
dc_off = (adc_float-ch_offset)*(3.0/4096.0);
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wa
it for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT5;
adc_float = adc_int;
adc_float1 = adc_float*(3.0/4096.0);
IL=((adc_float1-dc_off)-ch_offset);
IL = (IL/0.25)*(1000.0/(56.0*1.0));//calculatio
n for obtaining exact current; no of turns needs to be adjusted.
//Added for AC voltage and current calculation
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for
interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT6;
adc_float = adc_int;
adc_float1 = adc_float*(3.0/4096.0);
V_out1=adc_float1-dc_off;
V_out =((V_out1)*(4000.0/12.0)+2.5);
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wai
t for interrupt

AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
adc_int = AdcMirror.ADCRESULT7;
adc_float = adc_int;
adc_float1 = adc_float*(3.0/4096.0);
I_inv1=((adc_float1-dc_off)-ch_offset);
I_inv=(I_inv1)*(10.4/10.0)*(1000.0/56.0);
I_ac=I_inv-0.15;
//calculation fo
r obtaining exact current; no of turns needs to be adjusted.
// ********************************************** Battery-only mode voltage refe
rence **********************************************
// Vcref = 36;
// ................................................. PV voltage reference select
ion ......................................................
if (Vr_n1>= 41)
{Vr_n1 = 41;}
elseif (Vr_n1<= 25)
{Vr_n1 = 25;}
else
{Vr_n1 = Vr_n1;}
if (I_pv_n1>0)
{Vpvref = Vr_n1;}
else
{ Vpvref = 36; }
// ******************************************* Inductor current reference select
ion **************************************************
Vpv_er_n1 = Vpvref-V_pv_n1;
Vpv_error = Vpv_error1 + (ki_vpv*Vpv_er_n1);
if (Vpv_error > 15.0)
{
Vpv_error = 15.0;
}
else if (Vpv_error < -15.0)
{
Vpv_error = -15.0;
}
else
{
Vpv_error = Vpv_error;
}
ILstar = (kp_vpv*Vpv_er_n1) + Vpv_error;
Vpv_error1 = Vpv_error;
// ................................................. Limit on Inductor current r
eference .................................................
if (ILstar > ILstarmax)
{
ILref = ILstarmax;

}
else if (ILstar < ILstarmin)
{
ILref = ILstarmin;
}
else
{
ILref = ILstar;
}
ILer = ILref - IL;
IL_error= ILer1 + (ki_iL*ILer);
if (IL_error > 0.7)
{
IL_error = 0.7;
}
else if (IL_error < 0.0)
{
IL_error = 0.0;
}
else
{
IL_error = IL_error;
}

//edited by SP for test

Dpv =(kp_iL*ILer) + IL_error;


if (Dpv > 0.70)
{
Dpv_limit = 0.70;
}
else if (Dpv < 0.1)
//edited by SP for test
{
Dpv_limit = 0.1;
}
else
{
Dpv_limit = Dpv;
}
PWMcmp1 = Dpv_limit*PWMPRD_dc;
EPwm1Regs.CMPA.half.CMPA = PWMcmp1;
//--------------------------------------------Inverter Voltage Control-------------------------------------//
kp_vq=kp_vd;
ki_vq=ki_vd;
sin = sin + cos*w_dt;
cos = cos - sin*w_dt;
//----------------------------------------------Inverter soft start---------------------------------//

if(Vac_peak<=Vac_peak1)
{
Vac_peak1=Vac_peak;

}
else
{
Vac_peak1=Vac_peak1+0.001;
}
Vac_ref = Vac_peak1*sin;
// ************************************************* dq based control **********
************************************************
V_alpha_r = Vac_ref;
V_beta_r = 0.0;
Vd_r = cos*V_alpha_r + sin*V_beta_r;
Vq_r = -sin*V_alpha_r + cos*V_beta_r;
V_alpha =V_out;
V_beta = 0.0;
Vd = cos*V_alpha + sin*V_beta;
Vq = -sin*V_alpha + cos*V_beta;
Vd_er_n1 = Vd_r - Vd;
Id_p=kp_vd*Vd_er_n1;
Id_i=Id_i1+(ki_vd*Vd_er_n1);
if(Id_i>8.0)
{Id_i=8.0;Id_i1=8.0;}
else if(Id_i<-8.0)
{Id_i=-8.0;Id_i1=-8.0;}
else
{Id_i=Id_i;}
Id_ref=Id_p+Id_i;
Vq_er_n1 = Vq_r - Vq;
Iq_p=kp_vq*Vq_er_n1;
Iq_i=Iq_i1+(ki_vq*Vq_er_n1);
if(Iq_i>8.0)
{Iq_i=8.0;Iq_i1=8.0;}
else if(Iq_i<-8.0)
{Iq_i=-8.0;Iq_i1=-8.0;}
else
{Iq_i=Iq_i;}
Iq_ref=Iq_p+Iq_i;
I_alpha_r = cos*Id_ref - sin*Iq_ref;
I_beta_r = sin*Id_ref + cos*Iq_ref;
I_ac_ref = I_alpha_r;
if(I_ac_ref>8.0)
{I_ac_ref=8.0;}
else if(Iac_i<-8.0)
{I_ac_ref=-8.0;}
else
{I_ac_ref=I_ac_ref;}

Iac_er_n1 = I_ac_ref-I_ac;
Iac_error=Iac_error1+(ki_iac*Iac_er_n1);
if(Iac_error>0.9)
{
Iac_error=0.9;
Iac_error1=0.9;}
else if(Iac_error<-0.9)
{
Iac_error=-0.9;
Iac_error1=-0.9;}
else
{Iac_error=Iac_error;}
M = (kp_iac*Iac_er_n1)+Iac_error;
// -------------------------------------------------------------------- PI based
control +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*

Vd_er_n1 = Vac_ref - V_out;


Id_p=kp_vd*Vd_er_n1;
Id_i=Id_i1+(ki_vd*Vd_er_n1);
if(Id_i>8.0)
{Id_i=8.0;Id_i1=8.0;}
else if(Id_i<-8.0)
{Id_i=-8.0;Id_i1=-8.0;}
else
{Id_i=Id_i;}
Id_ref=Id_p+Id_i;
I_ac_ref = Id_ref;
if(I_ac_ref>8.0)
{I_ac_ref=8.0;}
else if(Iac_i<-8.0)
{I_ac_ref=-8.0;}
else
{I_ac_ref=I_ac_ref;}
Iac_er_n1 = I_ac_ref-I_ac;
Iac_error=Iac_error1+(ki_iac*Iac_er_n1);
if(Iac_error>0.9)
{
Iac_error=0.9;
Iac_error1=0.9;}
else if(Iac_error<-0.9)
{
Iac_error=-0.9;
Iac_error1=-0.9;}
else
{Iac_error=Iac_error;}

M = (kp_iac*Iac_er_n1)+Iac_error;
*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SPWM -------------------------------------------------------------------if (M > 0.9)
{M_limit = 0.9;}
else if( M < -0.9)
{M_limit =-0.9;}
else

{M_limit = M;}
//M_limit=0.5*sin;
PWMcmp2 = (M_limit)*(PWMPRD_ac/2) + (PWMPRD_ac/2);
PWMcmp3 = -(M_limit)*(PWMPRD_ac/2i) + (PWMPRD_ac/2);
EPwm2Regs.CMPA.half.CMPA = PWMcmp2;
EPwm3Regs.CMPA.half.CMPA = PWMcmp3;
Iac_error1=Iac_error;
Vac_i1=Vac_i;
Id_i1=Id_i;
Iq_i1=Iq_i;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
void Setup_ePWM1(void)
{
EPwm1Regs.TBCTL.bit.CLKDIV = 0;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1;
EPwm1Regs.TBCTL.bit.CTRMODE = 0;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0x0;
mode
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0x2;
or CTR = 0 or CTR = PRD */
EPwm1Regs.AQCTLA.all = 0x0024;

// CLKDIV = 1
// HSPCLKDIV = 2
// up count mode
// enable shadow
// Change CMPA f
// set ePWM1A on CMPA up

// clear ePWM1A on PRD


EPwm1Regs.TBPRD = PWMPRD_dc;
// 1KHz - PWM si
gnal
EPwm1Regs.CMPA.half.CMPA = 0; // 50% duty cycle first PWMPRD_d
c*dutyratio
EPwm1Regs.DBRED = 750/4;
croseconds delay 750/2
EPwm1Regs.DBFED = 750/4;
ising and falling edge
EPwm1Regs.DBCTL.bit.OUT_MODE = 3;
EPwm1Regs.DBCTL.bit.POLSEL = 2;
at ePWM1B
EPwm1Regs.DBCTL.bit.IN_MODE = 0;
ED & FED
}

// ePWM1A = RED
// S3=1 inverted signal

void Setup_ePWM2(void)
{
EPwm2Regs.TBCTL.bit.CLKDIV = 0;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1;
EPwm2Regs.TBCTL.bit.CTRMODE = 2;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = 0x0;
mode
EPwm2Regs.CMPCTL.bit.LOADAMODE = 0x2;
or CTR = 0 or CTR = PRD */

// CLKDIV = 1
// HSPCLKDIV = 2
// up - down mode
// enable shadow

EPwm2Regs.AQCTLA.all = 0x0060;
up// clear ePWM1A on CMPD

// 10 mi
// for r

// ePWM1A = source for R

// Change CMPA f
// // set ePWM1A on CMPA

EPwm2Regs.TBPRD = PWMPRD_ac;

// 1KHz - PWM si

gnal
EPwm2Regs.CMPA.half.CMPA = 0; // 50% duty cycle first PWMPRD_d
c*dutyratio
EPwm2Regs.DBRED = 0;

// 10 microsecon

EPwm2Regs.DBFED = 0;

// for rising an

ds delay
d falling edge
EPwm2Regs.DBCTL.bit.OUT_MODE = 3;
EPwm2Regs.DBCTL.bit.POLSEL = 2;

// ePWM1A = RED
// S3=1 inverted signal

EPwm2Regs.DBCTL.bit.IN_MODE = 0;

// ePWM1A = source for R

at ePWM1B
ED & FED
}
void Setup_ePWM3(void)
{
EPwm3Regs.TBCTL.bit.CLKDIV = 0;
EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1;
EPwm3Regs.TBCTL.bit.CTRMODE = 2;
EPwm3Regs.CMPCTL.bit.SHDWAMODE = 0x0;
mode
EPwm3Regs.CMPCTL.bit.LOADAMODE = 0x2;
or CTR = 0 or CTR = PRD
EPwm3Regs.AQCTLA.all = 0x0060;
// clear ePWM1A on CMPD
EPwm3Regs.TBPRD = PWMPRD_ac;

// CLKDIV = 1
// HSPCLKDIV = 2
// up - down mode
// enable shadow
// Change CMPA f
// set ePWM1A on CMPA up
// 1KHz - PWM si

gnal
EPwm3Regs.CMPA.half.CMPA = 0; // 50% duty cycle first PWMPRD_d
c*dutyratio
EPwm3Regs.DBRED = 0;

// 10 microsecon

EPwm3Regs.DBFED = 0;

// for rising an

ds delay
d falling edge
EPwm3Regs.DBCTL.bit.OUT_MODE = 3;
EPwm3Regs.DBCTL.bit.POLSEL = 2;

// ePWM1A = RED
// S3=1 inverted signal

EPwm3Regs.DBCTL.bit.IN_MODE = 0;

// ePWM1A = source for R

at ePWM1B
ED & FED
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // GPIO15 ... GPIO1 = General Pu
ropse I/O;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;
// GPIO0 = epwm1A
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;
// GPIO1 = epwm1B
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;
// GPIO2 = epwm2A
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;
// GPIO3 = epwm2B
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1;
// GPIO4 = epwm3A
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 1;
// GPIO5 = epwm3B

GpioCtrlRegs.GPAMUX2.all
urpose I/O
GpioCtrlRegs.GPBMUX1.all
urpose I/O
GpioCtrlRegs.GPBMUX2.all
urpose I/O
GpioCtrlRegs.GPCMUX1.all
urpose I/O
GpioCtrlRegs.GPCMUX2.all
urpose I/O

= 0x00000000; // GPIO31 ... GPIO16 = General P


= 0x00000000; // GPIO47 ... GPIO32 = General P
= 0x00000000; // GPIO63 ... GPIO48 = General P
= 0x00000000; // GPIO79 ... GPIO64 = General P
= 0x00000000; // GPIO87 ... GPIO80 = General P

GpioCtrlRegs.GPADIR.all = 0x0000000; //GPIO 0,9,11 = output 0x00000A01


GpioCtrlRegs.GPBDIR.all = 0x0000; //0x00020004
GpioCtrlRegs.GPAPUD.bit.GPIO0
GpioCtrlRegs.GPAPUD.bit.GPIO1
GpioCtrlRegs.GPAPUD.bit.GPIO2
GpioCtrlRegs.GPAPUD.bit.GPIO3
GpioCtrlRegs.GPAPUD.bit.GPIO4
GpioCtrlRegs.GPAPUD.bit.GPIO5
EDIS;

=
=
=
=
=
=

0;
0;
0;
0;
0;
0;

//
//
//
//
//
//

Enable
Enable
Enable
Enable
Enable
Enable

pullup
pullup
pullup
pullup
pullup
pullup

on
on
on
on
on
on

GPIO0
GPIO1
GPIO2
GPIO3
GPIO4
GPIO5

}
// **********************************************************
***********************************************************

THE END

Das könnte Ihnen auch gefallen