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

📄 vc33psad.c

📁 作者:张庆 单独AD程序,取出内存中的数据,传送给PCI,并转化为电压值.
💻 C
字号:
/*********************************************************************************
*作者:张庆                                                                                *
*单独AD程序,取出内存中的数据,传送给PCI,并转化为电压值.                			 *
*********************************************************************************/
#include "math.h"
#include "vc33ps.h"
#include "Max125.h"
#include "sram.h"
#include "pci.h"
#define vol 0.0006103515625
#define pi 3.1415926
#define N 1024
volatile float *SinTable = (volatile float *) 0x805400; /* Sin函数表/RAM BLOCK 3 */ 
volatile float *buf = (volatile float *) 0x804000;	/* x FFTOut/RAM BLOCK 3 */ 
cregister unsigned int IE,IF,ST,IOF; 
main()
{   
    int i,j;
	int shuju;
	unsigned int * ptr;
	volatile int *adbuf = (volatile int *) 0xc10000;
	/*AD设置参数C控制*/
/*	TIM0_CTL=TIM0_CTL_VALUE;
	TIM0_CNT=0;
	TIM0_PRD=TIM0_PRD_VALUE;
	TIM0_CTL=TIM0_CTL_VALUE|TIM0_START;
*/	 
  	/*AD设置叁数*/
  	PAdset adset;
	/*AD的采样方式(0:定时,1:单次猝发)*/
	unsigned int Adworkway;
  	/*AD的采样率,或是采样次数*/
  	unsigned int Adsample;
  	/*AD状态参数*/
  	PAdstuates adstuates;
  	unsigned int adsadress;
     
    /* 	清空AD的数据缓冲区 */
    ptr = (unsigned int *)0xc10000; 
    for(i=0; i<0x1000; i++)
    {
    	*ptr++ = 0x00;
    } 
    /*fft*/
	for (i=0;i<N/2;i++) 
	{
	SinTable[i]=sin(i*2*pi/N);
	}  
     
	for (i=0;i<1024;i++) 
	{
	buf[i]=sin(0.25*i*pi);
	}  
	ffft_rl( 1024, 10, buf, buf, SinTable, 1 ); 
  	/*建立状态区*/
  	adstuates = (PAdstuates)ADSTATE;
  	*(int *)0x808064=0x128;/*1个等待*/  
  	/*复位AD*/
  	adset = (PAdset)HOSTSET;
	 
	/* 假设对AD作如下设置,用户可以更改 */
	adset->Ad0count = 0x1; 			/* 采样1通道 */
	adset->Ad1count = 0x0;    		/* 采样0通道 */
	adset->Ad2count = 0x0;    		/* 采样0通道 */
	adset->Ad3count = 0x0;    		/* 采样0通道 */
	adset->AorB = 0x0;   			/* A通路 	 */   
	adset->ADsampleway = 0x0;       /* 定时采样方式 */
	adset->ADsample = 187;          /* 采样率 */ 
	
	/*AD初始化*/ 
	adset->Ad0count = adset->Ad0count + adset->AorB;
	adset->Ad1count = adset->Ad1count + adset->AorB;
	adset->Ad2count = adset->Ad2count + adset->AorB;
	adset->Ad3count = adset->Ad3count + adset->AorB; 
	*(int *)(ADSTATE+0xA)=adset->AorB;
	/*初始化MAX125*/  		
	Max125_init(adset->Ad0count,
	  			adset->Ad1count,
	  			adset->Ad2count,
	  			adset->Ad3count,
	  			ADINT1
	  			);
	Adworkway = adset->ADsampleway;
	Adsample = adset->ADsample;  
	/*启动AD*/
	if(Adworkway == 0x0)
	{
	  	/*定时器启动AD*/
	  	/*连续采样*/
	  	Max125_start(Adworkway,Adsample,0);
	}  
	if(Adworkway ==0x2)
	{
	  	/*软件启动AD*/
	  	Max125_start(Adworkway,0,Adsample);
	}	
	for(;;) 
	{
        
		while(adstuates->Adbuffhalf)
		 {
		  	/*清空标志*/
		  	adstuates->Adbuffhalf = 0;
		  	/*传送数据给PCI ltopci(0xC10000,0x401000, adlength);*/
		 	ltopci(0xC10000,0x401000, adlength);
		  	/*取出电压数据buf[i]=5*(shuju-16384)/8192*/
		  	for (j=0;j<1024;j++)
			{ 
 				shuju=adbuf[j]&0x3fff;
				if(shuju<8192)
				{
					buf[j]=vol*shuju;
				}
				else
				{
					buf[j]=vol*(shuju-16384);
				}   
				
			}

/*      fft_rl(1024,10,buf);   */
		    j=0;
		 }	
	
	}
	
}

⌨️ 快捷键说明

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