LabVIEW由三角波产生PWM
此代码组件演示如何使用锯齿波生成PWM 信号。该示例将正弦波与三角波形进行比较。产生的PWM信号是比较器的输出。
此代码设计为在单周期定时循环中运行,但也包含一个时钟deriver,允许代码以基本时钟频率的整数分数运行(由“除数”控件定义)。还有一个布尔值来重置时钟deriver。下图显示了与5kHz正弦波一起使用的PWM发生器的示例以及与之配合的框图。附件包括PWM发生器模块本身以及其在单周期定时循环中的使用示例。
如果将直流信号馈送到比较器,则输出为PWM信号,其占空比恒定等于直流信号与三角波峰值之比。如果将其他模拟波形发送到比较器,PWM输出会变化以对应于模拟波形。
此代码可以通过用各种版本的锯齿查表替换三角波来扩展到不同版本的PWM发生器。
注意:“TriangleWavePWMGentest.vi”中的测试代码用于演示块在基于 Windows 的系统上的行为。如果不进行一些更改,它不会直接编译为FPGA。但是,“simpleFPGA test.vi”中的代码将编译并生成一个指示器,该指示器在0.5Hz的PWM范围内循环。
执行代码的步骤
LabVIEW 开发环境
打开TrianglePWM.lvproj文件
打开TriangleWavePWMGenTest.vi
运行 VI
请注意,正确的PWM波是从顶部图上的两个信号生成的。
LabVIEWFPGA
更新 FPGA 目标以匹配配置
编译并运行简单Simple FPGA Test.vi
要求
LabVIEW2010 FPGA 模块 “或兼容”
Thiscomponent of code shows how to use a sawtooth to generate a PWM signal. The example compares a sinewave to a trianglewaveform. The PWM signal generated isthe output of the comparator.
Description
This codehas been designed to run in a single-cycle timed loop, but also contains aclock deriver that allows the code to run at an integer fraction of the baseclock frequency (defined by the "Divisor" control). There is also a boolean to reset the clockderiver. The following images shows anexample of the PWM generator being used with a 5kHz sinewave as well as theblock diagram to go with it. Theattached files include the PWM generator block itself as well as an example ofits use in a single-cycle timed loop.
If a DCsignal is fed to the comparator, the output is a PWM signal with a constantduty cycle that is equal to the ratio of the DC signal to the peak value of thetriangle wave. If some other analogwaveform is sent to the comparator, the PWM output varies to correspond to theanalog waveform.
This codecould be extended to a different version of a PWM generator by replacing thetriangle wave with various versions of a sawtooth look-up table.
NOTE: thetest code in "TriangleWavePWMGen test.vi" is to demonstrate thebehavior of the block on a Windows-based system. It won't directly compile to FPGA withoutsome changes. However, the code in"simple FPGA test.vi" will compile and will generate an indicatorthat cycles through the PWM range at 0.5Hz.
Steps toExecute Code
LabVIEWDevelopment Environment
Open theTrianglePWM.lvproj file
Open theTriangleWavePWMGenTest.vi
Run theVI
Noticethat the correct PWM wave being generated from the two signals on the top plot.
LabVIEWFPGA
Updatethe FPGA target to match your configuration
Compile andrun the Simple FPGA Test.vi
需要说明的是,上述的例程和文档,都是可以下载的,双击即可打开,其中压缩文件是可以采用粘贴复制的方式,拷贝到硬盘上。这不是图片,各位小伙伴看到后尝试一下,这个问题就不用加微信咨询了。有关LabVIEW编程、LabVIEW开发等相关项目,可联系们。附件中的资料这里无法上传,可去公司网站搜索下载。
LabVIEW程序,如下附件所示。