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.

TMS320F28377D: F28377 ADC多路采样结果值输出异常

Part Number: TMS320F28377D

问题描述:我目前配置了2路ADC转换,分别为ADCIN0和ADCIN1,由SOC0和SOC1进行转换,并且使用EPWM1触发转换,但是给ADCIN0给1.2V电压,居然结果寄存器ADCRESULT0和ADCRESULT1都为1.2V;如果给ADCIN1给1.2V电压,居然结果寄存器ADCRESULT0和ADCRESULT1都为0V。

一下是我ADC的配置程序以及ADC中断函数。

目前没有找到原因,希望大家能帮我这个新手看看呐。谢谢大家!

void ADC_INIT()
{
//
// Map ISR functions
//
EALLOW;
PieVectTable.ADCA1_INT = &adca1_isr; //function for ADCA interrupt 1
EDIS;

//
// Configure the ADC and power it up
//
ConfigureADC();

//
// Setup the ADC for ePWM triggered conversions on temperature sensor
//
SetupADCEpwm();

//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT1; //Enable group 1 interrupts
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

//
// enable PIE interrupt
//
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;

//
// sync ePWM
//
//EALLOW;
//CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
}


void ConfigureADC(void)
{
EALLOW;

//
//write configurations
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 0; //ADCCLK = SYSCLK/1
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);//工作在12bit下,转换时间是10.5个ADCCLK

//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;//在转换完成后触发ADC采样中断

//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;

//
//delay for 1ms to allow ADC time to power up
//
DELAY_US(1000);

EDIS;
}

//
// SetupADCEpwm - Configure ADC EPWM acquisition window and trigger
//
void SetupADCEpwm()
{
Uint16 acqps;

//determine minimum acquisition window (in SYSCLKS) based on resolution
if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION){
acqps = 14; //140ns
}
else { //resolution is 16-bit
acqps = 63; //630ns
}

//
//Select the channels to convert and end of conversion flag
//
EALLOW;
AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; //SOC0 will convert internal connection ADCIN0
AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C

AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; //SOC1 will convert internal connection ADCIN1
AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C

AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 1; //end of SOC1 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;
}
int k = 0;
int counter;
int flag = 0;

interrupt void adca1_isr(void)
{
Sample[0] = AdcaResultRegs.ADCRESULT0;
Sample[1] = AdcaResultRegs.ADCRESULT1;
//Sample[2] = AdcaResultRegs.ADCRESULT2;
//Sample[3] = AdcaResultRegs.ADCRESULT3;
//Sample[4] = AdcaResultRegs.ADCRESULT4;
//Sample[5] = AdcaResultRegs.ADCRESULT5;
//Sample[6] = AdcaResultRegs.ADCRESULT6;
for(counter = 0;counter < 2;counter++)
Sample1[counter] = 3*Sample[counter]/4096;
if(counter == 2)
counter = 0;
k++;
if(k == 10000)
k = 0;
if(flag == 0)
{
GpioDataRegs.GPASET.bit.GPIO2 = 1;
flag = 1;
}
else
{
GpioDataRegs.GPACLEAR.bit.GPIO2 = 1;
flag = 0;
}

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

//
// End of file
//