?? sfunusbda.m
字號:
function [sys,x0,str,ts] = sfunUsbDA(t,x,u,flag,ch,tempT,detaT)
%sfunUsbDA 是利用www.dzmi.com網站設計的usb數據采集卡的DA輸出的S函數。
%ch為采集的通道號。1-2代表DA的ch1到ch2。
%tempT為采集卡的實際采樣速率
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts] = mdlInitializeSizes;
%%%%%%%%%%
% Output %
%%%%%%%%%%
case 3,
sys = mdlOutputs(t,x,u,ch,tempT,detaT);
case { 1, 2, 4, 9 }
sys=[];
otherwise
error(['unhandled flag = ',num2str(flag)]);
end
%end sfundsc2
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;%沒有狀態變量
sizes.NumOutputs = 0;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [-1 0]; % 繼承前面的采樣周期
% end mdlInitializeSizes
%
%=======================================================================
% mdlOutputs
% Return the output vector for the S-function
%=======================================================================
%
function sys = mdlOutputs(t,x,u,ch,tempT,detaT)
sys = [];
Send_Data(u,ch); %發送數據u給OUT1通道。
pause(tempT-detaT);%此處和Ts的區別在于:Ts確定了示波器橫坐標數值,
%而此處是輸出速度的真實時間值。嚴格來講,此處應該減去一個常量:usb傳輸和輸出的時間。以
%確保Ts和DA輸出速度的盡量一致。假定此常量為0.008.可通過仿真時間與實際時間的比較估算.
%end mdlOutputs
%———以下函數不要輕易改動———————————————————————————
function Send_Data(temp,channel)
%函數名稱:function Send_Data(temp,channel)
%入口參數:temp為輸入數據,10位精度。channel為通道選擇。
%出口參數:無
%函數功能:發送指定電壓到DA。
tempH=fix(temp/256);%將一個10進制數轉化成兩個字節。
tempL=mod(temp,256);
dzmiUSB(1,channel,tempH,tempL);
%--------------------------------------------------------------------------
function data = Read_Data(channel)
%函數名稱:function data=Read_Data(channel)
%入口參數:channel為通道選擇
%出口參數:data為接收到的數據。10位精度。
%函數功能:讀取指定通道的數據。
data=dzmiUSB(0,channel);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -