Main Content

PWM输出

Generate square wave on the specified output pin

  • 图书馆:
  • 金宝appNXP FRDM-K金宝appL25Z董事会/FRDM-KL25Z的Simulink编码器支持包

  • PWM输出块

描述

PWM输出块为板上的指定引脚生成方波脉冲并输出。您可以作为块输入提供0-100之间的值。您提供的输入值控制脉冲波形的占空比。输入值的0产生0%的占空比和输入值100产生100%的占空比。

Ports

Input

展开全部

有效输入值的范围是0100。这input controls the duty cycle (width of the square wave) of the square waveform.

输入值的0产生0%的占空比和输入值100产生100%的占空比。任何范围的值,例如500or-500,在块上,输入端口的效果与最大或最小输入值相同。

数据类型:单身的|双倍的|int8|int16|int32|UINT8|uint16|UINT32|布尔

参数

展开全部

要查看板上的针映射,请单击查看引脚地图。On the board, each PWM pin is connected to either of the three timers, TPM0 (Timer PWM Module), TPM1, or TPM2. To learn about the Timer Channel Pin combination, see the Timer to Pin Mapping table in the计时器/PWM模块参数说明部分。

董事会有三个计时器TPM0,TPM1和TPM2。每个PWM引脚都连接到这三个计时器之一。当您在Pin列表,此参数填充了引脚连接到的计时器。例如,如果选择PTA1(D0)pin, this parameter is set toTPM2

这following table shows timer to pin mapping.

在您的模型中,如果您有多个实例PWM输出块,使用不同的计时器通道组合for every block instance. Otherwise, you receive an error message indicating you to use GPIO Pins from different Timer Channel combination for all the block instances.

For example, suppose that in onePWM输出块实例您选择PTC3引脚生成输出。这PTC3引脚连接到CH2 channel of the TPM0 timer. When selecting a pin for the other instances of thePWM输出block, select a pin that belongs to a timer channel combination other than TPM0 CH2.

依赖性

This parameter appears dimmed.

初始化时,块将其占空比设置为您在此参数中指定的值。

例子

此示例显示了如何使用PWM输出控制连接到蓝色LED的亮度的块D13钉在板上。

  1. 将FRDM-KL25Z硬件连接到您的计算机。

  2. 在Simuli金宝appnk中®编辑,打开一个新的模型窗口。在库浏览器中,复制一个Constantblock and aPWM输出阻止并连接它们。

  3. 设置值Constant块到50。该值表示输出方波的占空比百分比。

  4. In the Block Parameter dialog box, set the Pin toD13and the Initial duty cycle to0

  5. 在Simuli金宝appnk编辑器中,选择Simulation>Model Configuration Parameters

  6. 在“配置参数”对话框中,单击硬件实现

  7. 设置硬件板参数到NXP FRDM-KL25Z。

  8. 要设置输出信号的频率,请确定计时器D13pin is connected.

    要标识计时器,在“块参数对话框”中,单击查看引脚地图。在PIN地图中,搜索D13引脚和计时器名称旁边。这D13引脚连接到TMP0别针。

  9. In the Configuration Parameters dialog box, set theTPM0频率(以Hz为例)50。使用频率值,块计算了方波的周期。

    周期= 1/50 = 0.02秒

当您构建模型并将其加载到硬件上时PWM输出块生成方波脉冲,脉冲宽度为(50* 0.02)/100 = 0.01秒。蓝色LED打开0.01秒,然后在接下来的0.01秒中关闭。您可以迅速眨眼和关闭LED,以控制其亮度PWM输出堵塞。

版本历史记录

在R2016b中引入