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
//
Green Deng:
你好,前几天接触了一个类似的帖子,你看下里面的情况是否有涉及:https://www.ti2k.com/wp-content/uploads/ti2k/DeyiSupport_C2000_tms320f280049-adc
,
Hao Liu:
请问这个他指的那个VDDA的那个原因该怎么解决呢
,
Hao Liu:
而且他的芯片型号和我的也不太一样
,
Green Deng:
主要是ADC模块都是差不多的,你可以根据帖子里面我列出来的几项进行排查,看看是否有对应的问题。比如帖子中的用户就有电源不稳定的问题
,
Hao Liu:
那篇文章所说的VDDA电压具体在哪里进行测试呐
,
Green Deng:
这个你看一下datasheet中的VDDA引脚,测一下引脚电压波形看是否稳定就可以了。VDDA就是模拟部分的供电电源
,
Hao Liu:
问题解决了,是ADC时钟分频PRESCALE一开始设置的是0,没有分频,然后可能工作频率太快了导致多路采样出现问题,但是单路采样没有问题,只要把这个值设置成大于等于2即可