📄 etrig.c
字号:
/* FILE NAME: etrig.c FILE DESCRIPTION: Demonstrates usage of an external trigger. Digital I/O port 1 bit 0 (pin number 46) is used to generate the external trigger. This pin must be connected to the Trigger Input pin (pin number 47). A/D conversion starts on an external trigger. A positive edge starts conversion unless 'n' is passed in as the second command line argument, which means a negative edge starts conversion. 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 <slang/slang.h> //for anykey
#include <unistd.h> //sleep#include "dm7520_library.h"int anykey(void) {
int x;
SLang_init_tty(-1, 1, 1);
x = SLang_getkey();
SLang_reset_tty();
return x;
}
int main(int argc, char * argv[]){ FILE * infile; int devno; //device handler char negative = 0; cg_entry_t cgl; uint16_t *z=(uint16_t*)&cgl; uint8_t fifo_empty; if (argc<2) {fprintf(stderr,"Usage: %s <device> [n]\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) if (argv[2][0]=='n') negative = 1; //use negative edge of external trigger
devno = fileno(infile); // get device handler
InitBoard7520(devno); ClearADFifo7520(devno); EnableCGT7520(devno,0); SetupCgtRow7520(&cgl,0,0,0,0,0,0,0,0,0); WriteCGTLatch7520(devno,(uint16_t)*z);
SetDIO1Direction7520(devno, 1); //set port1 to output
WriteDIO17520(devno,0);
// init DIO
SetPacerStart7520(devno, PCLK_START_ETRIG); //pacer start on external trigger
SetEtrgPolarity7520(devno, negative); //set ext. trigger polarity if (negative) printf ("Using external trigger, negative edge\n"); else printf ("Using external trigger, positive edge\n"); SetPacerStop7520(devno, PCLK_STOP_SOFTWARE); SetPacerRate7520(devno, 1000000); SetConversionSelect7520(devno, 1);
//pacer clock StartPacer7520(devno); //arm the trigger printf("Press any key for positive edge of external trigger\n");
anykey();
WriteDIO17520(devno,1);
usleep(10); IsADFifoEmpty7520(devno, &fifo_empty); if (fifo_empty){
printf("Conversion is not started\n");
printf("Press any key for negative edge of external trigger\n");
anykey();
WriteDIO17520(devno,0);
usleep(10);
IsADFifoEmpty7520(devno, &fifo_empty); if (fifo_empty){
printf("Conversion is not started\n");
}
else { printf("Conversion is started\n"); } }
else {
printf("Conversion is started\n");
} printf("Press any key to exit the program\n"); anykey(); fclose(infile); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -