資源簡介
基于simulink的s-function的PWM生成,注釋詳細,可以更好的便于學習simulink的sfun的編寫

代碼片段和文件信息
/*?
?*?File?????:?sfun_pwm.c
?*?Abstract:
?*???
?*???This?file?represents?an?S-function?example?which?demonstrates?the?S-function?macros?for?using?a
?*???controllable?sample?time.?This?S-function?generates?PWM?(Pulse-width?modulation)?signals?based
?*???on?the?input?period?and?duty?cycle?signals.
?*
?*???This?S-function?registers?a?controllable?sample?time?with?which?the?S-function?can?schedule?the
?*???next?hit?when?changing?the?output?value.?The?S-function?has?two?input?ports?and?one?output
?*???port.?The?first?input?port?is?the?duty?cycle?signal?and?the?second?is?the?period?signal.?The
?*???S-function?has?two?block?parameters:?the?amplitude?of?the?generated?PWM?signal?and?the
?*???resolution?of?the?controllable?sample?time.
?*?
?*???This?S-function?illustrates?the?use?of?the?S-function?macro:
?*???????
?*????????ssSetControllableSampleTime(S?0?resolution)
?*
?*???to?register?a?controllable?sample?time?in?mdlInitializeSampleTimes().?The?resolution?must?be?a
?*???positive?finite?number?that?defines?the?fundamental?step?size?that?the?S-function?can?schedule
?*???the?next?hit?for?this?sample?time.
?*
?*???This?S-function?illustrates?the?use?of?the?S-function?macro:
?*
?*???????ssSetNumTicksToNextHitForControllableSampleTime(S?0?numTick)
?*??
?*???to?schedule?the?next?hit?of?the?controllable?sample?time.?The?next?hit?happens?after?t?=
?*???t_current?+?numTick?*?resolution.?numTick?must?be?a?positive?integer.?The?S-function?must?use
?*???this?macro?to?schedule?the?execution?of?the?controllable?sample?time?in
?*???mdlInitializeConditions()?and?mdlOutputs().
?*
?*?Copyright?2017?The?MathWorks?Inc.
?*/
#define?S_FUNCTION_NAME?mysfun_generate??????????????????????????//函數名
#define?S_FUNCTION_LEVEL?2???????????????????????????????????????//sfun的深度
#include?“simstruc.h“
#include?“assert.h“
/*?Function:?mdlInitializeSizes?================================================
?*?Abstract:
?*
?*???Register?an?S-function?with?two?input?ports?one?output?port?and?three?DWorks.?Specify?the
?*???number?of?sample?times?to?1.
?*
?*/
static?void?mdlInitializeSizes(SimStruct*?S)
{
????//這個函數用來初始化的,主要是設置輸入、輸出和參數的。
????
????if?(!ssSetNumInputPorts(S?2))?return;//設置輸入信號2個
????ssSetInputPortWidth(S?0?1);//設置輸入變量0的維數為1
????ssSetInputPortDirectFeedThrough(S?0?1);//?設置輸入端口的信號是否mdlOutputs函數中使用,這兒設置為true
????ssSetInputPortWidth(S?1?1);//設置輸入變量1的維數為1
????ssSetInputPortDirectFeedThrough(S?1?1);//?設置輸入端口的信號是否mdlOutputs函數中使用,這兒設置為true
????
????if?(!ssSetNumOutputPorts(S?1))?return;//設置輸出變量的個數
????ssSetOutputPortWidth(S?0?1);//設置輸出變量0的維數為1維
????ssSetNumSFcnParams(S?2);//設置參數2個
????if?(ssGetNumSFcnParams(S)?!=?ssGetSFcnParamsCount(S))?{
????????return;
????}
????
????ssSetNumContStates(S?0);//設置連續狀態變量的
????ssSetNumDiscStates(S?0);
????ssSetNumDWork(S?3);
????ssSetDWorkWidth(S?0?1);//設置離散狀態變量的
????ssSetDWorkDataType(S?0?SS_BOOLEAN);
????ssSetDWorkWidth(S?1?1);
????ssSetDWorkDataType(S
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6992??2020-06-03?23:17??mysfun_generate.c
?????文件??????20480??2020-06-03?22:48??mysfun_generate.mexw64
?????文件??????24325??2020-06-03?22:51??generate.slx
-----------?---------??----------?-----??----
????????????????51797????????????????????3
- 上一篇:經典MUSIC算法MATLAB仿真,帶詳細注釋
- 下一篇:ofdm_dmt.m
評論
共有 條評論