资源简介
基于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
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论