?? convert_assembak.c
字號:
// Compare action control. Action that takes place
// on a cmpare event
// output pin 2 CMPR1 - active high
// output pin 1 CMPR1 - active low
// output pin 4 CMPR2 - active high
// output pin 3 CMPR2 - active low
// output pin 6 CMPR3 - force high
// output pin 5 CMPR3 - active low
EvaRegs.ACTRA.all = 0x0FC9; ////0x0D69;
EvaRegs.DBTCONA.all = 0x0AF8; // 2us deadband
EvaRegs.COMCONA.all = 0xA6E0;
EvaRegs.EVAIMRA .all =0x0280;//Enable T1UFINT,T1CINT
EvaRegs.EVAIMRB.bit.T2UFINT =1; //Enable T2UFINT
EvaRegs.EVAIFRA .all =0xFFFF;
EvaRegs.EVAIFRB .all =0xFFFF;
}
void init_evb()
{
// EVB Configure T3PWM, T4PWM and PWM7-PWM12
// Step 1 - Initialize the Timers
// Initialize EVB Timer3
// Timer3 controls T3PWM and PWM7-12
EvbRegs.T3PR = 0xFFFF; // Timer3 period
EvbRegs.T3CMPR = 0x3C00; // Timer3 compare
EvbRegs.T3CNT = 0x0000; // Timer3 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvbRegs.T3CON.all = 0x1042;
// Initialize EVB Timer4
// Timer4 controls T4PWM
EvbRegs.T4PR = 0x00FF; // Timer4 period
EvbRegs.T4CMPR = 0x0030; // Timer4 compare
EvbRegs.T4CNT = 0x0000; // Timer4 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvbRegs.T4CON.all = 0x1042;
// Setup T3PWM and T4PWM
// Drive T3/T4 PWM by compare logic
EvbRegs.GPTCONB.bit.TCMPOE = 1;
// Polarity of GP Timer 3 Compare = Active low
EvbRegs.GPTCONB.bit.T3PIN = 1;
// Polarity of GP Timer 4 Compare = Active high
EvbRegs.GPTCONB.bit.T4PIN = 2;
// Enable compare for PWM7-PWM12
EvbRegs.CMPR4 = 0x0C00;
EvbRegs.CMPR5 = 0x3C00;
EvbRegs.CMPR6 = 0xFC00;
// Compare action control. Action that takes place
// on a cmpare event
// output pin 1 CMPR4 - active high
// output pin 2 CMPR4 - active low
// output pin 3 CMPR5 - active high
// output pin 4 CMPR5 - active low
// output pin 5 CMPR6 - active high
// output pin 6 CMPR6 - active low
EvbRegs.ACTRB.all = 0x0666;
EvbRegs.DBTCONB.all = 0x0000; // Disable deadband
EvbRegs.COMCONB.all = 0xA600;
}
void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
// To powerup the ADC the ADCENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap and reference circuitry.
// After a 5ms delay the rest of the ADC can be powered up. After ADC
// powerup, another 20us delay is required before performing the first
// ADC conversion. Please note that for the delay function below to
// operate correctly the CPU_CLOCK_SPEED define statement in the
// DSP28_Examples.h file must contain the correct CPU clock period in
// nanoseconds. For example:
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry
DELAY_US(ADC_usDELAY); // Delay before powering up rest of ADC
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
DELAY_US(ADC_usDELAY2); // Delay after powering up ADC
}
//ISR
interrupt void T1PINTIsr(void)
{
if (step<99)
{
//CMPR_LAST=sinv[step]*M+3750;
EvaRegs.CMPR1 = CMPR_LAST;
EvaRegs.CMPR2 = CMPR_LAST-325+DIF; //160 is used for generating PWM3,PWM4 2us deadband
EvaRegs.CMPR3 = CMPR_LAST-DIF;
}
else
{
//CMPR_LAST=3750-M*sinv[step-100];
EvaRegs.CMPR1 = CMPR_LAST;
if ((CMPR_LAST-325+DIF)>0)
{EvaRegs.CMPR2 = CMPR_LAST-325+DIF;}
else
{EvaRegs.CMPR2 =0;}
EvaRegs.CMPR3 = CMPR_LAST-DIF;
}
EvaRegs.EVAIFRA .all =0x0080;
PieCtrlRegs.PIEACK.all=0x0002; // Issue PIE ack
}
interrupt void T1UFINTIsr(void)
{
//extern void DSP28x_WaveCon(void);
if ((CMPR_LAST1>1875)&(CMPR_LAST1<5625))
{
//use T2 for CM current collection
EvaRegs.T2CNT = 0x0000; // Timer2 counter
EvaRegs.T2PR = 7550-(CMPR_LAST1>>1); // Timer2 period,7605=7500+105,7500---period,105---1.4us
CMPR_LAST=EvaRegs.T2CNT;
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x4842;
GpioDataRegs.GPFDAT.bit.GPIOF10 =0;
//ADC for CM current
AdcRegs.ADCTRL2.all = 0x4900;
AdcRegs.ADCMAXCONV.all=0xF;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x8;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x8;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x8;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x8;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x8;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x8;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x8;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x8;
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x8;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x8;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x8;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x8;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x8;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x8;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x8;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x8;
}
//claculate the energy of the CM current
for(BX=2;BX<14;BX++)
{
CM[BX]=((CM[BX-2]+CM[BX-1]+CM[BX+1]+CM[BX+2])>>2);
}
for(BX=0;BX<16;BX++)
{
CM_energy=CM_energy+((CM[BX]*CM[BX])>>10);
if (CM[BX]>CM_largest)
{CM_largest=CM[BX];}
else if (CM[BX]>CM_larger)
{CM_larger=CM[BX];}
}
CM_energy=CM_energy+((CM_largest*CM_largest+CM_larger*CM_larger)<<1);
energy_step=energy_step-1;
CM_largest=CM_larger=0;
//put the value to the CMPR for the SIN output
//WaveCon();
if (AX>1870)
{AX=1870;
}
if (step<99)
{
CMPR_LAST=sinv[step]*M+3750;
EvaRegs.CMPR1 = CMPR_LAST;
EvaRegs.CMPR2 = CMPR_LAST-325+DIF; //320 is used for generating PWM3,PWM4 2us deadband
EvaRegs.CMPR3 = CMPR_LAST+DIF;
CMPR_LAST1=sinv[step+1]*M+3750;
}
else
{
CMPR_LAST= 3750-M*sinv[step-100];
EvaRegs.CMPR1=CMPR_LAST;
if ((CMPR_LAST-325+DIF)>0)
{EvaRegs.CMPR2 = CMPR_LAST-325+DIF;}
else
{EvaRegs.CMPR2 =0;}
EvaRegs.CMPR3 = CMPR_LAST+DIF;
CMPR_LAST1= 3750-M*sinv[step-99];
}
if (step+1>199)
{step=0;}
else
{step=step+1;}
EvaRegs.EVAIFRA .all =0x0200;
PieCtrlRegs.PIEACK.all=0x0002; // Issue PIE ack
}
interrupt void T2UFINTIsr(void)
{
GpioDataRegs.GPFDAT.bit.GPIOF10 =1;
EvaRegs.T2CON.all = 0x4802;
EvaRegs.EVAIFRB.bit.T2UFINT =1;
PieCtrlRegs.PIEACK.all=0x0004; // Issue PIE ack
}
interrupt void ADCINTIsr(void)
{
//get ADC result
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
// Software wait = (HISPCP*2) * (ADCCLKPS*2) * (CPS+1) cycles
// = (1*2) * (3*2) * (0+1) = 12 cycles
asm(" RPT #11 || NOP");
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
CM[0] =((AdcRegs.ADCRESULT0>>4) );
CM[1] =((AdcRegs.ADCRESULT1>>4) );
CM[2] =((AdcRegs.ADCRESULT2>>4) );
CM[3] =((AdcRegs.ADCRESULT3>>4) );
CM[4] =((AdcRegs.ADCRESULT4>>4) );
CM[5] =((AdcRegs.ADCRESULT5>>4) );
CM[6] =((AdcRegs.ADCRESULT6>>4) );
CM[7] =((AdcRegs.ADCRESULT7>>4) );
CM[8] =((AdcRegs.ADCRESULT8>>4) );
CM[9] =((AdcRegs.ADCRESULT9>>4) );
CM[10] =((AdcRegs.ADCRESULT10>>4) );
CM[11] =((AdcRegs.ADCRESULT11>>4) );
CM[12] =((AdcRegs.ADCRESULT12>>4) );
CM[13] =((AdcRegs.ADCRESULT13>>4) );
CM[14] =((AdcRegs.ADCRESULT14>>4) );
CM[15] =((AdcRegs.ADCRESULT15>>4) );
//AdcRegs.ADCST .bit .INT_SEQ1_CLR =1;
PieCtrlRegs.PIEACK.all=0x0001; // Issue PIE ack
}
//===========================================================================
// No more.
//===========================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -