TI E2E 英文论坛海量技术问答的中文版全新上线,可点击相关论坛查看,或在站内搜索 “参考译文” 获取。

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28335: adc采样位置问题

Part Number: TMS320F28335

目前使用28335在做平均电流控制,如果我希望adc采样的位置在pwm的中间位置请问我该怎么设定

以下是我目前的代码

int main(void)
{
        InitSysCtrl();  
        InitEPwm1Gpio();
        InitEPwm2Gpio();
        Gpio_Setup();   
        InitEPwm1Example();

        DINT;          
        InitPieCtrl();  
        IER = 0x0000;
        IFR = 0x0000;
        InitPieVectTable();


        adc_init();
        AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
        EALLOW;
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; 
        EDIS;

        EALLOW;// This is needed to write to EALLOW protected registers
        PieVectTable.EPWM1_INT = &epwm1_isr;
        EDIS;

        EALLOW;
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  
        EDIS;

        IER |= M_INT3;

        // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
        PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

        // Enable global Interrupts and higher priority real-time debug events:
        EINT;   // Enable Global interrupt INTM
        ERTM;   // Enable Global realtime interrupt DBGM

        //for(;;){
         //   __asm(" NOP");

        while(1)
            {
            }

}

void adc_init(void)
{
EALLOW;
#if (CPU_FRQ_150MHZ)
#define ADC_MODCLK 0x3;
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2;
#endif
EDIS;

// Initialize ADC
InitAdc();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; //HSPCLK = SYSCLKOUT/2*HISPCP = 150/(2*3) = 25.0 MHz
EDIS;

AdcRegs.ADCTRL3.bit.SMODE_SEL = 1;
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xf;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 0x1; // Core clock driver Fclk = HSPCLK/(2*ADCCLKPS),但?ADCCLKPS=0?,Fclk = HSPCLK
AdcRegs.ADCTRL1.bit.CPS = 0x0; //ADCCLK = Fclk / (CPS+1)
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 15; // Set up ADC to perform (value+1) conversions for every SOC
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 0: Dual-sequencer mode, 1: Cascaded mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1;
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // ADCINA0 to ADCRESULT0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // ADCINA1 to ADCRESULT2

}
void read_adcresults(void)
{
    AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;           // Immediately reset sequencer to state CONV00
    AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;           // Software trigger
    while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);     // Interrupt request by INT_SEQ1 is enabled
    AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;         // Clear the SEQ1 interrupt flag bit
     p0= (AdcRegs.ADCRESULT0 >> 4);        //A0        // Convert 16 bits registers to 12 bits ADC results by right-shift 4 bits
     p1= (AdcRegs.ADCRESULT1 >> 4);        //B0
}
void InitEPwm1Example(void){
       // Setup TBCLK
       EPwm1Regs.TBPRD = 1500;                      // 100KHz
       EPwm1Regs.TBPHS.half.TBPHS =0;           // Phase is 0
       EPwm1Regs.TBCTR = 0;                           // ?基??器清零
       EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
       EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE;        // Disable phase loading
       EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;       // Clock ratio to SYSCLKOUT 除1
       EPwm1Regs.TBCTL.bit.CLKDIV = 0;          //1
       EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
       EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
       // Setup shadowing
       EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
       EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
       EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;  // Load on Zero
       EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

       // Set Dead-band
       EPwm1Regs.DBCTL.bit.OUT_MODE = 0x0;             // Enable Dead-band module
       EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;               // Active high
      // EPwm1Regs.DBFED = 30;
      // EPwm1Regs.DBRED = 30;

       // Set actions
       EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; // set actions for EPWM1A
       EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
       EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET ;
       EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

       // Interrupt where we will change the Compare Values
       EPwm1Regs.ETSEL.bit.SOCAEN = 1;              // Enable SOC on A group
       EPwm1Regs.ETSEL.bit.SOCASEL = 0x6;          // CTRU = CMPB
       EPwm1Regs.ETPS.bit.SOCAPRD = 0x1;
       //EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;    // Select INT on Zero event
       EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;      // Select INT on PRD event
       EPwm1Regs.ETSEL.bit.INTEN = 1;                 // Enable INT
       EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;            // Generate INT on 1ST event
       }
       
interrupt void epwm1_isr(void)
{
    read_adcresults();
     EPwm1Regs.CMPB=750;
}

我在epwm1_isr中读取adc的数值,这样感觉是在开关导通就采样而不是在中点采样