最近在做ad采集三相电压的项目,采集过来的数据graphy一下后发现,有的好像断了一样。
希望朋友们帮忙分析下
以下是代码:#include "DSP281x_Device.h"
#include "IQmathLib.h"
interrupt void Ad_intrpt_isr();
Uint16 count=1;
float ad_val[16],adclo=0.0;
float ad_sample[360];
Uint16 ad_num;
void main()
{
InitSysCtrl();
DINT;
IER =0;
IFR =0;
InitPieCtrl();
InitPieVectTable();
EALLOW;
PieVectTable.T1PINT=&Ad_intrpt_isr;
EDIS;
InitAdc();
PieCtrlRegs.PIEIER2.bit.INTx4 =1; //enable T1PINT in PIE
InitEv();
EvaRegs.T1CON.bit.TENABLE =1;
IER|=M_INT2; //enable CPU interrupt1
EINT; //enable Global interrupt
ERTM;
/*while(AdcRegs.ADCST.bit.SEQ1_BSY==0)
{
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
*/
for(;;);
}
interrupt void Ad_intrpt_isr()
{
//IER= 0;
// PieCtrlRegs.PIEIFR1.all= 0; //
// count++;
ad_val[0]=((float)AdcRegs.ADCRESULT0)*3.0/65520.0+adclo;
ad_val[1]=((float)AdcRegs.ADCRESULT1)*3.0/65520.0+adclo;
ad_val[2]=((float)AdcRegs.ADCRESULT2)*3.0/65520.0+adclo;
ad_val[3]=((float)AdcRegs.ADCRESULT3)*3.0/65520.0+adclo;
ad_val[4]=((float)AdcRegs.ADCRESULT4)*3.0/65520.0+adclo;
ad_val[5]=((float)AdcRegs.ADCRESULT6)*3.0/65520.0+adclo;
ad_val[6]=((float)AdcRegs.ADCRESULT7)*3.0/65520.0+adclo;
ad_val[7]=((float)AdcRegs.ADCRESULT8)*3.0/65520.0+adclo;
ad_val[8]=((float)AdcRegs.ADCRESULT9)*3.0/65520.0+adclo;
ad_val[9]=((float)AdcRegs.ADCRESULT10)*3.0/65520.0+adclo;
ad_val[10]=((float)AdcRegs.ADCRESULT11)*3.0/65520.0+adclo;
ad_val[11]=((float)AdcRegs.ADCRESULT12)*3.0/65520.0+adclo;
ad_val[12]=((float)AdcRegs.ADCRESULT13)*3.0/65520.0+adclo;
ad_val[13]=((float)AdcRegs.ADCRESULT14)*3.0/65520.0+adclo;
ad_val[14]=((float)AdcRegs.ADCRESULT15)*3.0/65520.0+adclo;
ad_val[15]=((float)AdcRegs.ADCRESULT15)*3.0/65520.0+adclo;
ad_sample[ad_num++]= ad_val[4];
if(ad_num>=360)ad_num = 0;
AdcRegs.ADCTRL2.bit.RST_SEQ1= 1; //reset seq1 for new adc sequence
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 =1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1= 1;
EvaRegs.EVAIFRA.bit.T1PINT =1;
EvaRegs.EVAIMRA.bit.T1PINT =1;
PieCtrlRegs.PIEACK.bit.ACK2 =1;
}
#define ADC_usDELAY 8000L
#define ADC_usDELAY2 20L
//---------------------------------------------------------------------------
// InitAdc:
//---------------------------------------------------------------------------
// This function initializes ADC to a known state.
void DSP28x_usDelay(Uint32 Count)
{
while(--Count);
}
void InitAdc(void)
{
DSP28x_usDelay(1000000);
// To powerup the ADC the ADCENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap and reference circuitry.
// After a 5ms delay the rest of the ADC can be powered up. After ADC
// powerup, another 20us delay is required before performing the first
// ADC conversion. Please note that for the delay function below to
// operate correctly the CPU_CLOCK_SPEED define statement in the
// DSP28_Examples.h file must contain the correct CPU clock period in
// nanoseconds. For example:
EALLOW;
//ADC RESET
AdcRegs.ADCTRL1.bit.RESET = 1;
// asm("RPT #10||NOP"); //delay 12 nop
AdcRegs.ADCTRL1.bit.RESET = 0;
//ADC上电
// DELAY_US(ADC_usDELAY);
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 3; // Power up bandgap/reference circuitry
DELAY_US(ADC_usDELAY); // Delay before powering up rest of ADC
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
DELAY_US(ADC_usDELAY2); // Delay after powering up ADC
AdcRegs.ADCTRL3.bit.ADCEXTREF = 0;
//ADC时钟选择
AdcRegs.ADCTRL1.bit.CPS = 0; //core clock prescale 一分频
AdcRegs.ADCTRL3.bit.ADCCLKPS = 0x5; //时钟分频器 对高速时钟分频
//AD 模式选择
AdcRegs.ADCTRL1.bit.ACQ_PS = 0x03; //S/H width in ADC model period
AdcRegs.ADCTRL1.bit.CONT_RUN = 0; //stop/start model
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1 ; // casaded model 级联模式
AdcRegs.ADCTRL1.bit.SUSMOD = 3 ; //仿真器被挂起时,排序器和其他逻辑立即停止
AdcRegs.ADCTRL3.bit.SMODE_SEL =0; //顺序采样模式
//ADC 通道选择
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x4;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 3;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 4;
//ADC 启动模式/中断模式
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; //复位马上转到conv00
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1;
AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ = 0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0; //每隔SEQ1序列结束时,中断马上触发
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; //软件触发排序,0清除排序
AdcRegs.ADCTRL2.bit.SOC_SEQ2 = 0; //不开启排序器2
EDIS;
}
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
//---------------------------------------------------------------------------
// InitEv:
//---------------------------------------------------------------------------
// This function initializes to a known state.
//
void InitEv(void)
{
EvaRegs.T1CNT =0;
EvaRegs.T1PR =0x0BB8;
EvaRegs.T1CON.all =0x1042;
EvaRegs.GPTCONA.all =0;
EvaRegs.EVAIFRA.bit.T1PINT =1;
EvaRegs.EVAIMRA.bit.T1PINT =1;
EvaRegs.GPTCONA.bit.T1TOADC =2;
}