Other Parts Discussed in Thread:C2000WARE
在调试28377D ADC数据采样的程序,程序按照EPWM进行触发ADC采样,当ADC采样结束之后通过ADC1中断里面读取ADC的值的。碰到点问题:
1.我目前程序写的是ADCA.SOC0-ACDA.SOC5, ADCB.SOC0-ADCB.SOC5,ADCC.SOC2-ADCC.SOC5,ADCD.SOC0-ADCD.SOC5然后进入ADC1的中断。这种情况下进ADC1中断的话ADCB、ADCC、ADCD这3个ADC是不是转换完成了?对应的转换完保存的寄存器是
AdcaResultRegs.ADCRESULT0—AdcaResultRegs.ADCRESULT5;
AdcbResultRegs.ADCRESULT0—AdcbResultRegs.ADCRESULT5;
AdccResultRegs.ADCRESULT2-AdccResultRegs.ADCRESULT5;
AdcaResultRegs.ADCRESULT0;AdcdResultRegs.ADCRESULT5
2.能不写ADC.SOC0-ADC.SOC15像下面这样
AdcaRegs.ADCSOC6CTL.bit.CHSEL =6;
AdcaRegs.ADCSOC7CTL.bit.CHSEL =7;
、、、、
AdcaRegs.ADCSOC15CTL.bit.CHSEL =15;
然后进入ADC1中断读取转换的数据。
我想到得到的就是所有数据转换完成后能正常进入中断ADC1,然后能在寄存器AdcaResultRegs.ADCRESULT0-AdcaResultRegs.ADCRESULT15里面能看到我的AD数据。我程序应该怎么改?
3.28377D到底有多路AD转换口,看资料ADCA有6个 ADCB有6个,ADCC有4个,ACD有6个加起来是22个。看实验板上的AD口只有20个,没明白为什么会少了2个
下面是我写的代码
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);
AdccRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCC, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
AdcdRegs.ADCCTL2.bit.PRESCALE = 6; //set ADCCLK divider to /4
AdcSetMode(ADC_ADCD, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
//
//Set pulse positions to late
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdccRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcdRegs.ADCCTL1.bit.INTPULSEPOS = 1;
//
//power up the ADC
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdccRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdcdRegs.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
AdcaRegs.ADCSOC1CTL.bit.CHSEL =1;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC2CTL.bit.CHSEL =2;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC3CTL.bit.CHSEL =3;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC4CTL.bit.CHSEL =4;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC5CTL.bit.CHSEL =5;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC5CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC0CTL.bit.CHSEL =0;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC1CTL.bit.CHSEL =1;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC1CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC2CTL.bit.CHSEL =2;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC2CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC3CTL.bit.CHSEL =3;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC3CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC4CTL.bit.CHSEL =4;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC4CTL.bit.TRIGSEL = 5;
AdcbRegs.ADCSOC5CTL.bit.CHSEL =5;// channel; //SOC0 will convert pin A0
AdcbRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcbRegs.ADCSOC5CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC2CTL.bit.CHSEL =2;// channel; //SOC0 will convert pin A0
AdccRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdccRegs.ADCSOC2CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC3CTL.bit.CHSEL =3;// channel; //SOC0 will convert pin A0
AdccRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdccRegs.ADCSOC3CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC4CTL.bit.CHSEL =4;// channel; //SOC0 will convert pin A0
AdccRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdccRegs.ADCSOC4CTL.bit.TRIGSEL = 5;
AdccRegs.ADCSOC5CTL.bit.CHSEL =5;// channel; //SOC0 will convert pin A0
AdccRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdccRegs.ADCSOC5CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC0CTL.bit.CHSEL =0;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC0CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC1CTL.bit.CHSEL =1;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC1CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC1CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC2CTL.bit.CHSEL =2;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC2CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC2CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC3CTL.bit.CHSEL =3;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC3CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC3CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC4CTL.bit.CHSEL =4;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC4CTL.bit.TRIGSEL = 5;
AdcdRegs.ADCSOC5CTL.bit.CHSEL =5;// channel; //SOC0 will convert pin A0
AdcdRegs.ADCSOC5CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcdRegs.ADCSOC5CTL.bit.TRIGSEL = 5;
/*AdcaRegs.ADCSOC7CTL.bit.CHSEL =1;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC7CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.ADCSOC7CTL.bit.TRIGSEL = 5;
AdcaRegs.ADCSOC8CTL.bit.CHSEL =2;// channel; //SOC0 will convert pin A0
AdcaRegs.ADCSOC8CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
AdcaRegs.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
// AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
// AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; //enable INT1 flag
//AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
EDIS;
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
InitPieVectTable();
// Enable global Interrupts and higher priority real-time debug events:
// EINT; // Enable Global interrupt INTM
//ERTM; // Enable Global realtime interrupt DBGM
// For this case just init GPIO pins for ePWM1
// Only CPU1 can configure GPIO muxing so this is done here
// These functions are in the F2837xD_EPwm.c file
InitEPwmGpio();
SetupEpwm();
// GpioCtrlRegs. //.GPCSET.bit.GPIO67= 1;
GPIO_SetupPinMux(67, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(67, GPIO_OUTPUT, GPIO_PUSHPULL);
GPIO_SetupPinMux(84, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(84, GPIO_OUTPUT, GPIO_PUSHPULL);
//Transfer ownership of EPWM1 and ADCA to CPU02
EALLOW;
// DevCfgRegs.CPUSEL0.bit.EPWM1 = 1;//connect to CPU2
// DevCfgRegs.CPUSEL11.bit.ADC_A = 1;//connect to CPU2
PieVectTable.TIMER0_INT=&cpu_timer0_isr;
PieVectTable.EPWM1_INT=&epwm1_time_isr;
PieVectTable.ADCA1_INT = &adca1_isr;
EDIS;
SetupAdc();
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 200, 300);
CpuTimer0Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit = 0
IER |= M_INT1;
IER |= M_INT3;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //开定时器中断
PieCtrlRegs.PIEIER3.bit.INTx1 = 1; //开pwm中断
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// SetupAdc();
TimeNub=0;
EpwmNub=0;
// Step 6. IDLE loop. Just sit and loop forever (optional):
while(1)
{
asm(" nop");
}
}
interrupt void cpu_timer0_isr(void)
{
TimeNub++;
if(TimeNub>100)
{
GpioDataRegs.GPCTOGGLE.bit.GPIO67 = 1;
TimeNub=0;
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
interrupt void epwm1_time_isr(void)
{
// READAD();
EpwmNub++;
if(EpwmNub>3000)
{
GpioDataRegs.GPCTOGGLE.bit.GPIO84 = 1;
EpwmNub=0;
}
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
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:
1、不是很了解你具体怎么设置的,不过这个问题我觉得你测试一下就可以看出来结果了。
2、不可以,之前的帖子中回复过你。具体CHSEL怎么设置你可以参考例程:C:\ti\c2000\C2000Ware_3_03_00_00\device_support\f2837xd\examples\cpu1\adc_soc_software
3、这个你可以看一下芯片datasheet上的Table 3-1. Device Comparison,受引脚限制,F28377D,12位模式的ADC引脚176分装的是20个,337封装的是24个。
,
陈三少:
基本调通了, 谢谢支持!
,
陈三少:
前面ADC口没对上一直看的是337封装的现在基本能读出来数据。但是还是有点疑惑,我在程序里开通了ADC1的中断也就是这一句PieVectTable.ADCA1_INT = &adca1_isr;然后通过EPWM1来进行触发ADCA到ADCD所有的20个口全部设置成bit.TRIGSEL = 5;最后设置ADC的中断那里只设置了ADC1的中断配置如下 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
那么当我进入到ADC1中断的时候我是不是可以认为这20个口的数据全部转换完成我只需去读取AdcaResultRegs、AdcbResultRegs、AdccResultRegs、AdcdResultRegs这四个对应的寄存器的值就可以?
如果这样不行的话我是还要开ADCB1_INT,ADCC1_INT,ADCD1_INT这三个中断同时配置好对应的寄存器,当进入这几个中断就认为对应的ADC已经转换完成?
,
Green Deng:
只要产生了ADCINT1就可以认为20路采样都完成了