Why do I get an error when generating code for Lookup Table blocks in Real-Time Workshop 6.0 (R14)?

2 views (last 30 days)
I am receiving an error that occurs under a specific combination of input data type and vector of input/output values for the Lookup Table block.
If the input data type is double and if either the input or output values of the Lookup Table block are defined as Simulink.Parameter with a non-double data type (for example, int16), the simulation works correctly. However, the following error occurs during code generation:
"Real-Time Workshop Error in block:
"MLOG_DC_Error/Parameter_int16", block type "Lookup":
Cannot access the address of expression, (double(Param_int16)), in InputValues."
I looked into "look_up.tlc" and found that a TLC variable "InputValues" has expression "double(Param_int16)" as the String field. I thought this "double(Param_int16)" is not a valid MATLAB expression and this might be the cause of the error. Additionally, I looked into the generated RTW file, and "double(Param_int16)" is already contained in the RTW file.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Jan 2010
This enhancement has been incorporated in Release 2009b (R2009b). For previous product releases, read below for any possible workarounds:
There is a bug in the way Real-Time Workshop 6.0 (R14) generates code for Lookup Table blocks. The cast is inserted because the data type (int16) of the Simulink.Parameter object differs from the data type (i.e., double) of the block's first input signal. The generated code casts the parameter to match the data type of the input signal.
To work around this issue:
- You can change the data type of the parameter to match the data type of the input signal. This will remove the need for the parameter cast.
- You can insert a data type conversion block onto the input signal to cast the input signal to the same data type as the parameter. This will also remove the need for the parameter cast.
Another option to consider:
- You can remove the explicit data type specification for the parameter (make it a 'double' instead of 'int16'). This will result in the block treating the parameter as "context-sensitive", so it will cast the parameter to the desired data type off-line (before generating code) and there will be no run-time cast generated. It should be noted that if a context sensitive parameter is used by multiple blocks, all of the blocks must use the parameter with the same data type or an error will occur.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!