基于simulink的s-function的PWM生成

基于simulink的s-function的PWM生成

simulink真是无所不能,不仅可以仿真电路,生成代码,还可以将自己的代码放在仿真里运行,这里基于sfun写一个PWM生成器,便于sfun的学习

模型

设置sfun的函数名和参数,其中有两个参数和两个输入信号,
两个参数分别是输出波形的幅值和模型运行的分辨率,这里设置幅值为5,分辨率为10k
两个输入信号分别是占空比和周期值,这里设置占空比为50%,周期为40ms(25hz)
注:分辨率要大于PWM的周期值
在这里插入图片描述
在这里插入图片描述

仿真结果如下:在这里插入图片描述

代码

/* 
 * 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.
 * 
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值