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

用28335的定时器触发adc采样,两个中断都能进去,但是采样值不对,求大神们帮忙看看!!!

采集的是一个正弦波,通过数组Voltage1来观察数据和波形。但是采样值基本无变化,这是为什么呢?下面附上程序:

主函数:

void main(void)
{EALLOW;SysCtrlRegs.HISPCP.all = ADC_MODCLK;	// HSPCLK = SYSCLKOUT/2*ADC_MODCLKEDIS;
	int i;
	InitSysCtrl();//初始化系统函数
	IER = 0x0000;//禁止CPU中断IFR = 0x0000;//清除CPU中断标志InitPieCtrl();//初始化PIE控制寄存器InitPieVectTable();//初始化PIE中断向量表
	InitCpuTimers();InitEPwm1Gpio();InitEPwm2Gpio();InitEPwm3Gpio();DINT;InitAdc();//ADC初始化EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//禁止PWM时钟EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();ConfigCpuTimer(&CpuTimer0,30,1000);StartCpuTimer0();//启动定时器0PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块的总中断EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//使能PWM时钟EDIS;EALLOW;  // This is needed to write to EALLOW protected registerPieVectTable.TINT0 = &TINT0_ISR;//使能Timer0中断PieVectTable.ADCINT = &ADCINT_ISR;//使能ADC中断EDIS;// This is needed to disable write to EALLOW protected registersPieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能PIE中断的CPU定时器0PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //使能PIE中断中的ADC中断IER |= (M_INT1); // Enable CPU Interrupt 1EINT;//使能全局中断ERTM;//使能实时中断
for (i=0; i<BUF_SIZE; i++){Voltage1[i] = 0;Voltage2[i] = 0;Voltage3[i] = 0;}

定时器中断函数:

Uint16 q=0;
interrupt void  TINT0_ISR(void)// CPU-Timer 0
{// Insert ISR Code hereq++;//判断是否进入中断
		AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;//软件触发启动SEQ1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

ADC中断函数:

Uint16 qa=0;
interrupt void ADCINT_ISR(void) // ADC
{
// Insert ISR Code here
qa++;//判断是否进入中断
// To receive more interrupts from this PIE group, acknowledge this interrupt // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
Uint16 a[10],b[10],c[10];
Uint16 i,j,r,s,t;
Voltage1[ConversionCount1++] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount2++] = AdcRegs.ADCRESULT1 >>4;
Voltage3[ConversionCount3++] = AdcRegs.ADCRESULT2 >>4;
if(ConversionCount1>(511))
ConversionCount1=0;
DELAY_US(100);

AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

ADC初始化函数:

extern void DSP28x_usDelay(Uint32 Count);EALLOW;
		SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
		ADC_cal();
		EDIS;
AdcRegs.ADCTRL1.bit.RESET = 1;//Reset ADC moduleasm(" RPT #20||NOP");AdcRegs.ADCTRL3.all = 0x00E0;  // 给ADC内部上电DELAY_US(ADC_usDELAY);// 在ADC转换前要延时一段时间
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xff;  // Sequential mode: Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]//= 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)//= 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;//不分频AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;// 1  Cascaded modeAdcRegs.ADCTRL1.bit.CONT_RUN = 1;// Setup continuous runAdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;// Enable Sequencer override featureAdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x2;  // convert and store in 8 results registersAdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;// Setup ADCINA2 as 2nd SEQ1 conv.AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // 向CPU发出中断申请

这个问题已经困扰我好几天了,实在是没检查出来是什么问题,希望看到的大神停下来帮忙指点一下,感激不尽!!!

likai hu:

代码有点多。。但是思路还是挺清晰的,求大神们帮忙看看!!!!

采集的是一个正弦波,通过数组Voltage1来观察数据和波形。但是采样值基本无变化,这是为什么呢?下面附上程序:

主函数:

void main(void)
{EALLOW;SysCtrlRegs.HISPCP.all = ADC_MODCLK;	// HSPCLK = SYSCLKOUT/2*ADC_MODCLKEDIS;
	int i;
	InitSysCtrl();//初始化系统函数
	IER = 0x0000;//禁止CPU中断IFR = 0x0000;//清除CPU中断标志InitPieCtrl();//初始化PIE控制寄存器InitPieVectTable();//初始化PIE中断向量表
	InitCpuTimers();InitEPwm1Gpio();InitEPwm2Gpio();InitEPwm3Gpio();DINT;InitAdc();//ADC初始化EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//禁止PWM时钟EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();ConfigCpuTimer(&CpuTimer0,30,1000);StartCpuTimer0();//启动定时器0PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块的总中断EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//使能PWM时钟EDIS;EALLOW;  // This is needed to write to EALLOW protected registerPieVectTable.TINT0 = &TINT0_ISR;//使能Timer0中断PieVectTable.ADCINT = &ADCINT_ISR;//使能ADC中断EDIS;// This is needed to disable write to EALLOW protected registersPieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能PIE中断的CPU定时器0PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //使能PIE中断中的ADC中断IER |= (M_INT1); // Enable CPU Interrupt 1EINT;//使能全局中断ERTM;//使能实时中断
for (i=0; i<BUF_SIZE; i++){Voltage1[i] = 0;Voltage2[i] = 0;Voltage3[i] = 0;}

定时器中断函数:

Uint16 q=0;
interrupt void  TINT0_ISR(void)// CPU-Timer 0
{// Insert ISR Code hereq++;//判断是否进入中断
		AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;//软件触发启动SEQ1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

ADC中断函数:

Uint16 qa=0;
interrupt void ADCINT_ISR(void) // ADC
{
// Insert ISR Code here
qa++;//判断是否进入中断
// To receive more interrupts from this PIE group, acknowledge this interrupt // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
Uint16 a[10],b[10],c[10];
Uint16 i,j,r,s,t;
Voltage1[ConversionCount1++] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount2++] = AdcRegs.ADCRESULT1 >>4;
Voltage3[ConversionCount3++] = AdcRegs.ADCRESULT2 >>4;
if(ConversionCount1>(511))
ConversionCount1=0;
DELAY_US(100);

AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

ADC初始化函数:

extern void DSP28x_usDelay(Uint32 Count);EALLOW;
		SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
		ADC_cal();
		EDIS;
AdcRegs.ADCTRL1.bit.RESET = 1;//Reset ADC moduleasm(" RPT #20||NOP");AdcRegs.ADCTRL3.all = 0x00E0;  // 给ADC内部上电DELAY_US(ADC_usDELAY);// 在ADC转换前要延时一段时间
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xff;  // Sequential mode: Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]//= 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)//= 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;//不分频AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;// 1  Cascaded modeAdcRegs.ADCTRL1.bit.CONT_RUN = 1;// Setup continuous runAdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;// Enable Sequencer override featureAdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x2;  // convert and store in 8 results registersAdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;// Setup ADCINA2 as 2nd SEQ1 conv.AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // 向CPU发出中断申请

这个问题已经困扰我好几天了,实在是没检查出来是什么问题,希望看到的大神停下来帮忙指点一下,感激不尽!!!

Eric Ma:

回复 likai hu:

ERIC:

你在CCS的register窗口上查看ADC的结果寄存器,看它有没有变化。

另外,用TI的例程进行对比测试,排查:

C:\ti\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\adc_soc

采集的是一个正弦波,通过数组Voltage1来观察数据和波形。但是采样值基本无变化,这是为什么呢?下面附上程序:

主函数:

void main(void)
{EALLOW;SysCtrlRegs.HISPCP.all = ADC_MODCLK;	// HSPCLK = SYSCLKOUT/2*ADC_MODCLKEDIS;
	int i;
	InitSysCtrl();//初始化系统函数
	IER = 0x0000;//禁止CPU中断IFR = 0x0000;//清除CPU中断标志InitPieCtrl();//初始化PIE控制寄存器InitPieVectTable();//初始化PIE中断向量表
	InitCpuTimers();InitEPwm1Gpio();InitEPwm2Gpio();InitEPwm3Gpio();DINT;InitAdc();//ADC初始化EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//禁止PWM时钟EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();ConfigCpuTimer(&CpuTimer0,30,1000);StartCpuTimer0();//启动定时器0PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块的总中断EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//使能PWM时钟EDIS;EALLOW;  // This is needed to write to EALLOW protected registerPieVectTable.TINT0 = &TINT0_ISR;//使能Timer0中断PieVectTable.ADCINT = &ADCINT_ISR;//使能ADC中断EDIS;// This is needed to disable write to EALLOW protected registersPieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能PIE中断的CPU定时器0PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //使能PIE中断中的ADC中断IER |= (M_INT1); // Enable CPU Interrupt 1EINT;//使能全局中断ERTM;//使能实时中断
for (i=0; i<BUF_SIZE; i++){Voltage1[i] = 0;Voltage2[i] = 0;Voltage3[i] = 0;}

定时器中断函数:

Uint16 q=0;
interrupt void  TINT0_ISR(void)// CPU-Timer 0
{// Insert ISR Code hereq++;//判断是否进入中断
		AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;//软件触发启动SEQ1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

ADC中断函数:

Uint16 qa=0;
interrupt void ADCINT_ISR(void) // ADC
{
// Insert ISR Code here
qa++;//判断是否进入中断
// To receive more interrupts from this PIE group, acknowledge this interrupt // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
Uint16 a[10],b[10],c[10];
Uint16 i,j,r,s,t;
Voltage1[ConversionCount1++] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount2++] = AdcRegs.ADCRESULT1 >>4;
Voltage3[ConversionCount3++] = AdcRegs.ADCRESULT2 >>4;
if(ConversionCount1>(511))
ConversionCount1=0;
DELAY_US(100);

AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

ADC初始化函数:

extern void DSP28x_usDelay(Uint32 Count);EALLOW;
		SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
		ADC_cal();
		EDIS;
AdcRegs.ADCTRL1.bit.RESET = 1;//Reset ADC moduleasm(" RPT #20||NOP");AdcRegs.ADCTRL3.all = 0x00E0;  // 给ADC内部上电DELAY_US(ADC_usDELAY);// 在ADC转换前要延时一段时间
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xff;  // Sequential mode: Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]//= 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)//= 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;//不分频AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;// 1  Cascaded modeAdcRegs.ADCTRL1.bit.CONT_RUN = 1;// Setup continuous runAdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;// Enable Sequencer override featureAdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x2;  // convert and store in 8 results registersAdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;// Setup ADCINA2 as 2nd SEQ1 conv.AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // 向CPU发出中断申请

这个问题已经困扰我好几天了,实在是没检查出来是什么问题,希望看到的大神停下来帮忙指点一下,感激不尽!!!

user5006393:请问你解决了么?请教下你

采集的是一个正弦波,通过数组Voltage1来观察数据和波形。但是采样值基本无变化,这是为什么呢?下面附上程序:

主函数:

void main(void)
{EALLOW;SysCtrlRegs.HISPCP.all = ADC_MODCLK;	// HSPCLK = SYSCLKOUT/2*ADC_MODCLKEDIS;
	int i;
	InitSysCtrl();//初始化系统函数
	IER = 0x0000;//禁止CPU中断IFR = 0x0000;//清除CPU中断标志InitPieCtrl();//初始化PIE控制寄存器InitPieVectTable();//初始化PIE中断向量表
	InitCpuTimers();InitEPwm1Gpio();InitEPwm2Gpio();InitEPwm3Gpio();DINT;InitAdc();//ADC初始化EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//禁止PWM时钟EDIS;InitEPwm1Example();InitEPwm2Example();InitEPwm3Example();ConfigCpuTimer(&CpuTimer0,30,1000);StartCpuTimer0();//启动定时器0PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块的总中断EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//使能PWM时钟EDIS;EALLOW;  // This is needed to write to EALLOW protected registerPieVectTable.TINT0 = &TINT0_ISR;//使能Timer0中断PieVectTable.ADCINT = &ADCINT_ISR;//使能ADC中断EDIS;// This is needed to disable write to EALLOW protected registersPieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能PIE中断的CPU定时器0PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //使能PIE中断中的ADC中断IER |= (M_INT1); // Enable CPU Interrupt 1EINT;//使能全局中断ERTM;//使能实时中断
for (i=0; i<BUF_SIZE; i++){Voltage1[i] = 0;Voltage2[i] = 0;Voltage3[i] = 0;}

定时器中断函数:

Uint16 q=0;
interrupt void  TINT0_ISR(void)// CPU-Timer 0
{// Insert ISR Code hereq++;//判断是否进入中断
		AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;//软件触发启动SEQ1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

ADC中断函数:

Uint16 qa=0;
interrupt void ADCINT_ISR(void) // ADC
{
// Insert ISR Code here
qa++;//判断是否进入中断
// To receive more interrupts from this PIE group, acknowledge this interrupt // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
Uint16 a[10],b[10],c[10];
Uint16 i,j,r,s,t;
Voltage1[ConversionCount1++] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount2++] = AdcRegs.ADCRESULT1 >>4;
Voltage3[ConversionCount3++] = AdcRegs.ADCRESULT2 >>4;
if(ConversionCount1>(511))
ConversionCount1=0;
DELAY_US(100);

AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

ADC初始化函数:

extern void DSP28x_usDelay(Uint32 Count);EALLOW;
		SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
		ADC_cal();
		EDIS;
AdcRegs.ADCTRL1.bit.RESET = 1;//Reset ADC moduleasm(" RPT #20||NOP");AdcRegs.ADCTRL3.all = 0x00E0;  // 给ADC内部上电DELAY_US(ADC_usDELAY);// 在ADC转换前要延时一段时间
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xff;  // Sequential mode: Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]//= 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)//= 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]AdcRegs.ADCTRL3.bit.ADCCLKPS = 0;//不分频AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;// 1  Cascaded modeAdcRegs.ADCTRL1.bit.CONT_RUN = 1;// Setup continuous runAdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;// Enable Sequencer override featureAdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x2;  // convert and store in 8 results registersAdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;// Setup ADCINA2 as 2nd SEQ1 conv.AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // 向CPU发出中断申请

这个问题已经困扰我好几天了,实在是没检查出来是什么问题,希望看到的大神停下来帮忙指点一下,感激不尽!!!

mangui zhang:

回复 user5006393:

个人还是觉得先用TI的例程测试然后在此基础上进行修改

赞(0)
未经允许不得转载:TI中文支持网 » 用28335的定时器触发adc采样,两个中断都能进去,但是采样值不对,求大神们帮忙看看!!!
分享到: 更多 (0)