iirc_system_configure

PURPOSE ^

[sys_config, status]= iirc_system_configure( config_file )

SYNOPSIS ^

function [Data,ErrorFlag]= iirc_system_configure( config_file )

DESCRIPTION ^

 [sys_config, status]= iirc_system_configure( config_file )
 Configure the IIRC EIT system

 (C) 2006 tongin oh
 $Id: iirc_system_configure.m 1535 2008-07-26 15:36:27Z aadler $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Data,ErrorFlag]= iirc_system_configure( config_file )
0002 % [sys_config, status]= iirc_system_configure( config_file )
0003 % Configure the IIRC EIT system
0004 %
0005 % (C) 2006 tongin oh
0006 % $Id: iirc_system_configure.m 1535 2008-07-26 15:36:27Z aadler $
0007 
0008 ErrorFlag= 0;
0009 Data= struct;
0010 
0011 Data= USBGetNum(Data);
0012 Data= File_Load(config_file, Data);
0013 [Receive_Data, Response_Data] = SysInit(Data);
0014 Data= NVMC( Data );
0015 AGC(Data);
0016 AVG(Data);
0017 % FreqSet
0018 % SetMFCP
0019 % Scan_EIT_48
0020 % Save_ScanData
0021 %
0022 % Image_EIT(16, 1, Data.EIT_Setting_Information.FreqIndex)
0023 
0024 function Data= USBGetNum(Data)
0025 
0026     [USB_Status, Device_Num]=USB_GetNum();
0027     if USB_Status == 1
0028         D1 = 'USB Connection : ';
0029         D2 = int2str(Device_Num);
0030         MsgTemp = strcat(D1, D2);
0031         %     msgbox(MsgTemp);
0032         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033         % Device select
0034         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035         if Device_Num == 1
0036             Data.EIT_Setting_Information.Device_Sel = 0;
0037         elseif Device_Num == 2
0038             Data.EIT_Setting_Information.Device_Sel = 1;
0039         else
0040             error('Connected too many USB system !!!');
0041         end
0042         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044     else
0045         error('USB No Connection');
0046     end
0047 
0048 function Data= File_Load(File_Name, Data)
0049     fid = fopen(File_Name, 'r');
0050 % end
0051     Instruction = fgetl(fid);
0052     if strcmp(upper(Instruction), upper('File_Start')) == 1
0053         File_On = 1;
0054     end    
0055 
0056     while File_On == 1
0057         Instruction = fgetl(fid);
0058         if strcmp(upper(Instruction), upper('Total_Ch')) == 1
0059             Data.EIT_Setting_Information.Total_Channel = fscanf(fid, '%d', 1);
0060         elseif strcmp(upper(Instruction), upper('Frequency')) == 1
0061             Data.EIT_Setting_Information.Frequency_Num = fscanf(fid, '%d', 1);
0062             for j = 1 : Data.EIT_Setting_Information.Frequency_Num
0063                 Temp_Freq_Num = fscanf(fid, '%d', 1);
0064                 Temp_Freq_Unit = fscanf(fid, '%s', 1);
0065                 if strcmp(upper(Temp_Freq_Unit), upper('kHz')) == 1
0066                     Data.EIT_Setting_Information.Frequency(j) = Temp_Freq_Num * 1000;
0067                 elseif strcmp(upper(Temp_Freq_Unit), upper('Hz')) == 1
0068                     Data.EIT_Setting_Information.Frequency(j) = Temp_Freq_Num;
0069                 else
0070                     msgbox('Out of Frequency Range !!!');
0071                 end
0072                 
0073                 switch Data.EIT_Setting_Information.Frequency(j)
0074                     case 10,
0075                         Data.EIT_Setting_Information.FreqInfo(j)=0;
0076                         Data.EIT_Setting_Information.GICCH(j)=0;
0077                         Data.EIT_Setting_Information.FreqIndex(j)=1;
0078                     case 50,
0079                         Data.EIT_Setting_Information.FreqInfo(j)=1;
0080                         Data.EIT_Setting_Information.GICCH(j)=0;
0081                         Data.EIT_Setting_Information.FreqIndex(j)=2;
0082                     case 100,
0083                         Data.EIT_Setting_Information.FreqInfo(j)=2;
0084                         Data.EIT_Setting_Information.GICCH(j)=0;
0085                         Data.EIT_Setting_Information.FreqIndex(j)=3;
0086                     case 1000,
0087                         Data.EIT_Setting_Information.FreqInfo(j)=3;
0088                         Data.EIT_Setting_Information.GICCH(j)=0;
0089                         Data.EIT_Setting_Information.FreqIndex(j)=4;
0090                     case 5000,
0091                         Data.EIT_Setting_Information.FreqInfo(j)=4;
0092                         Data.EIT_Setting_Information.GICCH(j)=1;
0093                         Data.EIT_Setting_Information.FreqIndex(j)=5;
0094                     case 10000,
0095                         Data.EIT_Setting_Information.FreqInfo(j)=5;
0096                         Data.EIT_Setting_Information.GICCH(j)=2;
0097                         Data.EIT_Setting_Information.FreqIndex(j)=6;
0098                     case 50000,
0099                         Data.EIT_Setting_Information.FreqInfo(j)=6;
0100                         Data.EIT_Setting_Information.GICCH(j)=4;
0101                         Data.EIT_Setting_Information.FreqIndex(j)=7;
0102                     case 250000,
0103                         Data.EIT_Setting_Information.FreqInfo(j)=7;
0104                         Data.EIT_Setting_Information.GICCH(j)=32;
0105                         Data.EIT_Setting_Information.FreqIndex(j)=8;
0106                     case 500000,
0107                         Data.EIT_Setting_Information.FreqInfo(j)=8;
0108                         Data.EIT_Setting_Information.GICCH(j)=16;
0109                         Data.EIT_Setting_Information.FreqIndex(j)=9;
0110                     case 100000,
0111                         Data.EIT_Setting_Information.FreqInfo(j)=9;
0112                         Data.EIT_Setting_Information.GICCH(j)=8;
0113                         Data.EIT_Setting_Information.FreqIndex(j)=10;
0114                     otherwise,
0115                         msgbox('Undefined Frequency Range !!!');
0116                 end
0117                 ComplexReadFlag = 1;
0118                 while (ComplexReadFlag == 1)
0119                     ComplexOnOff = fgetl(fid);
0120                     if strcmp(upper(ComplexOnOff), upper('Complex_On')) == 1
0121                         switch Data.EIT_Setting_Information.FreqInfo(j)
0122                             case 0,
0123                                 Data.EIT_Setting_Information.FreqInfo(j)= 128;
0124                                 Data.EIT_Setting_Information.GICCH(j)=0;
0125                                 Data.EIT_Setting_Information.FreqIndex(j)= 11;
0126                             case 3,
0127                                 Data.EIT_Setting_Information.FreqInfo(j)= 131;
0128                                 Data.EIT_Setting_Information.GICCH(j)=1;
0129                                 Data.EIT_Setting_Information.FreqIndex(j)= 12;
0130                             case 6,
0131                                 Data.EIT_Setting_Information.FreqInfo(j)= 134;
0132                                 Data.EIT_Setting_Information.GICCH(j)=32;
0133                                 Data.EIT_Setting_Information.FreqIndex(j)= 13;
0134                             otherwise
0135                                 msgbox('Undefined Frequency Range !!!');
0136                         end
0137                         ComplexReadFlag = 0;
0138                     elseif strcmp(upper(ComplexOnOff), upper('Complex_Off')) == 1
0139                         ComplexReadFlag = 0;
0140                     end
0141                 end
0142             end
0143 %         elseif strcmp(upper(Instruction), upper('Complex_On')) == 1
0144 %                 Data.EIT_Setting_Information.Complex = 1;
0145 %         elseif strcmp(upper(Instruction), upper('Complex_Off')) == 1
0146 %                 Data.EIT_Setting_Information.Complex = 0;
0147         elseif strcmp(upper(Instruction), upper('Set_CP')) == 1
0148             for j = 1 : Data.EIT_Setting_Information.Frequency_Num
0149                 Data.EIT_Setting_Information.Total_Projection(j) = fscanf(fid, '%d', 1);
0150                 for k = 1 : Data.EIT_Setting_Information.Total_Projection(j)
0151                     for l = 1 : 3
0152                         Data.EIT_Setting_Information.Current_Injection_Pattern(j, k, l) = fscanf(fid, '%d', 1);
0153                     end
0154                 end
0155             end
0156         elseif strcmp(upper(Instruction), upper('AGC_ON')) == 1
0157             Data.EIT_Setting_Information.AGC_On_Off = 1;
0158         elseif strcmp(upper(Instruction), upper('AGC_OFF')) == 1        
0159             Data.EIT_Setting_Information.AGC_On_Off = 0;
0160             Data.EIT_Setting_Information.Digipot = fscanf(fid, '%d', 1);
0161         elseif strcmp(upper(Instruction), upper('AVG_ON')) == 1
0162             Data.EIT_Setting_Information.AVG_On_Off = 1;
0163             Data.EIT_Setting_Information.AVG_Num = fscanf(fid, '%d', 1);
0164         elseif strcmp(upper(Instruction), upper('AVG_OFF')) == 1        
0165             Data.EIT_Setting_Information.AVG_On_Off = 0;
0166         elseif strcmp(upper(Instruction), upper('Wait_Time_ON')) == 1
0167             Data.EIT_Setting_Information.Wait_Time_ON = 1;
0168             Data.EIT_Setting_Information.Wait_Time1 = fscanf(fid, '%d', 1);
0169             Data.EIT_Setting_Information.Wait_Time2 = fscanf(fid, '%d', 1);
0170             Data.EIT_Setting_Information.Wait_Time3 = fscanf(fid, '%d', 1);
0171         elseif strcmp(upper(Instruction), upper('ADC_Error_Check')) == 1
0172             Data.EIT_Setting_Information.ADCErrCHK = fscanf(fid, '%d', 1);
0173         elseif strcmp(upper(Instruction), upper('Calibration_File')) == 1   
0174             Cal_File = fgetl(fid);
0175         elseif strcmp(upper(Instruction), upper('Neighboring Injection')) == 1   
0176             Data.EIT_Setting_Information.Injection_Method = 0;
0177         elseif strcmp(upper(Instruction), upper('2D Diagonal Injection')) == 1   
0178             Data.EIT_Setting_Information.Injection_Method = 1;
0179         elseif strcmp(upper(Instruction), upper('3D Diagonal Injection')) == 1   
0180             Data.EIT_Setting_Information.Injection_Method = 2;
0181         elseif strcmp(upper(Instruction), upper('File_End')) == 1
0182             File_On = 0;  
0183             fclose(fid);
0184         end        
0185     end  
0186 
0187     load VM_Neighboring_Cal.mat
0188     Data.VMCal = VMCal;
0189 
0190     load CCS_CAL_Digipot_Value.mat
0191     Data.CCS_CAL_Digipot_Value = CCS_CAL_Digipot_Value;
0192 
0193     load Digipot_Value.mat
0194     Data.Digipot_Value = Digipot_Value;
0195 
0196 function [Receive_Data, Response_Data] = SysInit(Data)
0197     Dummy=51;
0198     Send_Data = [0 Data.EIT_Setting_Information.Total_Channel Dummy Dummy Dummy Dummy Dummy];
0199     [USB_Status Temp_Data Count] = Multi_USB_Comm(Data.EIT_Setting_Information.Device_Sel, Send_Data);
0200     if USB_Status == 0
0201         error('USB Read Error');
0202     end    
0203     Receive_Data = Temp_Data(1 : Count);
0204     Response_Data = [129 Send_Data(2 : 7)];
0205     if Receive_Data == Response_Data'
0206     %     msgbox('System Initial OK');
0207     else
0208         error('System Initial Error');
0209         Error_Flag=1;
0210     end
0211 
0212 function Data= NVMC(Data)
0213     Dummy=51;
0214     Send_Data = [4 Dummy Dummy Dummy Dummy Dummy Dummy];
0215 
0216     [USB_Status Temp_Data Count] = Multi_USB_Comm(Data.EIT_Setting_Information.Device_Sel, Send_Data);
0217     if USB_Status == 0
0218         error('USB Read Error');
0219     end    
0220     Receive_Data = Temp_Data(1 : Count);
0221 
0222     if Receive_Data(2) == Data.EIT_Setting_Information.Total_Channel
0223         Channel_Gap = 64 / Data.EIT_Setting_Information.Total_Channel;
0224         Data.Channel_List = 0 : Channel_Gap : Channel_Gap * (Data.EIT_Setting_Information.Total_Channel - 1);
0225         Data.Channel_List_Reverse = zeros(64, 1);
0226         for i = 1 : Data.EIT_Setting_Information.Total_Channel
0227             Data.Channel_List_Reverse(Data.Channel_List(i) + 1) = i;
0228         end
0229     %     msgbox(['NVMC ' num2str(Receive_Data(2)) ' OK']);
0230     else
0231         error(['NVMC Error(' num2str(Receive_Data(2)) ')']);
0232         Error_Flag=1;
0233     end
0234 
0235 function AGC( Data );
0236     Dummy = 51;
0237         
0238     if Data.EIT_Setting_Information.AGC_On_Off == 1
0239         Send_Data = [12 1 Dummy Dummy Dummy Dummy Dummy];
0240     else
0241         Send_Data(1 : 2) = [12 0];
0242         Send_Data(3 : 4) = Data.Digipot_Value(Data.EIT_Setting_Information.Digipot, :);
0243         Send_Data(5 : 7) = [255 Dummy Dummy];
0244     end    
0245 
0246     [USB_Status Temp_Data Count] = Multi_USB_Comm(Data.EIT_Setting_Information.Device_Sel, Send_Data);
0247     if USB_Status == 0
0248         error('USB Read Error');
0249     end    
0250     Receive_Data = Temp_Data(1 : Count);
0251 
0252     Response_Data = [141 Send_Data(2 : 7)];
0253     if Receive_Data == Response_Data'
0254     %     msgbox('AGC OK');
0255     else    
0256         error('AGC Error');
0257         Error_Flag=1;
0258     end
0259 
0260 function AVG( Data )
0261     Dummy = 51;
0262     if Data.EIT_Setting_Information.AVG_On_Off == 1
0263         Send_Data = [16 (Data.EIT_Setting_Information.AVG_Num - 1) Dummy Dummy Dummy Dummy Dummy];
0264     else    
0265         Send_Data = [16 0 Dummy Dummy Dummy Dummy Dummy];
0266     end
0267 
0268     [USB_Status Temp_Data Count] = Multi_USB_Comm(Data.EIT_Setting_Information.Device_Sel, Send_Data);
0269     if USB_Status == 0
0270         msgbox('USB Read Error');
0271     end    
0272     Receive_Data = Temp_Data(1 : Count);
0273 
0274     Response_Data = [145 Send_Data(2 : 7)];
0275     if Receive_Data == Response_Data'
0276     %     msgbox('AVG OK');
0277     else    
0278         msgbox('AVG Error');
0279         Error_Flag=1;
0280     end
0281

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005