main content

model, simulate, and generate code for ladder logic-凯发k8网页登录

rapidly prototype the ladder logic-based controller for a single car elevator by using simulink® plc coder™ to model and simulate the ladder logic. after verifying that the controller works for your requirements, generate code for the controller.

model description

the model consists of a elevator control system block, elevator block, and a human machine interface (hmi) block. open the model:

open_system('plcdemo_ladder_elevator');

elevator_controller.png

opening the model loads the timer configuration, model data types, and initializes the model by using information from the plcdemo_ladder_elevator_init.m file.

type plcdemo_ladder_elevator_init
% sample time
ts = 0.1;
% load plc builtin types
plcloadtypes;
% define timer initial values
t37_initialvalue = fb_ton.initialvalue;
t37_initialvalue.pre = int32(300*100);
t38_initialvalue = fb_tof.initialvalue;
t38_initialvalue.pre = int32(100*100);
t39_initialvalue = fb_ton.initialvalue;
t39_initialvalue.pre = int32(12*100);
t40_initialvalue = fb_ton.initialvalue;
t40_initialvalue.pre = int32(10*100);
t41_initialvalue = fb_tof.initialvalue;
t41_initialvalue.pre = int32(1*100);
% define dashboard parameters
interiorfloor1request = false;
interiorfloor2request = false;
interiorfloor3request = false;
interiorfloor4request = false;
exteriorfloor1request = false;
exteriorfloor2request = false;
exteriorfloor3request = false;
exteriorfloor4request = false;
photocell  = false;

elevator control system block

the elevator control system block is a plc controller block. it contains a ladder program block that contains the ladder logic. to view the ladder logic for the controller, open:

  • the elevator control system block

  • the elevator plc ladder diagram system block

  • the elevator controller block

  • the task block

  • the program block

this image shows a section of the ladder diagram logic inside the program block.

elevator_ladder_logic.png

hmi block

the hmi block enables you to interact with the model simulation. open the hmi block by double-clicking the block. this image shows the components of the hmi block.

elevator_hmi.png

the hmi block contains:

  • exterior buttons: represents the exterior floor request buttons.

  • interior buttons: represents the interior floor request buttons.

  • photocell: represents the door sensor.

elevator block

the elevator block is a matlab function block that contains a mathematical model representing the elevator system. the calculations from the elevator block are used as inputs to the graphics function to simulate the elevator movement.

simulate model and generate code

simulate the model and observe the elevator animation. in this image, the second floor external request button was pressed.

elevator_simulation.png

after verifying that the controller functions for your requirements, generate code for the elevator controller block

plcgeneratecode('plcdemo_ladder_elevator/elevator control system/elevator plc ladder diagram system/elevator controller')

alternatively, generate code by selecting the elevator controller block, and then selecting apps > plc coder. on the plc code tab, click generate plc code.

see also

网站地图