This example shows how to do ladder logic simulation and code generation from ladder tank controller model.
To start, create a new folder with write permission, copy the files plcdemo_ladder_tankcontrol_template.slx and TankControl.L5X into the new folder.
Change the current folder to the new folder, rename plcdemo_ladder_tankcontrol_template.slx to plcdemo_ladder_tankcontrol.slx.
Run plcimportladder command in MATLAB:
plcimportladder TankControl TopAOI TankControl
Open the generated model TankControl_runner_TankControl.slx, select and copy the TankControl_runner block. Open plcdemo_ladder_tankcontrol, replace Controller/TankControl_runner with the copied block
Click Run button to start simulation. Open Tank HMI and use the rotary switch to set controller command input: * Set switch to 'Fill' position to fill tank; * Set switch to 'Hold' position to hold current tank state; * Set switch to 'Empty' position to empty tank; * Set switch to 'Stir' position to activate tank stir state. Note: Tank will enter 'STIR' state only when fluid level is full; otherwise, 'Stir' command has no effect. If tank is in 'STIR' state, the STIR indicator lamp will be on, otherwise off. The numerical value of tank command is the following: 'Fill' - 0 'Hold' - 1 'Empty' - 2 'Stir' -3
Open ladder tank control testbench model: