Get inverse of scalar in hdl code generation

5 ビュー (過去 30 日間)
taaha saleem bajwa
taaha saleem bajwa 2017 年 4 月 26 日
回答済み: Kiran Kintali 2023 年 10 月 29 日
hi,
I am implementing an algorithm in matlab for hdl code generation which requires inverse of a variable scalar e.g 1/x . Most articles state that the divisor must be a constant and a power of two. Only thing I can find is reciprocal block but it is available in simulink and my design is in matlab mfile.
Is their any function or way of doing this in matlab mfile?

回答 (1 件)

Kiran Kintali
Kiran Kintali 2023 年 10 月 29 日
There are multiple ways to generate HDL from HDL with reciprocal and divide operators.
If the scalar variable you are computing reciprocal for is of fixed-point type, you may want to consider use of approximations such as LUT approximation or CORDIC function based approximation.
You can also consider use of shift-add based division replacement if you want more accurate but a bit mroe resource heavy implementation. Shift-add performs divide operations on fixed-point types by using a non-restoring division algorithm that performs multiple shift and add operations to compute the quotient. This architecture provides improved accuracy compared to the LUT / CORDIC / Newton-Raphson approximation methods.
If you are writing fixed-point code manually for HDL code generation you can consider using fixed.cordicDivide function.
If you are using automatic float to fixed functionality available in MATLAB to HDL workflow you can take advantage of the automatic replacement operator workflow. See the attached tutorials with the examples for the various replacmenet methods.
See the attached MATLAB code and tutorial on how to perform the replacements either manually or automatically.

カテゴリ

Help Center および File ExchangeHDL Coder についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by