Target Language Compiler | ![]() ![]() |
Generate and Run Code from the Model
simple_log.mdl
is set up to generate code properly by opening the Simulation parameters dialog and clicking the Advanced tab. Make sure that Inline parameters is selected. The bug you will fix only appears when inline parameters are used.
simple_log.mat
in your Current Directory pane, then double-click on rt_yout
(the stand-alone version of variable yout
) in the Workspace pane.
rt_yout
with yout
. Do you notice any differences? Can you surmise what caused values in rt_yout
to change?
A look at the generated C code that the TLC placed in your build directory (/simple_log_grt_rtw
) helps to identify the problem.
simple_log.c and l
ook at its MdlOutputs function, which should appear as shown below:
void MdlOutputs(int_T tid) { /* local block i/o variables */ real_T rtb_Discrete_Pulse_Generator; real_T rtb_first_output; /* This is a single rate system */ (void)tid; /* DiscretePulseGenerator: '<Root>/Discrete Pulse Generator' */ rtb_Discrete_Pulse_Generator = (rtDWork.Discrete_Pulse_Generator_IWORK.ClockTicksCounter < 1.0 && rtDWork.Discrete_Pulse_Generator_IWORK.ClockTicksCounter >= 0) ? 1.0 : 0.0; if (rtDWork.Discrete_Pulse_Generator_IWORK.ClockTicksCounter >= 2.0-1) { rtDWork.Discrete_Pulse_Generator_IWORK.ClockTicksCounter = 0; } else { (rtDWork.Discrete_Pulse_Generator_IWORK.ClockTicksCounter)++; } /* Gain Block: <Root>/Gain1st */ rtb_first_output = 1.0; /* Outport: '<Root>/Out1' */ rtY.Out1 = rtb_first_output; }
Note the line near the end, rtb_first_output = 1.0;. How did a constant value get passed to the output when it was supposed to receive a variable that alternates between 1.0
and 0.0
? Use the debugger to find out.
![]() | Getting Started | Start the Debugger and Explore Commands | ![]() |