HDL simulinks coder support

2 visualizzazioni (ultimi 30 giorni)
Pham Van Dung
Pham Van Dung il 22 Apr 2012
Dear friends, I have a problem MATLAB Function. How do I generate HDL Code for my MATLAB Function in Simulink HDL Coder (R2011b).
My Matlab functions are:
1. y = 1+fix(u/(pi/3+1.e-30));
2. y = rem(u(1),1/1000);
What functions I Can use to replace these Functions?
Please help me!
Best regards!
[Merged information from duplicate question]
Dear friends,
When I try to convert to HDL code i meet some errors:
'floor' : Call to 'floor' is not supported for HDL code generation.
Function 'eml_scalar_fix' (#33554436.391.403), line 19, column 9 P
Function 'eml_scalar_fix' (#33554436.171.184), line 9, column 13 A
Function 'eml_scalar_fix' (#33554436.171.184), line 9, column 13 P
Function 'fix' (#33554435.325.345), line 12, column 12 A
Function 'fix' (#33554435.325.345), line 12, column 12 P
Function 'Subsystem2/MATLAB Function2' (#305.37.57), line 4, column 7 A
Function 'Subsystem2/MATLAB Function2' (#305.37.57), line 4, column 7 P
Please help me!
Best regards!

Risposta accettata

Walter Roberson
Walter Roberson il 22 Apr 2012
You would need the fixed point toolbox.
Warning: eps(pi/3) is much greater than 1e-30, so unless you are overwriting "pi" with some other value, in IEEE double precision binary floating point arithmetic, the addition is not going to make any difference to the result. If your intention is that it will make a difference, then you will need to use somewhere around 90 bits in your fixed point arithmetic.

Più risposte (1)

Tim McBrayer
Tim McBrayer il 23 Apr 2012
As Walter observed, floating point math will cause your argument to 'fix' to simply resolve to 'u', since fix(pi/3 + 1-e30) == 1. This assumes that you are using floating point for all your values. In general, the use of floating point will result in a large and slow hardware implementation, and is not recommended unless you are aware of the hardware implications of doing so.
It is much more common to use fixed-point arithmetic for HDL code generation. It is so much more common that the MATLAB to HDL flow has an explicit semi-automated float-to-fixed conversion step as part of the design flow. This flow helps you choose an appropriate word length and amount of precision, based off of the actual input data from your testbench. You can graphically compare the deviation of the derived fixed-point model from the floating point golden model to help guide the data typing choices.
To address your actual question: if you are using fixed-point, the call to 'fix' is supported, but in general you don't need to explicitly call it. By default, all fixed point arithmetic for HDL code generation uses fimath settings that are suitable for HDL. To see the default HDL fimath type 'hdlfimath':
>> hdlfimath
ans =
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: FullPrecision
SumMode: FullPrecision
You can change 'floor' (round towards -infinity) to 'fix' (round towards zero) with little effect on the generated HDL.
For rem: rem is not supported for HDL code generation even in fixed point. However, the algorithm for rem is straightforward and is in the MATLAB doc page for rem. Note that it contains a divide, which is inefficient to implement in hardware. This is another opportunity to reconsider what your actual task is and see if there is a more hardware-friendly way to address the problem.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by