dsp 28335 AD中断4次后程序停止,付代码。(dsp新手 望大神指教)

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include"SPI_com2.h"
interrupt void adc_isr(void);

// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 a;
int32 sum;
Uint16 Voltage1[64];
int32 Ver;
int j;
main()
{

InitSysCtrl();

EALLOW;
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
EDIS;
// Step 3. Clear all interrupts and initialize PIE vector table:
DINT;
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
EDIS; // This is needed to disable write to EALLOW protected registers

InitAdc(); // For this example, init the ADC

// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

LoopCount = 0;
ConversionCount = 0;
a=0;
Ver=0;

// 配置 ADC
AdcRegs.ADCTRL1.bit.ACQ_PS=15;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 0xf;
AdcRegs.ADCMAXCONV.all = 0xf; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x0;

AdcRegs.ADCTRL1.bit.SEQ_OVRD=0;
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;
AdcRegs.ADCTRL1.bit.CONT_RUN=1;

AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)

// Assumes ePWM1 clock is already enabled in InitSysCtrl();
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start

//清除中断标志位
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

//初始化数组

 for(j=0;j<64;j++)
 {
    Voltage1[j]=0;
 }

/**/

// Wait for ADC interrupt
for(;;)
{
LoopCount++;
}

}

interrupt void adc_isr(void)
{

Voltage1[ConversionCount++] = AdcRegs.ADCRESULT0 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT1 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT2 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT3 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT4 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT5 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT6 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT7 >>4;

Voltage1[ConversionCount++] = AdcRegs.ADCRESULT8 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT9 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT10 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT11 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT12 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT13 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT14 >>4;
Voltage1[ConversionCount++] = AdcRegs.ADCRESULT15 >>4;

if(ConversionCount == 64) //当数组存满是做一次求平均,然后通过串口发出
{ //问题就出现在进入四次中断,数组值做完平均运算 //后,跳出中断,程序停止
Uint16 i;
sum=0;
for(i=0;i<64;i++)

{
sum=sum+(int32)Voltage1[i];
}
Ver=sum/64; //将数组的数值做平均
SPI_com2(Ver); //串口发送这个平均数
ConversionCount = 0;
}

/**/
// Reinitialize for next ADC sequence
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
a++; //查看进入中断次数
return;
}

2个回答

这种ad/da的采集,要看你的信号源是否稳定,用示波器去调试,看代码没用

嗯,我再试试,谢谢, AD输入电压是开发板的电阻的分压

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问