TI中文支持网
TI专业的中文技术问题搜集分享网站

28377d读取16路AD

Other Parts Discussed in Thread:C2000WARE, CONTROLSUITE

通过epwm中断启动ADC采样,采样完成进入ADC中断。现在我是所有的中断都能正常进行,但是我的AD数据能读到一路不知道我那里配置错了。

EALLOW;

//
//write configurations
// AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 1;
AdcaRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
AdcbRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);

//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;

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

//
//delay for 1ms to allow ADC time to power up
//

if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
{
acqps = 14; //75ns
}
else //resolution is 16-bit
{
acqps = 63; //320ns
}

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

AdcbRegs.ADCSOC0CTL.bit.CHSEL =8;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC8CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;

interrupt void adca1_isr(void)
{

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

void READAD(void)
{
// static unsigned int m; //做AD采样判断用的
ReadADNUB=AdcaResultRegs.ADCRESULT0;
//AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //adc的seq1序列转换完成后,软件清零中断标志int_seq1
// Reinitialize for next ADC sequence
//AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
}

Green Deng:

你好,程序中是采样率两路?但是你只能读取一路的数据?
AdcaRegs.ADCSOC0CTL.bit.CHSEL =0;

AdcbRegs.ADCSOC0CTL.bit.CHSEL =8;

TI有提供PWM触发ADC的例程,不知道你是否有参考?C:\ti\c2000\C2000Ware_3_03_00_00\device_support\f2837xd\examples\cpu1\adc_soc_epwm

,

陈三少:

做了点改动代码如下,能正常读取ADC0到ADC5的数据 剩余的没读到。
尝试过SOC6-SOC15全部用AdcaRegs. 做配置情况一样 ,。AdcaRegs.ADCSOC0CTL.bit.CHSEL =0;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //trigger on ePWM1 SOCA/C
AdcaRegs.ADCSOC1CTL.bit.CHSEL =1;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC2CTL.bit.CHSEL =2;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC3CTL.bit.CHSEL =3;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC4CTL.bit.CHSEL =4;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC5CTL.bit.CHSEL =5;// channel;//SOC0 will convert pin A0AdcaRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcaRegs.ADCSOC5CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC6CTL.bit.CHSEL =6;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC6CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC6CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC7CTL.bit.CHSEL =7;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC7CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC7CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC8CTL.bit.CHSEL =8;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC8CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC8CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC9CTL.bit.CHSEL =9;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC9CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC9CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC10CTL.bit.CHSEL =10;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC10CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC10CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC11CTL.bit.CHSEL =11;// channel;//SOC0 will convert pin A0AdcbRegs.ADCSOC11CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcbRegs.ADCSOC11CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC12CTL.bit.CHSEL =12;// channel;//SOC0 will convert pin A0AdccRegs.ADCSOC12CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdccRegs.ADCSOC12CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC13CTL.bit.CHSEL =13;// channel;//SOC0 will convert pin A0AdccRegs.ADCSOC13CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdccRegs.ADCSOC13CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC14CTL.bit.CHSEL =14;// channel;//SOC0 will convert pin A0AdcdRegs.ADCSOC14CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcdRegs.ADCSOC14CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC15CTL.bit.CHSEL =15;// channel;//SOC0 will convert pin A0AdcdRegs.ADCSOC15CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cyclesAdcdRegs.ADCSOC15CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flagAdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;//enable INT1 flagAdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared

,

Green Deng:

AdcbRegs.ADCSOC7CTL.bit.CHSEL =7;// channel; //SOC0 will convert pin A0

开始设置的ADC通道都是无效的,你可以仔细看一下F28377D的ADC通道设置方法,上述语句应该改为:

AdcaRegs.ADCSOC7CTL.bit.CHSEL =7;// channel; //SOC7 will convert pin A7

或者

AdcbRegs.ADCSOC7CTL.bit.CHSEL =0;// channel; //SOC0 will convert pin B0

AdcaRegs.ADCSOCxCTL.bit.CHSEL =0~y,对应ADCINA0~y,

AdcbRegs.ADCSOCxCTL.bit.CHSEL =0~y,对应ADCINB0~y,

AdccRegs.ADCSOCxCTL.bit.CHSEL =0~y,对应ADCINC0~y,

AdcdRegs.ADCSOCxCTL.bit.CHSEL =0~y,对应ADCIND0~y,

你可以多看一下芯片TRM中介绍的ADC 配置例程代码。

,

陈三少:

芯片TRM在哪里?我看到的例程代码是controlSUITE上看到的。但是这个例程代码只采样的A0。
按照你说的改成
1个
AdcaRegs.ADCSOC7CTL.bit.CHSEL =7;// channel; //SOC7 will convert pin A7
或者
1个
AdcbRegs.ADCSOC7CTL.bit.CHSEL =0;
我带着仿真器看到还是只有ADC0-ADC5能读到数据。

,

Green Deng:

芯片TRM就是芯片技术手册,你可以在芯片主页找到:www.ti.com.cn/…/TMS320F28377D
现在controlSUITE不更新了,你可以用C2000ware,也是同样的用法

赞(0)
未经允许不得转载:TI中文支持网 » 28377d读取16路AD
分享到: 更多 (0)