主要内容

浮点支持:定向控制算法金宝app

在这个例子中你审查定向控制(FOC)算法的永磁同步电机(永磁同步电动机)实现使用单精度和half-precision浮点类型。

介绍

你有见过这种设计的定点版本磁场定向控制的永磁同步机这需要深入了解如何使用定点实现电流控制算法类型。该模型转换为定点生成HDL代码之前。

你可以使用浮点单精度类型设计和生成HDL代码本身没有皈依定点类型。这个例子展示了生成代码时的设计考虑从浮点单精度和half-precision定点模型的变体hdlcoderFocCurrentFixptHdl

testbench模型hdlcoderFocCurrentTestBench有一个参考块指向DUT定点或浮点实现。

特色的本地浮点支持金宝app

  • 供应商独立和目标无关的RTL FPGA和ASIC设计

  • 全方位的ieee - 754功能包括支持舍入模式,正无穷和nan数据类型和可选支持d金宝appenormal数字。

  • 广泛的数学块(添加、mul div、倒数、日志、exp rsqrt√6)和三角块(罪,因为,要求:量化)支金宝app持。

为什么使用浮点类型

有时你可能想要开始在浮点和留在浮点针对高密度脂蛋白,而不是转换为定点,原因如下:

  • 你的算法有大型或未知动态范围(例如集成商在反馈回路)

  • 你的算法使用的操作很难被设计在定点(例:量化)

在定点版本的例子hdlcoderFocCurrentFloatHDL.slx你注意到几个定点舍入和饱和决定保存数值算法的行为。例如,块hdlcoderFocCurrentFixptHdl / FOC_Current_Control DQ_Current_Control / D_Current_Control /饱和是一个饱和块被放置在积分器循环,这样的结果不溢出由于积累的循环。

open_system (“hdlcoderFocCurrentFixptHdl”);open_system (“hdlcoderFocCurrentFixptHdl / FOC_Current_Control / DQ_Current_Control / D_Current_Control /饱和的);

有时,定点转换的任务可能需要几个星期与多级算法后续几个月。它也可能导致不良的精度损失可能不会接受的一些关键任务应用程序要求很高的精度。

在这些情况下,您可以选择使用本机浮点合成高密度脂蛋白编码器中的可用功能。

单精度船模型

打开单精度算法的版本、运行这些命令:

load_system (“hdlcoderFocCurrentFloatHdl”);open_system (“hdlcoderFocCurrentFloatHdl / FOC_Current_Control”)

定点算法相比,单精度模型不需要额外的舍入和饱和块和设置可以看到在浮点模型的版本hdlcoderFocCurrentFloatHdl / FOC_Current_Control DQ_Current_Control / D_Current_Control

open_system (“hdlcoderFocCurrentFloatHdl / FOC_Current_Control DQ_Current_Control / D_Current_Control ')

通过仿真来验证行为,运行这些命令:

hasSimPowerSystems =许可证(“测试”,“Power_System_Blocks”);如果hasSimPowerSystems open_system (“hdlcoderFocCurrentTestBench”)%设置testbench单精度浮点模型set_param (“hdlcoderFocCurrentTestBench /控制器”,“ModelName”,“hdlcoderFocCurrentFloatHdl”);set_param (“hdlcoderFocCurrentTestBench”,“IgnoredZcDiagnostic”,“没有”);sim卡(“hdlcoderFocCurrentTestBench”)set_param (“hdlcoderFocCurrentTestBench”,“IgnoredZcDiagnostic”,“警告”);结束

你可以生成HDL代码控制器和视图生成的代码。

hdlset_param (“hdlcoderFocCurrentFloatHdl”,“FloatingPointTargetConfiguration”hdlcoder.createFloatingPointTargetConfig (“NATIVEFLOATINGPOINT”));makehdl (“hdlcoderFocCurrentFloatHdl / FOC_Current_Control”);
# # #开始编译模型的“hdlcoderFocCurrentFloatHdl”……# # #生成“hdlcoderFocCurrentFloatHdl / FOC_Current_Control”高密度脂蛋白。使用的配置集模型# # # < a href = " matlab: configset。showParameterGroup (hdlcoderFocCurrentFloatHdl, {HDL代码生成的})" > hdlcoderFocCurrentFloatHdl < / > HDL代码生成参数。# # #“hdlcoderFocCurrentFloatHdl”高密度脂蛋白检查运行模型。# # #应用高密度脂蛋白对模型优化“hdlcoderFocCurrentFloatHdl”……# # #开始生成模型。# # #模型生成完成。# # #时钟频率流水线可以诊断结果通过运行这个脚本:< a href = " matlab:运行(hdlsrc / hdlcoderFocCurrentFloatHdl / highlightClockRatePipelining) " > hdlsrc / hdlcoderFocCurrentFloatHdl / highlightClockRatePipelining。m < / > # # #强调块阻碍分布式流水线,点击下面的MATLAB脚本:< a href = " MATLAB:运行(hdlsrc / hdlcoderFocCurrentFloatHdl / highlightDistributedPipeliningBarriers) " > hdlsrc / hdlcoderFocCurrentFloatHdl / highlightDistributedPipeliningBarriers。m < / > # # #清除高亮显示,点击下面的MATLAB脚本:< a href = " MATLAB:运行(hdlsrc / hdlcoderFocCurrentFloatHdl / clearhighlighting.m) " > hdlsrc / hdlcoderFocCurrentFloatHdl / clearhighlighting。m < / > # # #产生新的验证模型:< a href = " matlab: open_system (gm_hdlcoderFocCurrentFloatHdl_vnl) " > gm_hdlcoderFocCurrentFloatHdl_vnl < / >。 ### Validation model generation complete. ### Begin VHDL Code Generation for 'hdlcoderFocCurrentFloatHdl'. ### MESSAGE: The design requires 800 times faster clock with respect to the base rate = 2e-05. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_relop_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_relop_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_relop_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_relop_single_block.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_sincos_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_sincos_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_relop_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_relop_single_block1.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_relop_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_relop_single_block2.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_add_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_add_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_gain_pow2_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_gain_pow2_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_sub_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_sub_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_add2_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_add2_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_mul_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_mul_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_uminus_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_uminus_single.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control/nfp_relop_single as hdlsrc/hdlcoderFocCurrentFloatHdl/nfp_relop_single_block3.vhd. ### Working on FOC_Current_Control_tc as hdlsrc/hdlcoderFocCurrentFloatHdl/FOC_Current_Control_tc.vhd. ### Working on hdlcoderFocCurrentFloatHdl/FOC_Current_Control as hdlsrc/hdlcoderFocCurrentFloatHdl/FOC_Current_Control.vhd. ### Generating package file hdlsrc/hdlcoderFocCurrentFloatHdl/FOC_Current_Control_pkg.vhd. ### Code Generation for 'hdlcoderFocCurrentFloatHdl' completed. ### Generating HTML files for code generation report at hdlcoderFocCurrentFloatHdl_codegen_rpt.html ### Creating HDL Code Generation Check Report file:///tmp/Bdoc22a_1891349_32774/tp571c54f9/ex95119120/hdlsrc/hdlcoderFocCurrentFloatHdl/FOC_Current_Control_report.html ### HDL check for 'hdlcoderFocCurrentFloatHdl' complete with 0 errors, 0 warnings, and 3 messages. ### HDL code generation complete.

Half-Precision船模型

对于需要较小的动态范围的应用程序,您可以使用一半类型,而不必把你的设计使用定点类型。使用一半消耗更少的内存类型,具有更低的延迟,节省FPGA资源。

在硬件的角度优势half-precision浮点类型:

  • 低延迟

  • 较低的区域

  • 高速

  • 16位浮点行为将有助于优化存储

  • 宽动态范围相对于整数或定点数据类型的大小相同

Half-precision类型具有相同的功能作为单-和双精度浮点类型。金宝app支持运营商包括基本的算术运算符(EX:添加/ Sub、Mul Div /倒数)和增益,关系运算符、数据类型转换。

load_system (“hdlcoderFocCurrentFloatHalfHdl”);open_system (“hdlcoderFocCurrentFloatHalfHdl / FOC_Current_Control”)

通过仿真来验证行为,运行这些命令:

hasSimPowerSystems =许可证(“测试”,“Power_System_Blocks”);如果hasSimPowerSystems open_system (“hdlcoderFocCurrentTestBench”)%设置half-precision testbench浮点模型set_param (“hdlcoderFocCurrentTestBench /控制器”,“ModelName”,“hdlcoderFocCurrentFloatHalfHdl”);set_param (“hdlcoderFocCurrentTestBench”,“IgnoredZcDiagnostic”,“没有”);sim卡(“hdlcoderFocCurrentTestBench”)set_param (“hdlcoderFocCurrentTestBench”,“IgnoredZcDiagnostic”,“警告”);结束

你可以生成HDL代码控制器和视图生成的代码。

hdlset_param (“hdlcoderFocCurrentFloatHalfHdl”,“FloatingPointTargetConfiguration”hdlcoder.createFloatingPointTargetConfig (“NATIVEFLOATINGPOINT”));makehdl (“hdlcoderFocCurrentFloatHalfHdl / FOC_Current_Control”);
# # #生成“hdlcoderFocCurrentFloatHalfHdl / FOC_Current_Control”高密度脂蛋白。使用的配置集模型# # # < a href = " matlab: configset。showParameterGroup (hdlcoderFocCurrentFloatHalfHdl, {HDL代码生成的})" > hdlcoderFocCurrentFloatHalfHdl < / > HDL代码生成参数。# # #“hdlcoderFocCurrentFloatHalfHdl”高密度脂蛋白检查运行模型。# # #开始编译模型的“hdlcoderFocCurrentFloatHalfHdl”……# # #应用高密度脂蛋白对模型优化“hdlcoderFocCurrentFloatHalfHdl”……# # #开始生成模型。# # #模型生成完成。# # #时钟频率流水线可以诊断结果通过运行这个脚本:< a href = " matlab:运行(hdlsrc / hdlcoderFocCurrentFloatHalfHdl / highlightClockRatePipelining) " > hdlsrc / hdlcoderFocCurrentFloatHalfHdl / highlightClockRatePipelining。m < / > # # #强调块阻碍分布式流水线,点击下面的MATLAB脚本:< a href = " MATLAB:运行(hdlsrc / hdlcoderFocCurrentFloatHalfHdl / highlightDistributedPipeliningBarriers) " > hdlsrc / hdlcoderFocCurrentFloatHalfHdl / highlightDistributedPipeliningBarriers。m < / > # # #清除高亮显示,点击下面的MATLAB脚本:< a href = " MATLAB:运行(hdlsrc / hdlcoderFocCurrentFloatHalfHdl / clearhighlighting.m) " > hdlsrc / hdlcoderFocCurrentFloatHalfHdl / clearhighlighting。m < / > # # #产生新的验证模型:< a href = " matlab: open_system (gm_hdlcoderFocCurrentFloatHalfHdl_vnl) " > gm_hdlcoderFocCurrentFloatHalfHdl_vnl < / >。 ### Validation model generation complete. ### Begin VHDL Code Generation for 'hdlcoderFocCurrentFloatHalfHdl'. ### MESSAGE: The design requires 800 times faster clock with respect to the base rate = 2e-05. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_relop_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_relop_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_relop_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_relop_half_block.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_relop_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_relop_half_block1.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_relop_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_relop_half_block2.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_add_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_add_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_gain_pow2_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_gain_pow2_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_sub_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_sub_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_add2_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_add2_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_mul_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_mul_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_uminus_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_uminus_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_relop_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_relop_half_block3.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_convert_sfix_16_En14_to_half as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_convert_sfix_16_En14_to_half.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control/nfp_convert_half_to_sfix_16_En8 as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/nfp_convert_half_to_sfix_16_En8.vhd. ### Working on FOC_Current_Control_tc as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control_tc.vhd. ### Working on hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control as hdlsrc/hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control.vhd. ### Generating package file hdlsrc/hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control_pkg.vhd. ### Code Generation for 'hdlcoderFocCurrentFloatHalfHdl' completed. ### Generating HTML files for code generation report at hdlcoderFocCurrentFloatHalfHdl_codegen_rpt.html ### Creating HDL Code Generation Check Report file:///tmp/Bdoc22a_1891349_32774/tp571c54f9/ex95119120/hdlsrc/hdlcoderFocCurrentFloatHalfHdl/FOC_Current_Control_report.html ### HDL check for 'hdlcoderFocCurrentFloatHalfHdl' complete with 0 errors, 1 warnings, and 3 messages. ### HDL code generation complete.

您可以参考文档全部在高密度脂蛋白编码器原生浮点功能可用。看到链接开始使用HDL编码器原生浮点支持金宝app