⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad.c

📁 ad采样
💻 C
字号:

#include "DSP28_Device.h"

float	a1[16];
float   b1[10][10]  ;  //数据存储二维数组
//unsigned int a2=0;
float	adclo=0.0;
int   X_count=0;
int   Y_count=0;

int RUN_X=0;
int RUN_Y=0;
int DIR_X=0;
int DIR_Y=0;
int temp=1; 
int Y;
 float  x;
 float   T;
float a2[10];
// Prototype statements for functions found within this file.
interrupt void ad(void);
void Y_Step_In(void);


float CatchAndDeal(t) 
{
   int j=0,k=0;
   

    
    while(j<=10)      //   一条通道取十个MAX值
     {


        while(k<=20 )     //周期采样点数
         {
              
             if(t/65520*3>a2[j])        //取最大值
               
               {
                 a2[j]=t/65520*3;
               }
              k++;
           } 
           j++;  
     
            EINT;
     }      
  // 数据处理a2[10]

              x=(a2[0]+a2[1]+a2[2]+a2[3]
              +a2[4]+a2[5]+a2[6]+a2[7]+
              a2[8]+a2[9])/11;

   

       return  x;

}	


void DELAY_LOOP_WAIT(unsigned int DELAY)
{	
	int i;
    int j;
	
	for(i=1;i<DELAY;i++)
    {
	  for(j=1;j<10000;j++);
	}
}
 
void X_Step_In(void)
{
  if(X_count<10)
     {
       DIR_X=0;
       RUN_X=0x3f;
      }
    else if(X_count==10)
     {
       DIR_X=1 ;
       RUN_X=0x00;
       Y_Step_In();
     }
     else if(X_count>10&&X_count<20)
     {
       DIR_X=1 ;
       RUN_X=0x3f;
      
     }
     else
     {
       DIR_X=0 ;
       RUN_X=0x00;
       X_count=0;
       Y_Step_In();
     }
     
  
     
     EvaRegs.T1CMPR = RUN_X;  	// 使能X电机
     EvaRegs.T2CMPR = DIR_X ;     // DIR=0 or 1  控制X电机运动方向
   
     DELAY_LOOP_WAIT(3000);     // 延时  步进
     EvaRegs.T1CMPR = 0x00;     // 停止X电机
    
    	
    AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;//    中断清除
//	AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;      
   
     DELAY_LOOP_WAIT(3000);
  
  
    while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)	
	{			

	    AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;     //  启动ADC

	}
	
	
}


void Y_Step_In(void)
{
     if(Y_count<10)
     {
       DIR_Y=0;
       RUN_Y=0x3f;
      }
    else if(Y_count==10)
     {
       DIR_Y=1 ;
       RUN_Y=0x00;
      }
     else if(Y_count>10&&Y_count<20)
     {
       DIR_Y=1 ;
       RUN_Y=0x3f;
      
     }
     else
     {
       DIR_Y=0 ;
       RUN_Y=0x00;
       Y_count=0;
      }
     
     
     EvbRegs.T3CMPR = RUN_Y;  	// 使能Y电机
     EvbRegs.T4CMPR = DIR_Y;     // DIR=0 or 1  控制Y电机运动方向
   
     DELAY_LOOP_WAIT(3000);     // 延时  步进
     EvbRegs.T3CMPR = 0x00;     // 停止Y电机
       
     DELAY_LOOP_WAIT(3000);

}


void main(void)
{

	InitSysCtrl();

	DINT;
	IER = 0x0000;
	IFR = 0x0000;

	InitPieCtrl();


	InitPieVectTable();	
	
	
	EALLOW;	// This is needed to write to EALLOW protected registers
	PieVectTable.ADCINT=&ad;
	EDIS;   // This is needed to disable write to EALLOW protected registers
    
    InitAdc();
    
    InitEv();
    
    IER |= M_INT1;
    EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM
	
	
	
	for(;;)
	{
			KickDog();
			
            X_Step_In();
			
	}
} 	


interrupt void ad(void)
{
	IFR=0x0000;
//	PieCtrl.PIEIFR1.all = 0;
	PieCtrl.PIEACK.all=0xffff;
//	a2++;

	
    T=CatchAndDeal(AdcRegs.RESULT0);
    
  if(T<1000&temp<8) 
   {
      
      
     
      Y=GpioDataRegs.GPADAT.all;
      Y&=0xFFF0;
      Y|=temp;
      GpioDataRegs.GPADAT.all=Y;
      temp++;
   //   b1[X_count][Y_count]=CatchAndDeal(AdcRegs.RESULT0);
   
   }
   else if(T>=1000&temp<8)
   {
       
    b1[X_count][Y_count]=T;
             X_count++;
   }
   
   else
   {
         b1[X_count][Y_count]=0; 
   }
  
      
/*  a1[0]=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
	a1[1]=((float)AdcRegs.RESULT1)*3.0/65520.0+adclo;
	a1[2]=((float)AdcRegs.RESULT2)*3.0/65520.0+adclo;
	a1[3]=((float)AdcRegs.RESULT3)*3.0/65520.0+adclo;
	a1[4]=((float)AdcRegs.RESULT4)*3.0/65520.0+adclo;
	a1[5]=((float)AdcRegs.RESULT5)*3.0/65520.0+adclo;
	a1[6]=((float)AdcRegs.RESULT6)*3.0/65520.0+adclo;
	a1[7]=((float)AdcRegs.RESULT7)*3.0/65520.0+adclo;
    a1[8]=((float)AdcRegs.RESULT8)*3.0/65520.0+adclo;
	a1[9]=((float)AdcRegs.RESULT9)*3.0/65520.0+adclo;
	a1[10]=((float)AdcRegs.RESULT10)*3.0/65520.0+adclo;
	a1[11]=((float)AdcRegs.RESULT11)*3.0/65520.0+adclo;
	a1[12]=((float)AdcRegs.RESULT12)*3.0/65520.0+adclo;
	a1[13]=((float)AdcRegs.RESULT13)*3.0/65520.0+adclo;
	a1[14]=((float)AdcRegs.RESULT14)*3.0/65520.0+adclo;
	a1[15]=((float)AdcRegs.RESULT15)*3.0/65520.0+adclo;*/
//	DELAY_LOOP_WAIT(3000);

 	
	
	 
}

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -