PLC (Programmable Logic Controller) はオン、オフ制御を行うリレー回路の置き換えとして発達したビット演算主体の制御機器です。工場の機械制御に大量に使われています。リレー回路(ラダーロジック言います。)のイメージでプルグラムできるようになっています。このようなビット演算をアセンブラで作るのはとても面倒でやってられません。そこで簡易 PLC のプログラムを作ることにしました。

PLC (Programmable Logic Controller) is industrial equipment that replaced most of relay logic circuit. It can be programmed in ladder logic that represents relay circuit. It is very cumbersome to program bit operation like relay logic in assembler. So I developed a simplified PLC program.

In actual PLC the programming is dene through graphic editor like this.

  • In this ladder diagram, if “INPUT1” and “INPUT2” are ON then “COIL1” turns ON. When “COIL1” becomes ON, “COIL2” also turns ON.
  • At this moment if “INPUT1” turns OFF, “COIL1” will be OFF. However “COIL2” still keeps ON by itself contact connected in parallel with “COIL1” contact. This sort of circuit is called “self holding circuit”.
  • If “INPUT3” turns ON, “COIL2” will be OFF.

本物の PLC のプログラムはこのようなグラフィックエディターで行います。

  • このラダーではINPUT1 と INPUT2 が同時に ON すると、 COIL1 が ON になります。 COIL1 がの ON すると COIL2 も ON します。
  • ここで INPUT1 が OFF になると COIL1 は OFF になりますが、 COIL2 は自分の接点が COIL1 の接点とパラに入っているので ON のままです。このような回路を自己保持回路といっています。
  • INPUT3 が ON することで、 COIL2 は OFF になります。

;********** User Reg # & Bit Location Definision for Boolians (PLC) *****
.equ Bit0=$01
.equ Bit1=$02
.equ Bit2=$04
.equ Bit3=$08
.equ Bit4=$10
.equ Bit5=$20
.equ Bit6=$40
.equ Bit7=$80
;**************************************

;***** Bit Definition ******
.equ INPUT1_R=4
.equ INPUT1_B=Bit0

.equ INPUT2_R=4
.equ INPUT2_B=Bit1

.equ INPUT3_R=4
.equ INPUT3_B=Bit2

.equ COIL1_R=5
.equ COIL1_B=Bit0

.equ COIL2_R=5
.equ COIL2_B=Bit1
;****************************

; First Rung
.csg
.db   Load_A,INPUT1_R,INPUT1_B,0
.db   And_A,INPUT2_R,INPUT2_B,0
.db   Coil_A,COIL1_R,COIL1_B,0

;  Second Rung
.db   Load_A,COIL1_R,COIL1_B,0
.db   Or_A,COIL2_R,COIL2_B,0
.db   And_B,INPUT3_R,INPUT3_B,0
.db   Coil_A,COIL2_R,COIL2_B,0

Of course we do not have graphic editor in this case. So we have to convert this ladder diagram to intermediate language that the PLC software can understand. Above ladder logic will be converted as this.

  • The first part of this defines the bit pattern of each bit. This simplified PLC does need bit pattern instead of bit number.
  • The next part defines bits used in the ladder diagram. They are defined as a combination of register number (_R) and bit pattern (_B) mentioned above.
  • The last part is ladder diagram converted to intermediate language. The order is instruction code, register number, bit patter and “0”.

もちろんグラフィックエディターなんかありませんから、自分で、簡易 PLC プログラムが理解可能な中間言語に落とさなければなりません。上記のプログラムを変換すると左のようになります。

  • 最初の部分はビットパターンの定義です。簡易 PLC プログラムの都合上ビットはビット番号ではなくビットの位置パターンで定義します。
  • 次の部分は各ビットの定義で、レジスター番号 (_R) と上記ビットパターン (_B) の組み合わせで表します。
  • 最後の部分がラダーを中間言語に変換したものです。 インストラクション、レジスター番号、ビットパターン、0の順番で記述します。

Following instructions are provided.

インストラクションは下のようなものを用意しました。

;********* Instruction Codes **********
.equ   Load_A=1         ; Load NO Contact      |-I I-

.equ   Load_B=2         ; Load NC Contact      |-I/I-

.equ   And_A=3          ; And NO Conatct       -I I-

.equ   And_B=4          ; And NC Conatct       -I/I-

.equ   Or_A=5           ; Or NO Contact        |-I I-^

.equ   Or_B=6           ; Or NC Contact        |-I/I-^

.equ   Coil_A=7         ; Coil Output           -( )-|

.equ   Coil_B=8         ; Coil Inverted Output  -(/)-|

.equ   Set_Coil=9       ; Set Coil              -(S)-|

.equ   Reset_Coil=10    ; Reset Coil            -(R)-|

.equ   TON=11           ; On-Delay Timer       -[TON]-

.equ   TOF=12           ; Off-Delay Timer      -[TOF]-

.equ   TP=13            ; Pule Timer           -[TP]-

.equ   Not=14           ; Inverter             -I|I-

.equ   Pulse_A=15       ; Rising Edge Pulse    -IPI-

.equ   Pulse_B=16       ; Falling Edge Pulse   -INI-

.equ   End_PLC=$FF      ; End of PLC Codes     [END]

;**************************************

Timers work as diagrams below. Be careful “TOF” output will be on for set time on power up.

タイマー類は下記のような動きます。TOFは電源ON時にセット時間、出力ONしてしまうので注意が必要です。

    

Special contacts work as diagrams below. Since “Inverter” does not require any operand so bit data should be “0”. “P” and “N” need a bit operand to keep previous status.

特殊接点類は下記のように動きます。Inverterはビット情報はいらないので命令以外全て、0にすること。PとNには前のスキャンの状態を記憶するためのビット情報が必要。

     

.dseg
PLC_Timer_Top: ; PLC Timers
E_Stop_Timer:    .byte 2
Start_TP:        .byte 2
Stop_TP:         .byte 2

.cseg
; Run  Direct    E_Stop
;--| |--| |--[TOF]--( )-|
;
.db Load_A,Run_R,Run_B,0
.db And_A,Direct_R,Direct_B,0
.db TOF,LOW(E_Stop_Timer),LOW(1000/Scan),HIGH(1000/Scan)
.db Coil_A,E_Stop_R,E_Stop_B,0


Each timer requires two bytes in RAM to save count value. This RAM area must be labelled as “PLC_Timer_Top".

An example of timer program in intermediate language is shown after “.cseg”. Here the second byte is lower RAM address. The third and fourth bytes are timer setting value. The unit of timer setting value is scan period of simplified PLC program.

タイマー類はタイマーカウント値を収める2バイトのRAMを必要とします。このRAMエリアの頭には"PLC_Timer_Top"というラベルをつけてください。

タイマー類のプログラムは下半分の例のように行います。ここで2バイトめは下位RAMアドレス、3および4バイトめはタイマー設定値です。単位は簡易PLCプログラムのスキャン時間になります。

There is a restriction in application of “OR”. Or-line can have only one contact.

ORの使い方に制約があります。ORでつなぐのは一つの接点だけです。

This type of connection is prohibited because of language limitation.

こういう使い方は、言語仕様上できません。

簡易PLCのサンプルプログラムはこちらからダウンロード可能。

  • "Bool_Definition.asm" はラダーで使われているビット定義のサンプル
  • "PLC.asm" は、簡易PLCの本体プログラム
  • "PLC_Bit_Def.asm" はビットパターンの定義
  • "PLC_Program.asm" はラダープログラムのサンプル

Sample program of simplified PLC can be downloaded from here.

  • "Bool_Definition.asm" is a sample of bit definitions
  • "PLC.asm" is simplified PLC program itself
  • "PLC_Bit_Def.asm" is definition of bit patterns
  • "PLC_Program.asm" is a sample of ladder program

 

 
inserted by FC2 system