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

📄 ad.c

📁 rt 7520采集卡 linux驱动源代码
💻 C
字号:
/*	FILE NAME: ad.c	FILE DESCRIPTION:		Sample program for AD conversion using pacer clock without DMA.		Samples are read from the specified channel and then shown on		the screen		It is not recommended to use this program to get more samples		than FIFO size. For more samples, use DMA as it is shown in		"ad_dma" program.	PROJECT NAME: Linux DM7520 Driver, Library, and Example Programs	PROJECT VERSION: (Defined in README.TXT)	Copyright 2004 RTD Embedded Technologies, Inc.  All Rights Reserved.*/#include <stdio.h>	//printf
#include <stdlib.h>	//exit
#include <errno.h>	//errno
#include "dm7520_library.h"


#define BUFSIZE 512
int main(int argc, char * argv[])
{
 FILE * infile;		
 int16_t buffer[BUFSIZE]; //input buffer
 int cnt;
 int i;
 uint16_t fifostat; int devno;	//device handler
 // short sample;
 int channel;
 cg_entry_t cgl;
 uint16_t *z=(uint16_t*)&cgl; uint8_t	bus_master; if (argc<2) {fprintf(stderr,"Usage: %s <device> [channel]\n",argv[0]);exit(1);}

 if (NULL==(infile=fopen(argv[1],"r"))) 
   {
    fprintf(stderr,"Cannot open file, errno=%d\n",errno);
    perror("Error is");
    exit(2);
   }

 if (argc==3)
   {
    channel=atoi(argv[2])-1;
   } 
 else channel=0;

 if (channel<0 || channel>15) 
   {
    fprintf(stderr,"%s: Channel number not in valid range (1..16).\n",argv[0]);
    exit(1);
   }

 devno = fileno(infile);		// get device handler
 IsBusMaster7520(devno, &bus_master); if (bus_master != 0)    printf("Busmaster card\n"); else    printf("Non-busmaster card\n"); InitBoard7520(devno);


 ClearADFifo7520(devno);
 GetFifoStatus7520(devno, &fifostat); printf("\nFIFO status: %04X.\n",fifostat); 

 EnableCGT7520(devno,0);
 
 SetupCgtRow7520(&cgl,channel,0,0,0,0,0,0,0,0);
 
 WriteCGTLatch7520(devno,(uint16_t)*z);

 SetPacerStart7520(devno, PCLK_START_SOFTWARE);
 SetPacerStop7520(devno, PCLK_STOP_SOFTWARE);
 SetPacerRate7520(devno, 1000000);
 SetConversionSelect7520(devno, ADC_START_PCLK);
 
 StartPacer7520(devno);

 cnt=ReadData7520(devno, buffer,BUFSIZE);
 if (cnt!=BUFSIZE) printf("error while reading\n");
 StopPacer7520(devno);
 printf("Raw samples:");
 for (i=0;i<(cnt);i++)
   {
    if (0==i%8) printf("\n");
    printf("%5d ", buffer[i]/8);
 //need to devide by 8 to remove markers   }
 printf("\n");

 fclose(infile);
 return(0); 
}

⌨️ 快捷键说明

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