EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
隔了好久没有进展了,主要原因是装matlab2005a的时候把win8的系统搞崩溃了,搞了几天无法修复,只好忍痛重新装了新的系统,时间耗费了大把大把的,就是个悲剧啊! 言归正传,前面已经完成了数据的传输,下面主要谈谈数据的显示,本来打算是用web来显示的,但目前对于我来说还是有不小的难度的,暂且用matlab来辅助显示,并分析一下数据的正确性吧 1、 硬件环境 硬件平台: Embest SoC --LarkBoard 软件平台:开发板-linux-3.10.31 Quartus 14.0
" d3 o- P5 `3 }& \ c( K
2、数据获取 前面已经完成了ADC的驱动了,并且能够正确的获取到数据,这次的任务是把得到数据存入到文件中,便于后期的数据处理和分析,很自然的需要编写一个应用程序,把ADC通道0的数据存入adc0_source,把ADC通道1的数据存入adc1_source,程序如下: - #include <stdio.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <math.h>
- #define POINT (1024)
- static unsigned int gSource_buff[POINT];
- int main(int argc, char* argv[])
- {
- int i = 0;
- int val;
- FILE * adc0Fp;
- FILE * adc1Fp;
- unsigned int tmp = 0;
- int fd;
- adc0Fp = fopen("/root/adc/adc0_source", "wb");
- if(!adc0Fp){
- perror("adc0_source open failed\n");
- return 1;
- }
- adc1Fp = fopen("/root/adc/adc1_source", "wb");
- if(!adc1Fp){
- perror("adc0_result open failed\n");
- return 1;
- }
- fd = open("/dev/adc/adc", O_RDONLY);
- if (fd == -1) {
- perror("device open error\n");
- return 1;
- }
- read(fd,gSource_buff,POINT*4);
- for(i=0;i<10;i++)
- printf("0x%x ",gSource_buff);
- printf("\n");
- for(i = 0;i < POINT; i++ ){
- tmp = gSource_buff&0x0000ffff; //chanel 0
- if( (tmp&0x800) != 0){ //negative
- tmp = (tmp | 0xfffff000);
- }
- fprintf(adc0Fp,"%d\n",tmp);
- tmp = (gSource_buff&0xffff0000)>>16; //chanel 1
- if( (tmp&0x800) != 0){ //negative
- tmp = (tmp | 0xfffff000);
- }
- fprintf(adc1Fp,"%d\n",tmp);
- }
- return 0;
- }
# R M9 n6 I: w8 \5 S L
, z' Z* N* Z; ]4 s
! ?% O+ G- m; P, L) p% X- j$ M; W4 j6 v; d! |5 G; ]8 I
3、编写一个matlab程序,读取文件,并做FFT分析 - clear all;
- close all;
- N=1024;
- fid_adc1 = fopen('adc1_source','r');
- adc1_data = fscanf(fid_adc1,'%d');
- fclose(fid_adc1);
- figure;
- subplot(2,1,1);
- plot(adc1_data);
- x = adc1_data';
- y = fft(x,N);
- subplot(2,1,2);
- plot(2*abs(y(1:N/2+1)));( |8 O" D, g$ T$ Y% `# y9 x
h( G1 F4 P9 m/ M- A* H9 |2 H7 Q" h- F# V$ {
9 \4 q3 W( T# j3 I, B* q4、测试结果 1) 正弦信号 9 ^5 J# M. B/ t' n; j
: J; [: T( p7 x$ i/ ~' h
2)方波信号
4 h5 f) F. x! Z" M R3)三角波信号 ( L/ x, p+ N' p( |% F$ I
5、小结 1) 方波信号感觉怪怪的,畸变的比较严重,看的很明显;三角波信号在下面的时候也有一点畸变,原因不是很明确,我估计是硬件电路设计的问题; 2) 从matlab分析的结果来看,信号获取应该是没什么问题了; 3) 怎么用web显示这些结果呢?对于我来说是个头疼的问题,进一步努力吧 : N) B; y; Y3 Z/ f
|