Check HDL Compatibility of Model Using HDL Code Advisor

Before you can generate HDL code, it is recommended that you verify the compatibility of your algorithm modeled in Simulink® for HDL code generation. To verify model compatibility, you use the HDL Code Advisor. The HDL Code Advisor verifies and updates your Simulink model or subsystem for compatibility with HDL code generation. The Code Advisor checks for model configuration settings, ports and subsystem settings, block settings, support for native floating point, and conformance to the industry-standard rules. The Code Advisor produces a report that lists suboptimal conditions or settings, and then proposes better model configuration settings.

This example shows how you can update a simple up counter model for HDL compatibility. To learn more about the counter algorithm and how you can create this model, see Create Simulink Model for HDL Code Generation.

Simple Up Counter Model

Open this model to see a simple up counter. The model counts up from zero to a threshold value and then wraps back to zero. In this model, the threshold value is set to 15. You can change the threshold value by changing the value of the Constant block that is input to the count_threshold port. The Enable signal specifies whether the counter should count up or hold the previous value. The Enable signal is set to 1 which means that the counter counts upwards continuously.

open_system('hdlcoder_simple_up_counter.slx')
set_param('hdlcoder_simple_up_counter', 'SimulationCommand', 'Update')

Open the HDL Code Advisor

To open the HDL Code Advisor, in the Apps tab, select HDL Coder. The HDL Code tab appears. Select the DUT Subsystem and then click HDL Code Advisor.

Note

You open the HDL Code Advisor and then run checks for the DUT Subsystem that you want to generate code for. The top level model can contain blocks that are not compatible for HDL code generation. Running the HDL Code Advisor for the entire model can flag these blocks and your model as incompatible for HDL code generation.

In the HDL Code Advisor, the left pane lists the folders in the hierarchy. Each folder represents a group or category of related checks. Expanding the folders shows available checks in each folder. From the left pane, you can select a folder or an individual check. The HDL Code Advisor displays information about the selected folder or check in the right pane. The content of the right pane depends on the selected folder or check. The right pane has a Result subpane that contains a display area for status messages and other task results.

To learn more about each individual check, right-click that check, and select What's This?.

How to Run Checks In the HDL Code Advisor

In the HDL Code Advisor window, you can run individual checks or a group of checks. To run a check, Select that check and then click Run This Check. For example, to run the Check for safe model parameters, select the check box, and then click Run This Check.

In the HDL Code Advisor window, you can run a group of checks within a folder.

  1. Select the checks that you want to run.

  2. Select the folder that contains these checks and then click Run Selected Checks.

This example shows how to run selected checks in the Model configuration checks folder.

Run Checks for Counter Model

By using this approach, for your counter model, run all checks in these folders:

  • Model Configuration checks

  • Checks for ports and subsystems

  • Checks for blocks and block settings

For this example, you do not need to run the checks in Native Floating Point checks and Industry standard checks folders. To learn more about these checks, see HDL Code Advisor Checks.

For the counter model, the checks display the results as Passed, which means that the model is compatible for HDL code generation.

Fix HDL Code Advisor Warnings or Failures

In the HDL Code Advisor, if a check fails, the right pane shows the warning or failure information in a Result subpane. The Result subpane displays model settings that are not compliant. For some tasks, use the Action subpane to apply the Code Advisor recommended settings.

For example, inside the HDL_DUT Subsystem, consider that you remove the Enable port and replace this port with a Constant input that has a value of 1.

Now, if you run the Check for infinite and continuous sample time sources check, the HDL Code Advisor displays this warning.

To apply the model configuration settings that the code generator reported in the Result subpane, click the Modify Settings button. After you click Modify Settings, the Result subpane reports the changes that were applied. In this example, the Sample time of the Constant block is reset to -1. You can now run this check.

Caveats

  • If you reference one model in another by using a Model block, the HDL Code Advisor checks the model configurations or settings of the parent model. To check whether the referenced model is compatible with HDL code generation, open the HDL Code Advisor for the referenced model, and then run the checks.

  • If you run the checks on masked library blocks in your Simulink model, the Code Advisor cannot verify whether the blocks inside the library blocks have HDL-compatible settings.

  • When you apply Model Advisor checks to your model, it increases the likelihood that your model does not violate certain modeling standards or guidelines. However, it does not guarantee that the design is ready for HDL code generation. Make sure that you verify the design by using multiple methods for HDL code generation readiness.

Generate HDL Code

The counter model is now compatible for HDL code generation. You can generate HDL code for the HDL_DUT Subsystem, which contains the counter algorithm. To learn how to generate code, see Generate HDL Code from Simulink Model.

See Also

| |

Related Topics