首页->【超声成像实验室】

8 1

       在前面的一篇文章中提到了QuartusII 逻辑分析仪高级触发条件存储数据案例,实际在调试过程中遇到了这个需求,即需要在MATLAB下读取Quartus II 逻辑分析仪高级触发条件生成的多通道数据文件。对文件里面的数据内容进行分析,由于fpga的器件的ram限制所以对高级触发模式为数多通道数据的抓取提供了可能。

      多通道下数据生成的数据文件类似于如图:其中 文件包含了信号名称,以及信号数据,sample为采样时刻,key:0~10代表信号名称,3位十六进制为数据 key:3~10为分析的数据,共8组。

chdata1.png


function [chasam] = freadListFileFromSTPVIII(fsimpathstp,sampleDepth,dataLenth)
%READLISTFILEFROMSTP
% In para  
% fsimpathstp : STP List File Path,
% fsimpathcha,fsimpathchb: storage files path
% sampleDepth  :Quartus STP Sample Depth
% dataLenth    :12 Or 16bits
% Output Para :
% chasam,chbsam
% format enable signal  
% Vailid signal
line=0;
chasam=ones(8,sampleDepth);
rown=1;
fileIdsimch=fopen(fsimpathstp);
switch(dataLenth)    
    case 12
        DataLen=2048;
        DataMaxValue=4096;
        childsize =3;
    otherwise
        DataLen=32768;
        DataMaxValue=65536;
        childsize=4;
end
while ~feof(fileIdsimch)
    t=fgetl(fileIdsimch);
    if line > 23       
                [~,row]=size(t);
                chhdatatxt=t(row-15-8*childsize:row-15-7*childsize);%ch1
                chgdatatxt=t(row-13-7*childsize:row-13-6*childsize);%ch2
                chfdatatxt=t(row-11-6*childsize:row-11-5*childsize);%ch3
                chedatatxt=t(row-9-5*childsize:row-9-4*childsize);%ch4
                
                chddatatxt=t(row-7-4*childsize:row-7-3*childsize);% ch5            
                chcdatatxt=t(row-5-3*childsize:row-5-2*childsize);%ch6
                chbdatatxt=t(row-3-2*childsize:row-3-childsize);%ch7
                chadatatxt=t(row-1-childsize:row-1); %  ch8         
                t1=chadatatxt(1,1:childsize);% txt format : aaaah  
                t2=chbdatatxt(1,1:childsize);% txt format : aaaah
                t3=chcdatatxt(1,1:childsize);% txt format : aaaah
                t4=chddatatxt(1,1:childsize);% txt format : aaaah  
                
                t5=chedatatxt(1,1:childsize);% txt format : aaaah
                t6=chfdatatxt(1,1:childsize);% txt format : aaaah
                t7=chgdatatxt(1,1:childsize);% txt format : aaaah  
                t8=chhdatatxt(1,1:childsize);% txt format : aaaah
                
                a1=hex2dec(t1);
                a2=hex2dec(t2);
                a3=hex2dec(t3);
                a4=hex2dec(t4);
                a5=hex2dec(t5);
                a6=hex2dec(t6);
                a7=hex2dec(t7);
                a8=hex2dec(t8);
                a=[a8,a7,a6,a5,a4,a3,a2,a1];

               %负数操作

                for cnt=1:8
                    if a(cnt)>=DataLen
                            a(cnt)=-1*(DataMaxValue-a(cnt));
                    end  
                    chasam(cnt,rown)=a(cnt);
                end                
                rown=rown+1;                
   end
    line =line+1;
end
fclose(fileIdsimch);
%%prevent the error with the different size of namesize  
end


作者于2018-01-29 15:50:17修改!
楼主可见

  1. shwnyoo 1#

    该例程为读者提供了思路,供参考