📄 da.c
字号:
/* FILE NAME: da.c FILE DESCRIPTION: D/A conversion without DMA. Samples are loaded directly into the DAC1 and DAC2 FIFO. The samples are used for waveform generation. DAC1 generates a square wave and DAC2 generates a complex wave form consisting of three sine periods with different amplitudes If 'r' is passed in as the second command line argument, the D/A FIFOs are reset whenever two-thirds of the waveform has been generated. The D/A 1 Update Counter is used to keep track of the number of conversions. When operating in this manner, the same wave forms are generated but one-third of their length is cut off. SyncBus signals control D/A 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 <unistd.h> //sleep#include <errno.h> //errno#include <stdlib.h> //exit#include <math.h> //sin#include "dm7520_library.h"#define DABUFFERSIZE 1000 //can not be more then FIFO size//resetDAFIFOs//this function is used in resetDA mode to reset DA FIFOint wave = 0;int devno;void resetDAFIFOs(void) { ResetDAC1Fifo7520(devno); ResetDAC2Fifo7520(devno); wave++;}int main(int argc, char * argv[]){ FILE * infile; int i; short sample; float fok,val; int resetDA = 0; if (argc<2) {fprintf(stderr,"Usage: %s <device> [r]\n",argv[0]);exit(1);} if (3==argc) { if ('r' == *(argv[2])) { // reset mode resetDA = 1; } } if (NULL==(infile=fopen(argv[1],"r"))) //open device. Enough to open for reading only { fprintf(stderr,"Cannot open file, errno=%d\n",errno); perror("Error is"); exit(2); } devno = fileno(infile); // device handler InitBoard7520(devno); //Initialize the device ClearDAC1Fifo7520(devno); ClearDAC2Fifo7520(devno); sample=2047<<3;
// set up the buffer for the first half of wave form 1 for (i=0;i<DABUFFERSIZE/2;i++){ WriteDac1Fifo7520(devno,sample); // load to fifo DAC1 } sample=(-2047)<<3;
// set up the buffer for the second half of wave form 1 for (i=0;i<DABUFFERSIZE/2;i++){ WriteDac1Fifo7520(devno,sample); // load to fifo DAC1 }// set up the buffer for the wave form 2 for (i=0;i<DABUFFERSIZE;i++) { fok =(float)i*(2*M_PI/(float)DABUFFERSIZE); val=sin(fok)+sin(fok*3)+sin(fok*5)+sin(fok*7)+sin(fok*9);
sample=((int16_t)(2047*val/5.))<<3;
WriteDac2Fifo7520(devno,sample); // load to fifo DAC2 } if (resetDA) { SetupDAC7520(devno,DM7520_WRITE_DA1,AOUT_BIP5,DAC_CYCLE_MULTI,DAC_START_SBUS1); // set up wave form1 SetupDAC7520(devno,DM7520_WRITE_DA2,AOUT_BIP5,DAC_CYCLE_MULTI,DAC_START_SBUS2); //set up wave form 2 SetUtc2Clock7520(devno, CUTC2_8MHZ); SetupSbus7520(devno,1, SBUS1_UTC2,1); SetupSbus7520(devno,2, SBUS2_UTC2,1); Set8254Mode7520(devno, TC_UTC2, M8254_SQUARE_WAVE); Set8254Divisor7520(devno, TC_UTC2,8000000/10000); //start da coversion at 10 kHz wave = 0; LoadUcnt17520(devno,DABUFFERSIZE*2/3); SetNotification7520(devno, (unsigned short) IRQS_DAC1_UCNT,resetDAFIFOs); while (wave<200); // generate 200 periods of the wave form UnSetNotification7520(devno); } else { SetupDAC7520(devno,DM7520_WRITE_DA1,AOUT_BIP5,DAC_CYCLE_MULTI,DAC_START_DAC_CLK); // set up wave form1 SetupDAC7520(devno,DM7520_WRITE_DA2,AOUT_BIP5,DAC_CYCLE_MULTI,DAC_START_DAC_CLK); //set up wave form 2 SetDACRate7520(devno, 10000); //start da coversion at 10 kHz sleep(10); // generate waveforms for 10 seconds } fclose(infile); // close device return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -