资源简介
基于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
相关资源
- 经典MUSIC算法MATLAB仿真,带详细注释
- dft函数matlab代码
- matlab傅里叶级数展开程序
- 颜色CIEDE2000matlab程序
-
卡尔曼滤波器在simuli
nk 中的实现 - QPSK调制解调过程的MATLAB仿真
- MATLAB-GWR-地理加权回归模型-代码
- 偏最小二乘法总算法matlab代码
- K近邻法 模板 0-9数字识别 matlab
- 数字语音处理及matlab仿真配套代码完
- 阴影去除资源matlab
- 用MATLAB对两幅图片进行图像匹配的实
- 频域外推EC的matlab代码
- 用matlab实现最大最小距离聚类算法
- matlab语音信号特征值提取
- 基于遗传算法的柔性车间调度.rar
-
基于matlab的simuli
nk实现2ask2fsk2psk的数 - matlab 画双曲线代码
- 克里金插值的matlab实现
- matlab仿真高斯信道下的QPSK误码率,有
- 基于PR调节器的单相PWM整流器的simul
- 基于MATLAB的多元非线性回归模型
- 基于matlab的粒子群算法PSO工具箱
- 基于matlab线性回归模型负荷预测
- pso-SVM的MATLAB程序
- Matlab仿真窄带随机过程
- MATLAB 复数拟合
- MP匹配追踪算法Matlab仿真
- 三相桥式整流电路
- 3自由度机械臂正逆解matlab.zip
评论
共有 条评论