Why does PLC Coder generate an incorrect testbench for a model with continuous stimulus?

2 views (last 30 days)
I generate Structured Text for my Function Block using PLC Coder. The simulation results in Simulink look fine, and the generated PLC Code for the Function Block seems to be correct.
However, for the testbench, the input stimulus does not have the number of samples that I expect, and the output vector looks garbled:
tb_In1: ARRAY [0..54] OF SINT := 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
tb_Out1: ARRAY [0..54] OF SINT := 1,1,1,1,2,2,1,1,1,1,1,-45,2,0,0,0,0,0,0,0,2,0,0,0,90,55,-39,99,-14,0,0,-120,
-80,83,-31,10,0,0,0,0,1,0,0,0,1,0,0,0,16,-77,28,39,0,0,0;
Instead, I expected:
tb_In1: ARRAY [0..10] OF SINT := 0,0,0,0,1,1,0,0,0,0,0;
tb_Out1: ARRAY [0..10] OF SINT := 1,1,1,1,2,2,1,1,1,1,1;
Why is this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Jun 2019
This issue may arise if the discrete Function Block is fed by a continuous signal.
To work around the issue, discretize your stimulus by specifying a Sample Time in the respective signal source block, or use a Signal Specification block before the Function Block to set a matching sample time for the stimulus.

More Answers (0)

Categories

Find more on Simulink PLC Coder in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!