Skip to content

Commit e09c7c9

Browse files
committed
Update CustomLib
1 parent 17c5a76 commit e09c7c9

14 files changed

+186
-0
lines changed

04_CustomLib_Sample/ADCCallback.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
classdef ADCCallback
2+
3+
methods(Static)
4+
5+
% Following properties of 'maskInitContext' are available to use:
6+
% - BlockHandle
7+
% - MaskObject
8+
% - MaskWorkspace: Use get/set APIs to work with mask workspace.
9+
function MaskInitialization(maskInitContext)
10+
maskObj = maskInitContext.MaskObject; %マスクワークスペースオブジェクト取得
11+
%パラメータ更新関数の呼び出し
12+
updateADCMaskParam(maskObj);
13+
14+
end
15+
16+
% Use the code browser on the left to add the callbacks.
17+
18+
19+
function ADC_QuantBit(callbackContext)
20+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
21+
maskObj = Simulink.Mask.get(blkHandle);
22+
%パラメータ更新関数の呼び出し
23+
updateADCMaskParam(maskObj);
24+
end
25+
26+
function MaxRange(callbackContext)
27+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
28+
maskObj = Simulink.Mask.get(blkHandle);
29+
%パラメータ更新関数の呼び出し
30+
updateADCMaskParam(maskObj);
31+
end
32+
33+
function MinRange(callbackContext)
34+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
35+
maskObj = Simulink.Mask.get(blkHandle);
36+
%パラメータ更新関数の呼び出し
37+
updateADCMaskParam(maskObj);
38+
end
39+
end
40+
end

04_CustomLib_Sample/PWMCallback.m

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
classdef PWMCallback
2+
3+
methods(Static)
4+
5+
% Following properties of 'maskInitContext' are available to use:
6+
% - BlockHandle
7+
% - MaskObject
8+
% - MaskWorkspace: Use get/set APIs to work with mask workspace.
9+
function MaskInitialization(maskInitContext)
10+
11+
maskWS = maskInitContext.MaskWorkspace; %マスクワークスペースオブジェクト取得
12+
%マスクワークスペースにマスクエディタで指定したパラメータが格納されています。
13+
%MaskWorkspaceオブジェクトのgetメソッドでパラメータ名を指定して利用することで値を取得できます。
14+
fsw = maskWS.get('fsw');
15+
PWM_Resolution = maskWS.get('PWM_Resolution');
16+
DeadTimeRangeNum = maskWS.get('DeadTimeRange');
17+
18+
%初期化関数内であれば、マスクパラメータの値を更新したいときにはsetメソッドが利用できます
19+
maskWS.set("DeadTime",1/fsw*PWM_Resolution*DeadTimeRangeNum);
20+
maskWS.set("TimerCountMax", 1/ PWM_Resolution);
21+
22+
end
23+
24+
25+
function fsw(callbackContext)
26+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
27+
maskObj = Simulink.Mask.get(blkHandle);
28+
%パラメータ更新関数の呼び出し
29+
updatePWMMaskParam(maskObj);
30+
end
31+
32+
function PWM_Resolution(callbackContext)
33+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
34+
maskObj = Simulink.Mask.get(blkHandle);
35+
%パラメータ更新関数の呼び出し
36+
updatePWMMaskParam(maskObj);
37+
end
38+
39+
function DeadTimeRange(callbackContext)
40+
blkHandle = callbackContext.BlockHandle; % Block Handle of this block
41+
maskObj = Simulink.Mask.get(blkHandle);
42+
%パラメータ更新関数の呼び出し 
43+
updatePWMMaskParam(maskObj);
44+
end
45+
end
46+
end
-5.98 KB
Binary file not shown.
6.35 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%PWMGeneratorが持っているマスクパラメータの更新
2+
function updateADCMaskParam(maskObj)
3+
4+
%パラメータ値の取得
5+
ADC_QuantBit_str = maskObj.getParameter('ADC_QuantBit').Value;
6+
MaxRange_str = maskObj.getParameter('MaxRange').Value;
7+
MinRange_str = maskObj.getParameter('MinRange').Value;
8+
9+
%変数の評価実施
10+
ADC_QuantBit= safeEval(ADC_QuantBit_str);
11+
MaxRange = safeEval(MaxRange_str);
12+
MinRange = safeEval(MinRange_str);
13+
14+
%計算の実施
15+
QuantResolution = 1/(2^ADC_QuantBit);
16+
QuantUnit = (MaxRange - MinRange) * QuantResolution;
17+
18+
%更新値を代入
19+
maskObj.getParameter('QuantResolution').Value = num2str(QuantResolution);
20+
maskObj.getParameter('QuantUnit').Value = num2str(QuantUnit);
21+
22+
end
23+
24+
25+
function val = safeEval(expr)
26+
try
27+
val = evalin('base', expr); % ベースワークスペースで評価
28+
if ~isnumeric(val)
29+
val = [];
30+
end
31+
catch
32+
val = [];
33+
end
34+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%PWMGeneratorが持っているマスクパラメータの更新
2+
function updatePWMMaskParam(maskObj)
3+
4+
%パラメータ値の取得
5+
fsw_str = maskObj.getParameter('fsw').Value;
6+
PWM_Resolution_str = maskObj.getParameter('PWM_Resolution').Value;
7+
DeadTimeRange_str = maskObj.getParameter('DeadTimeRange').Value;
8+
9+
%変数の評価実施
10+
fsw = safeEval(fsw_str);
11+
PWM_Resolution = safeEval(PWM_Resolution_str);
12+
DeadTimeRange = safeEval(DeadTimeRange_str);
13+
14+
%計算の実施
15+
TimerCountMax = 1/ PWM_Resolution;
16+
DeadTime = 1/fsw*PWM_Resolution*DeadTimeRange;
17+
18+
%更新値を代入
19+
maskObj.getParameter('TimerCountMax').Value = num2str(TimerCountMax);
20+
maskObj.getParameter('DeadTime').Value = num2str(DeadTime);
21+
22+
end
23+
24+
25+
function val = safeEval(expr)
26+
try
27+
val = evalin('base', expr); % ベースワークスペースで評価
28+
if ~isnumeric(val)
29+
val = [];
30+
end
31+
catch
32+
val = [];
33+
end
34+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="ADCCallback.m" type="File"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="updateADCMaskParam.m" type="File"/>

0 commit comments

Comments
 (0)