Part Number:TMS320F28069
ADC采样结
//ADC初始化 ChSel[0] = 0x0; // ADC ChSel[1] = 0x1; // ADC ChSel[2] = 0x2; // ADC ChSel[5] = 0x3; // ADC ChSel[4] = 0x4; // ADC ChSel[5] = 0x5; // ADC ChSel[6] = 0x6; // ADC ChSel[7] = 0x7; // ADCChSel[8] = 0x8; // ADCChSel[9] = 0x9; // ADCChSel[10] = 0xA; // ADCChSel[11] = 0xB; // ADCChSel[12] = 0XC; // ADC TrigSel[0]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[1]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[2]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[3]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[4]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[5]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[6]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[7]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[8]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socATrigSel[9]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[10]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[11]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA TrigSel[12]= ADCTRIG_EPWM1_SOCA; //通道的触发源epwm1socA EALLOW; ADC_SOC_CNF(ChSel,TrigSel,ACQPS,12,0);//ADC初始化//ePWM初始化PWM_1ch_CNF(1,SYS_CLOCK/EPWM_FS,1,0);PWM_1ch_CNF(2,SYS_CLOCK/EPWM_FS,1,0);PWM_ComplPairDB_CNF(6,SYS_CLOCK/EPWM_FS, 1, 0);PWM_ComplPairDB_CNF(7,SYS_CLOCK/EPWM_FS, 0, 0);PWM_ComplPairDB_UpdateDB(6,100,100);//配置死区时间PWM_ComplPairDB_UpdateDB(7,100,100);//DPLib初始化 DPL_Init(); PWMDRV_1ch_Duty1 = &Duty_Boost1;//建立通道链接变量 PWMDRV_1ch_Duty2 = &Duty_Boost2; PWMDRV_ComplPairDB_Duty6 = &Duty; PWMDRV_ComplPairDB_Duty7 = &Duty; ADCDRV_1ch_Rlt4 = &ADC1Out;ADCDRV_8ch_RltPtrA = &RltA;ADCDRV_8ch_RltPtrB = &RltB;ADCDRV_8ch_RltPtrC = &RltC;ADCDRV_8ch_RltPtrD = &RltD;ADCDRV_8ch_RltPtrE = &RltE;ADCDRV_8ch_RltPtrF = &RltF;ADCDRV_8ch_RltPtrG = &RltG;ADCDRV_8ch_RltPtrH = &RltH; ADCDRV_4ch_RltPtrA=&Rlta; ADCDRV_4ch_RltPtrB=&Rltb; ADCDRV_4ch_RltPtrC=&Rltc; ADCDRV_4ch_RltPtrD=&Rltd; void ADC_SOC_CNF(int ChSel[], int Trigsel[], int ACQPS[], int IntChSel, int mode) { EALLOW; AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power up band gap AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power up reference AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power up rest of ADC AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC DSP28x_usDelay(1000); // Delay before converting ADC channels AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcRegs.ADCSOC0CTL.bit.ACQPS = ACQPS[0]; AdcRegs.ADCSOC1CTL.bit.ACQPS = ACQPS[1]; AdcRegs.ADCSOC2CTL.bit.ACQPS = ACQPS[2]; AdcRegs.ADCSOC3CTL.bit.ACQPS = ACQPS[3]; AdcRegs.ADCSOC4CTL.bit.ACQPS = ACQPS[4]; AdcRegs.ADCSOC5CTL.bit.ACQPS = ACQPS[5]; AdcRegs.ADCSOC6CTL.bit.ACQPS = ACQPS[6]; AdcRegs.ADCSOC7CTL.bit.ACQPS = ACQPS[7]; AdcRegs.ADCSOC8CTL.bit.ACQPS = ACQPS[8]; AdcRegs.ADCSOC9CTL.bit.ACQPS = ACQPS[9]; AdcRegs.ADCSOC10CTL.bit.ACQPS = ACQPS[10]; AdcRegs.ADCSOC11CTL.bit.ACQPS = ACQPS[11]; AdcRegs.ADCSOC12CTL.bit.ACQPS = ACQPS[12]; AdcRegs.ADCSOC13CTL.bit.ACQPS = ACQPS[13]; AdcRegs.ADCSOC14CTL.bit.ACQPS = ACQPS[14]; AdcRegs.ADCSOC15CTL.bit.ACQPS = ACQPS[15]; AdcRegs.INTSEL1N2.bit.INT1SEL = IntChSel; // IntChSel causes ADCInterrupt 1 if (mode == 0){ // Start-Stop conversion mode AdcRegs.ADCINTFLG.bit.ADCINT1 = 0; // clear interrupt flag for ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; // clear ADCINT1 flag to begin a new set of conversions AdcRegs.ADCINTSOCSEL1.all = 0x0000; // No ADCInterrupt will trigger SOCx AdcRegs.ADCINTSOCSEL2.all = 0x0000; } if (mode == 1){ // Continuous conversion mode AdcRegs.INTSEL1N2.bit.INT1CONT = 1; // set ADCInterrupt 1 to auto clr AdcRegs.ADCINTSOCSEL1.all = 0xFF; // ADCInterrupt 1 will trigger SOCx, TrigSel is ignored AdcRegs.ADCINTSOCSEL2.all = 0xFF; } if (mode == 2){ // CLA mode, Start Stop ADC with auto clr ADC Flag AdcRegs.ADCINTFLG.bit.ADCINT1 = 0; // clear interrupt flag for ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 1; // set ADCInterrupt 1 to auto clr AdcRegs.ADCINTSOCSEL1.all = 0x0000; // No ADCInterrupt will trigger SOCx AdcRegs.ADCINTSOCSEL2.all = 0x0000; } if (IntChSel <= 15) AdcRegs.INTSEL1N2.bit.INT1E = 1; // enable ADC interrupt 1 else AdcRegs.INTSEL1N2.bit.INT1E = 0; // disable the ADC interrupt 1 // Select the channel to be converted when SOCx is received AdcRegs.ADCSOC0CTL.bit.CHSEL = ChSel[0]; AdcRegs.ADCSOC1CTL.bit.CHSEL = ChSel[1]; AdcRegs.ADCSOC2CTL.bit.CHSEL = ChSel[2]; AdcRegs.ADCSOC3CTL.bit.CHSEL = ChSel[3]; AdcRegs.ADCSOC4CTL.bit.CHSEL = ChSel[4]; AdcRegs.ADCSOC5CTL.bit.CHSEL = ChSel[5]; AdcRegs.ADCSOC6CTL.bit.CHSEL = ChSel[6]; AdcRegs.ADCSOC7CTL.bit.CHSEL = ChSel[7]; AdcRegs.ADCSOC8CTL.bit.CHSEL = ChSel[8]; AdcRegs.ADCSOC9CTL.bit.CHSEL = ChSel[9]; AdcRegs.ADCSOC10CTL.bit.CHSEL = ChSel[10]; AdcRegs.ADCSOC11CTL.bit.CHSEL = ChSel[11]; AdcRegs.ADCSOC12CTL.bit.CHSEL = ChSel[12]; AdcRegs.ADCSOC13CTL.bit.CHSEL = ChSel[13]; AdcRegs.ADCSOC14CTL.bit.CHSEL = ChSel[14]; AdcRegs.ADCSOC15CTL.bit.CHSEL = ChSel[15]; AdcRegs.ADCSOC0CTL.bit.TRIGSEL = Trigsel[0]; AdcRegs.ADCSOC1CTL.bit.TRIGSEL = Trigsel[1]; AdcRegs.ADCSOC2CTL.bit.TRIGSEL = Trigsel[2]; AdcRegs.ADCSOC3CTL.bit.TRIGSEL = Trigsel[3]; AdcRegs.ADCSOC4CTL.bit.TRIGSEL = Trigsel[4]; AdcRegs.ADCSOC5CTL.bit.TRIGSEL = Trigsel[5]; AdcRegs.ADCSOC6CTL.bit.TRIGSEL = Trigsel[6]; AdcRegs.ADCSOC7CTL.bit.TRIGSEL = Trigsel[7]; AdcRegs.ADCSOC8CTL.bit.TRIGSEL = Trigsel[8]; AdcRegs.ADCSOC9CTL.bit.TRIGSEL = Trigsel[9]; AdcRegs.ADCSOC10CTL.bit.TRIGSEL = Trigsel[10]; AdcRegs.ADCSOC11CTL.bit.TRIGSEL = Trigsel[11]; AdcRegs.ADCSOC12CTL.bit.TRIGSEL = Trigsel[12]; AdcRegs.ADCSOC13CTL.bit.TRIGSEL = Trigsel[13]; AdcRegs.ADCSOC14CTL.bit.TRIGSEL = Trigsel[14]; AdcRegs.ADCSOC15CTL.bit.TRIGSEL = Trigsel[15]; EDIS; AdcRegs.ADCSOCFRC1.all = 0xFFFF; // kick-start ADC }
果寄存器和SOC通道错位,SOC0通道的结果在ADCRESULT1里,SOC1在ADCRESULT2 里,以此类推,这是什么原因?
? ?:
结果寄存器 ADCRESULT0 的数值不知道是哪一路的,ADCRESULT1的结果读到的是ADCINA0的也就是SOC0 的 ,ADCRESULT2的结果读到的是ADCINA1的也就是SOC1的 ,这很奇怪 ,请问可能是什么原因引起的呢?