DSP adc²É¼¯³ÌÐò ÏÂÔر¾ÎÄ

ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2024/11/8 11:43:12ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£

#include \ #include \ #include \

#include \#include \

int ConversionCount,f; int Voltage[1024],Vmax,Vmin,Vavr; //µçѹת»»½á¹û´æ´¢Êý×é¼°Ò»¸öÖÜÆÚÄڵIJÉÑùÖµÊý×é float RMS=0,U0[1024],SV[]; //µçѹÓÐЧֵ interrupt void adc_isr(void);

main() { InitSysCtrl(); //³õʼ»¯Ê±ÖÓ£¬CPUΪ15M,¸ßËÙʱÖÓHspclkΪ1.5M DINT; //¹Ø±ÕÖжÏ

InitPieCtrl(); //³õʼ»¯Pie¼Ä´æÆ÷

IER=0x0000; //½ûÖ¹ËùÓпÉÆÁ±ÎÖÐ¶Ï IFR=0x0000;

InitPieVectTable(); //³õʼ»¯PieÖжÏÏòÁ¿±í

EALLOW; //´ò¿ª¼Ä´æÆ÷д±£»¤

PieVectTable.ADCINT=&adc_isr; //½«AdcÖжÏ×Ó³ÌÐòµÄ·þÎñµØַдÈëÖжÏÏòÁ¿±í EDIS; //½ûÖ¹¼Ä´æÆ÷µÄ·ÃÎÊ

InitAdc(); //³õʼ»¯Adc£¬Íê³ÉAdcµÄÉϵç InitLcd(); //Òº¾§³õʼ»¯ /*ÔÚPieÖÐʹÄÜAdcµÄÖжÏADCINT*/

PieCtrlRegs.PIEIER1.bit.INTx6=1; //²é±íÖªADCINT¶ÔÓ¦µÄÊÇINT1,INTx.6 IER=M_INT1; //ʹÄÜCPUÖÐ¶Ï EINT; //ʹÄÜÈ«¾ÖÖÐ¶Ï /*ÅäÖÃAdcÄ£¿é*/

AdcRegs.ADCMAXCONV.all=0x0000; //ÉèÖÃSEQ1µÄ×î´óת»»Í¨µÀÊýΪ1 AdcRegs.ADCCHSELSEQ1.bit.CONV00=0x0; //Ñ¡Ôñ0ͨµÀ

AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1=1; //Ñ¡ÔñEVA×÷ΪSEQ1µÄ´¥·¢Æô¶¯ÐźŠAdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1; //ʹÄÜSEQ1µÄÖжϲÙ×÷£¨ÖжϷ½Ê½0£©

/*ÅäÖÃEVA*/

EvaRegs.T1CNT=0x0000; //¼ÆÊý³õÖµ

EvaRegs.T1PR=0x007D; //ÉèÖÃÖÜÆڼĴæÆ÷ֵΪ125£¬ÒòΪÏÂÃæÉèµÄÊÇÔö¼õ¼ÆÊýģʽ£¬EVAµÄÏÂÒçÆô¶¯Adc£¬ËùÒÔ²ÉÑùÖÜÆÚÊÇ250¸ö¼ÆÊýÖÜÆÚ

EvaRegs.GPTCONA.bit.T1TOADC=0x1; //ÉèÖÃEVAµÄÏÂÒçÆô¶¯Adc EvaRegs.T1CON.all=0x0842; //ÉèÖÃT1ΪÁ¬ÐøÔö¼õ¼ÆÊýģʽ£¬²»·ÖƵ£¬¼´Ê±ÖÓΪ¸ßËÙʱÖÓHspclk£º1.5M £¬

}

ConversionCount=0;

while(1) //µÈ´ýÖÐ¶Ï { ; }

interrupt void adc_isr(void) {

if(Vmin>Voltage[i]) Vmin=Voltage[i]; //Çó³ö×îСֵ

int i=0,j=0,flag=0; //flag×÷ΪÓöµ½ÁãµãµÄ±êÖ¾ Voltage[ConversionCount]=AdcRegs.ADCRESULT0>>4;

U0[ConversionCount]=3.0*Voltage[ConversionCount]/4095;

if(ConversionCount==1023) //Èç¹û²ÉÑùµãÊý´ïµ½ÁË1024 {

PieCtrlRegs.PIEIER1.bit.INTx6=0; //½ûÖ¹ÖжÏÇëÇó ConversionCount=0;

/*Çó³ö1024¸öµãÖеÄ×î´ó×îСֵºÍÖмäÖµ*/

Vmax=Voltage[0]; Vmin=Voltage[0];

for(i=0;i<1024;i++) { if(Vmax

}

Vavr=(Vmax-Vmin)/2; //Çó³öÖмäÖµ

{

if(flag==1)

SV[j]=U0[i]; //U0[i]¾ÍÊǶÔÓ¦µÄVoltage[i]µÄÄ£ÄâÖµ RMS+=SV[j]*SV[j];

for(i=1;i<1024;i++) {

if((Voltage[i-1]<=Vavr)&&(Voltage[i]>=Vavr)) { }

flag++;

}

} { }

j++;

if(flag==2) i=1024; flag=0;

RMS=sqrt(RMS/j); rg=(int)RMS;

r1=((int)(RMS*10)); r2=((int)(RMS*100)); f=(1500000/250)/j;

fb=f/100; fs=(f-fb*100)/10; fg=f-fb*100-fs*10;

lcd_write_dy();

lcd_write_pl();

PieCtrlRegs.PIEIER1.bit.INTx6=1; //ʹÄÜÖжÏÇëÇó }

}

else ConversionCount++;

/*¸´Î»SEQ1£¬µÈ´ý´¥·¢ÐźÅÖØÆôÏ´Îת»»*/

AdcRegs.ADCTRL2.bit.RST_SEQ1=1; //¸´Î»SEQ1

AdcRegs.ADCST.bit.INT_SEQ1_CLR=1; //Çå³ýSEQ1µÄÖжϱê־λ

PieCtrlRegs.PIEACK.all=PIEACK_GROUP1; //ʹÄÜAdcÄ£¿éµÄÏ´ÎÖжÏÇëÇó return;