9.28.2021

speedupSt.md

Use autohotkey to speedup st programming.

As the poor support for structure text programming in plc world(code snippet), here are some short key for it I used with autohotkey.

It’s good for your healthy, enjoy it.

  • ,s ==> SET(TRUE, );
  • ,r ==> RST(TRUE, );
  • ,t ==> := TRUE;
  • ,f ==> := FALSE;

9.27.2021

UseStWritePLC.md

How to use structure text to write a simple indexing rotary table plc program

What is a indexing rotary table machine

Brief definition:

  1. At least one material input station and one finished product output station
  2. At least one indexing rotary table
  3. The indexing rotary table has a different number of divisions (or workstations) according to the manufacturing process
  4. Each division can place one or more workpieces
  5. Materials can input by man or feeder.

Found on the Internet:

Program Layout

Generally, I’ll layout the plc program as :

  • “Init” : Initialization code
  • “Always” : The normal execution code, including the Instance of Function Block
  • “Auto” : Automatic mode control
  • “Manual” : Manual mode control
  • “Error” : Error status control code
  • “St1”
  • “Stx” : Cycle control code of each station

State Machine

I’d like to centralization the mode control in one state machine, as shown in the figure:

If it is a simpler system, it will be simplified to only manual/automatic switching, or execute according to individual needs.

Of course, the actions of each station are also processed by their own state machine. In automatic mode, the role of the main state machine is only to evoke the status of whether each station needs to perform an action and check completion.

Timing diagram

  • a: The first automatic action is to turn the indexing rotary table, then let each station act
  • b: After the indexing rotary table is arrived, St2Cycle can work
  • c: The indexing rotary table will be rotated again after the St1 and St2 (all stations) operations are completed

The indexing table basically has only two states:

  • Rotating
  • Stopped in place

And each station basically has two types,

  • Can only act after the indexing rotary table is in place
  • You can do act first, and then continue to act after the indexing rotary table is in place

As shown in the figure above, St1 can pre-act while rotating, while St2 can only be acted after it is in place.

Sample file

Sample file

Summarize

In fact, sometimes its more intuitive to use the ladder style, but the advantage of ST is that it is convenient to write automatic code generator, It can shorten a lot of time during development.

Pay attention to when writing ST:

  1. ":=" equivalent “out” command
  1. The “if” instruction will take up more steps

    If there is only one line of instructions, it is recommended to switch to a single command. Although it is less readable, it saves more steps…

ST writing recommendation reference:PLC結構化文本設計模式和算法_rediculous的專欄-CSDN博客_plc結構化文本編程

使用ST寫圓盤類程式.md

如何使用ST寫簡易圓盤類PLC程式

什麼是圓盤類機台

簡要定義:

  1. 至少有一個料件輸入站,一個成品輸出站
  2. 至少有一個圓盤
  3. 圓盤依製程有不同的分割數(或稱工位)
  4. 每個分割可放置一或多個工件
  5. 可用人工或送料機輸入料件

網路上找到的:

程式 Layout

一般我會把plc程式的架構切分如下:

  • “Init” 初始化程式碼
  • “Always” 放置常態執行程式碼,含 Function Block 的 Instance
  • “Auto” 自動模式的控制
  • “Manual” 手動模式控制
  • “Error” 錯誤狀態控制碼
  • “St1”
  • “Stx” 各站的週期控制碼

狀態機

手/自動模式的管理,我習慣由統一的狀態機來執行,如圖:

若是較簡單的系統,就會簡化成只有手動/自動的切換,或依各別需求執行。

當然,各站別的動作也是自己的狀態機處理。自動模式時,主狀態機的作用只在喚起各站是否需要執行動作及判斷完成等狀態。

時序圖

  • a:自動的第一個動作都是轉圓盤,後再讓各站作動
  • b:圓盤到位後,St2Cycle才能作業
  • c:St1、St2作業完成後才會再次轉動圓盤

圓盤基本上只有兩個狀態:

  • 轉動中
  • 到位停止中

而各站別基本上有兩種類型,

  • 圓盤到位後才能作動的
  • 可以先動作,圓盤到位後再接續作動

如上圖,St1屬於轉動中可偷跑的,而St2屬於到位後才能作動的。

Sample file

範例檔案

總結

其實有的寫法用ladder的型式去表現會較直覺,但是ST的好處在於方便寫程式碼自動產生器,在開發時能夠縮短不少時間。

寫ST時要注意:

  1. ":=" 等效 “out” 命令
  1. if 指令會佔用較多的steps空間

    如果只有一行指令時,建議轉為單一的命令,雖然可讀性較差,但更省空間…

ST寫作推薦參考:PLC結構化文本設計模式和算法_rediculous的專欄-CSDN博客_plc結構化文本編程

9.13.2021

Simple Project With Label

Enable label in simple project for better program layout

In general, we use “Ctrl + L” or “Ctrl + G” to track our ladder program, which is great, but it would be better if we use the label feature in simple project.

ps: Label feature will slightly slow down compilation speed.

Works2 no label

Works2 with label

Works2 with label, seperated program, even better