how to use local parameter in HDL Coder toolbox?
4 views (last 30 days)
Show older comments
Dear MATLAB Support Team,
I am currently working on developing an UART transmitter block in Simulink. Within this block, I require two parameters: CLOCK_FREQ and BAUD_RATE, which are essential for calculating the DIVIDER parameter, given by CLOCK_FREQ / BAUD_RATE.
While I have learned how to generate parameters using HDL Coder, I am facing confusion regarding the generation of the local parameter DIVIDER, which will be utilized within a counter block. I aim to produce Verilog code similar to the following:
- - - - - - - -
parameter BAUD_RATE = 9600;
parameter CLOCK_FREQ = 100000000;
localparam DIVIDER = CLOCK_FREQ / BAUD_RATE;
if (clk_divider == DIVIDER) begin
// Further implementation
end
- - - - - - - - -
However, the generated code I am obtaining differs:
- - - - - - - - - - - -
parameter integer BAUD_RATE = 9600;
parameter integer CLOCK_FREQ = 100000000;
assign DIVIDER_out1 = 32'b00000000000000000010100010110001;
- - - - - - - - - - -
How can I use BAUD_RATE and CLOCK_FREQ within the module to generate other parameters?
The Constant Block setting is as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1686501/image.png)
0 Comments
Answers (1)
kiyoko
on 7 May 2024
Unfortunately, HDL Coder does not support the generation of "localparam". "Generate Parameterized HDL Code for Constant and Gain Blocks" is only compatible with "parameter".
As an alternative, if you have custom HDL code, you can use the DocBlock block to integrate that custom HDL code into your design.
See Also
Categories
Find more on HDL Code Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!