-
Notifications
You must be signed in to change notification settings - Fork 28
OSCAT BASIC LogicModules
Matthias Mersch edited this page Apr 11, 2018
·
1 revision
Type Function: INT
Input IN: BYTE (BCD coded input)
Output INT (output value)
BCDC_TO_INT converts a BCD coded input BYTE in an integer value.
Type Function: INT
Input IN: DWORD (input)
Output INT (number of bits which have value TRUE (1) in IN)
BIT_COUNT determines the number of bits in IN, which have the value
TRUE (1). The input IN is DWORD and can also process the types Byte and
Word.
Type Function: BYTE
Input IN: BYTE (input)
VAL: BOOL (value of bits to be loaded)
POS: INT (position of the bits to be loaded)
Output BYTE (output)
BIT_LOAD_B copies the bit at VAL to the bit in the position N in byte IN.
The least signifcant bit B0 is described by the position 0.
Type Function: BYTE
Input I: BYTE (input value)
D: BOOL (value of bits to be loaded)
P: INT (position of the bits to be loaded)
N: INT (number of bits that are loaded from position P)
Output BYTE (output)
BIT_LOAD_B2 can set or delete multiple bits in a byte at the same time.
The position is indicated with 0 for Bit0 and 7 for Bit7. N specifes how
many bits from the specifed location can be changed. If N = 0, no bits are
changed. If the P and N is specifed that the bits to be written goes over
the highest bit (bit 7), so it starts again at bit 0.
BIT_LOAD_B2(2#1111_0000, TRUE, 1, 2) = 2#1111_0110
BIT_LOAD_B2(2#1111_1111, FALSE, 7, 2) = 2#0111_1110
Type Function: DWORD
Input IN: DWORD (input)
VAL: BOOL (value of bits to be loaded)
POS: INT (position of the bits to be loaded)
Output DWORD (output)
BIT_LOAD_DW copies the VAL bit at the input to the bit in position N in
DWORD IN. The least signifcant bit B0 is described by the position 0.
Type Function: DWORD
Input I: DWORD (input value)
D: BOOL (value of bits to be loaded)
P: INT (position of the bits to be loaded)
N: INT (number of bits that are loaded from position P)
Output DWORD (output)
BIT_LOAD_DW2 can set or delete multiple bits in a byte at the same time.
The position is indicated with 0 for Bit0 and 31 for Bit 31. N specifes how
many bits from the specifed location can be changed. If N = 0, no bits are
changed. If P and N is specifed that the bits to be written goes over the
highest bit (bit 31), so it starts again at bit 0.
Examples, see BIT_LOAD_B2
Type Function: WORD
Input IN: WORD (input)
VAL: BOOL (value of bits to be loaded)
POS: INT (position of the bits to be loaded)
Output WORD (output)
BIT_LOAD_W copies the bit at input VAL to the bit in position N in WORD
IN. The least signifcant bit B0 is described by the position 0.
Type Function: WORD
Input I: WORD (input value)
D: BOOL (value of bits to be loaded)
P: INT (position of the bits to be loaded)
N: INT (number of bits that are loaded from position P)
Output WORD (output)
BIT_LOAD_W2 can set or delete multiple bits in a WORD at the same time.
The position is indicated with 0 for Bit 0 and 15 for Bit 15. N specifes how
many bits from the specifed location can be changed. If N = 0, no bits are
changed. If P and N is specifed that the bits to be written goes over the
highest bit (bit 15), so it starts again at bit 0.
Examples, see BIT_LOAD_B2
Type Function: BOOL
Input IN: DWORD (input)
N: INT (number of bits 031)
Output BOOL (output bit)
BIT_OF_DWORD extracts a bit of the DWORD at the input IN.
Bit0 für N=0, Bit1 für N=1 and so on.
Type Function: BYTE
Input IN: BYTE (input data)
POS: INT (Position)
Output BYTE (output byte)
BIT_TOGGLE_B inverts a specifed bit at IN.
BIT_TOGGLE_W(2#0000_1111, 2) = 2#0000_1011
BIT_TOGGLE_W(2#0000_1111, 7) = 2#1000_1111
Type Function: DWORD
Input IN: DWORD (input data)
POS: INT (Position)
Output DWORD (output byte)
BIT_TOGGLE_DW inverts a specifed bit at IN.
BIT_TOGGLE_DW(2#0000_1111, 2) = 2#0000_1011
BIT_TOGGLE_DW(2#0000_1111, 7) = 2#1000_1111
Type Function: WORD
Input IN: WORD (input data)
POS: INT (Position)
Output WORD (output byte)
BIT_TOGGLE_W inverts a specifed bit POS at IN.
BIT_TOGGLE_W(2#0000_1111, 2) = 2#0000_1011
BIT_TOGGLE_W(2#0000_1111, 7) = 2#1000_1111
Type Function: BYTE
Input B0 B7: BOOL (input bits)
Output BYTE (output byte)
BYTE_OF_BIT uses one byte of 8 individual bits (B0 B7) together.
Type Function: BYTE
Input IN: DWORD (DWORD input)
Output BYTE (output byte)
BYTE_OF_DWORD extracts a byte (B0 B3) a DWORD. The individual by-
tes are selected with 0-3 at the input IN.
Type Function module
Input IN: BYTE (input byte)
Output B0 B7: BOOL (output bits)
BYTE_TO_BITS split a byte (IN) into its individual bits (B0 B7). The input
IN is defned as a DWORD to handle either byte, word, or DWORD at the
input. If a Word or DWORD used at the input, only the bits 0th .7 are pro-
cessed. A DWORD can then, using the default command SHR , be shifted
by 8 bits to the right and then the next byte can be processed.
Type Function: BYTE
Input IN: BYTE (input byte)
Output Byte (value in Gray code)
BYTE_TO_GRAY converts a byte value (IN) in the Gray code.
Type Function: BYTE
Input X: REAL (value to be tested)
Output BYTE (return value)
CHK_REAL reviewes X for valid values.
The return values are:
#00 valid foating-point
#20 + Infnity
#40 - Infnity
#80 NAN
For more information see the IEEE754 foating point specifcation.
Type Function: BOOL
Input IN: BYTE (input byte)
P: BOOL ( Parity-Bit)
Output BYTE (output is TRUE in even parity)
CHECK_PARITY checks an input byte IN and an associated paritybit P to
even parity. The output is TRUE if the number of bits in the byte IN have
the value TRUE together with the parity-bit results is an even number.
Example for output = TRUE:
Example output = FALSE:
The module CRC_CHECK was removed from the library because the func-
tionality can be fulflled in their entirety, with the module CRC_GEN.
Usually CRC_GEN generates a checksum which is is appended to the origi-
nal message. If we now build again the checksum of the message with an
attached checksum then the new checksum 0.
With some specifc CRC's where this is not the case, the checksum will be
created once again after receive of a message. The checksum is build
about all the transferred databytes without checksum and then is compa-
red with the transmitted checksum.
Type Function : DWORD
Input PT: POINTER TO ARRAY OF BYTE (data package)
SIZE: UINT (size of the Arrays )
Setup PL: UINT (length of the polynomial)
PN: DWORD (polynomial)
INIT: DWORD (INIT data)
REV_IN: BOOL (input data bytes invert)
REV_OUT: BOOL (invert output data)
XOR_OUT: DWORD (Last XOR of the output)
Output DWORD (calculated CRC checksum)
CRC_GEN generates a CRC check sum of an arbitrarily large array of Bytes.
When the function is called a Pointer is passed on the processed array and
its size in bytes. In CoDeSys the call reads: CRC_GEN(ADR(array),
SIZEOF(Array),.), where array is the name of the processed array. ADR is
a standard function, the Pointer the array is determined and SIZEOF is a
standard function, which determines the size of the array. The polynomial
can be any polynomials up to a maximum of 32 bits in length. A polynomi-
al X³ + X² + 1 is represented by 101 (1*X³ + 1*X² + 0+X¹ + 1*X⁰). The
most signifcant bit, in this case 1*X³ is not specifed in the polynomial, be-
cause it is always one. It can process up polynomials to X³² (CRC 32). By
the value INIT, the CR can be passed a starting value. Usually are here are
0000 and FFFF. The appropriate start value is the standard in the litera-
ture, "Direct Initial Value". The input XOR_OUT determines with which bit
sequence with the checksum at the end of XOR is associated with. The in-
puts and REV_IN REV_OUT set the bit sequence of data. If REV_IN = TRUE,
each byte with LSB beginning is processed, if REV_IN = FALSE with MSB is
started. REV_OUT = TRUE turns the bit corresponding sequence to the
checksum. The module requires a minimum length of the processed data
of 4 bytes, and is limited up only by the maximum array size.
The CRC further down in the following table provides detailed information
on common CRC's and the setup data for CRC_GEN. Due to the number of
possible and even common CRC's, it is not possible for us to show a com-
plete list.
For further research, the website http://regregex.bbcmicro.net/crc-cata-
logue.htm is recommended.
Online test calculations are possible for the following Java Tool:
http://zorc.breitbandkatze.de/crc.html
Common CRC'S AND polynomials:
CRC PL PN [Hex] INIT [Hex] REV
IN
REV
OU
T
XOUT [Hex]
CRC-3/ROHC 3 3 7 T T 0
CRC-4/ITU 4 3 0 T T 0
CRC-5/EPC 5 9 9 F F 0
CRC-5/ITU 5 15 0 T T 0
CRC-5/USB 5 5 1F T T 1F
CRC-6/DARC 6 19 0 T F 0
CRC-6/ITU 6 3 0 T T 0
CRC-7 7 9 0 F F 0
CRC-7/ROHC 7 4F 7F T T 0
CRC-8 8 7 0 F F 0
CRC-8/DARC 8 39 0 T T 0
CRC-8/I-CODE 8 1D FD F F 0
CRC-8/ITU 8 7 0 F F 55
CRC-8/MAXIM 8 31 0 T T 0
CRC-8/ROHC 8 7 FF T T 0
CRC-8/WCDMA 8 9B 0 T T 0
CRC-10 10 233 0 F F 0
CRC-11 11 385 1A F F 0
CRC-12/3GPP 12 80F 0 F T 0
CRC-12/DECT 12 80F 0 F F 0
CRC-14/DARC 14 805 0 T T 0
CRC-15 15 4599 0 F F 0
CRC-16/LHA 16 8005 0 T T 0
CRC-16/CCITT-AUG 16 1021 1D0F F F 0
CRC-16/BUYPASS 16 8005 0 F F 0
CRC-16/CCITT-FALSE 16 1021 FFFF F F 0
CRC-16/DDS 16 8005 800D F F 0
CRC-16/DECT-R 16 589 0 F F 1
CRC-16/DECT-X 16 589 0 F F 0
CRC-16/DNP 16 3D65 0 T T FFFF
CRC-16/EN13757 16 3D65 0 F F FFFF
CRC-16/GENIBUS 16 1021 FFFF F F FFFF
CRC-16/MAXIM 16 8005 0 T T FFFF
CRC-16/MCRF4XX 16 1021 FFFF T T 0
CRC-16/RIELLO 16 1021 B2AA T T 0
CRC-16/T10-DIF 16 8BB7 0 F F 0
CRC-16/TELEDISK 16 A097 0 F F 0
CRC-16/USB 16 8005 FFFF T T FFFF
CRC-16/CCITT-TRUE 16 1021 0 T T 0
CRC-16/MODBUS 16 8005 FFFF T T 0
CRC-16/X-25 16 1021 FFFF T T FFFF
CRC-16/XMODEM 16 1021 0 F F 0
CRC-24/OPENPGP 24 864CFB B704CE F F 0
CRC-24/FLEXRAY-A 24 5D6DCB FEDCBA F F 0
CRC-24/FLEXRAY-B 24 5D6DCB ABCDEF F F 0
CRC-32/PKZIP 32 04C11DB7 FFFFFFFF T T FFFFFFFF
CRC-32/BZIP2 32 04C11DB7 FFFFFFFF F F FFFFFFFF
CRC-32/CASTAGNOLI 32 1EDC6F41 FFFFFFFF T T FFFFFFFF
CRC-32/D 32 A833982B FFFFFFFF T T FFFFFFFF
CRC-32/MPEG2 32 04C11DB7 FFFFFFFF F F 0
CRC-32/POSIX 32 04C11DB7 0 F F FFFFFFFF
CRC-32/Q 32 814141AB 0 F F 0
CRC-32/JAM 32 04C11DB7 FFFFFFFF T T 0
CRC-32/XFER 32 AF 0 F F 0
Type Function module
Input D: BOOL (input bit)
A: BOOL (address)
Output Q0: BOOL (TRUE if A=0)
Q1: BOOL (TRUE if A=1)
DEC_2 is a 2-bit decoder module. If A=0, the input D is passed to output
Q0. If A=1, so D is set to Q1. In other words, Q0=1 if D=1 and A=0
Logical connection: Q0 = D & /A; Q1 = D & A
Type Function module
Input D: BOOL (input bit)
A0: BOOL (address bit0)
A1: BOOL (address bit1)
Output Q0: BOOL (TRUE with A0=0 and A1=0)
Q1: BOOL (TRUE if A0=1 and A1=0)
Q2: BOOL (true when A0=0 and A1=1)
Q2: BOOL (true when A0=0 and A1=1)
DEC_4 is a 4-bit decoder module. If A0=0 and A1=0, the input D is passed
to output Q0. If A0=1 and A1=1, the input D is passed to output Q3. In
other words, Q0=1, if D=1 and A0=0 and A1=0.
Logical connection: Q0 = D & / A0 & / A1
Q1 = D & A0 & /A1
Q2 = D & /A0 & A1
Q3 = D & A0 & A1
Type Function module
Input D: BOOL (input bit)
A0: BOOL (address bit0)
A1: BOOL (address bit1)
A2: BOOL (address bit 2)
Output Q0: BOOL (TRUE with A0 = 0 and A1 = 0 and A2 = 0)
Q1: BOOL (TRUE = 1 with A0 and A1 = 0 and A2 = 0)
Q2: BOOL (true when A0 = 0 and A1 = 1 and A2 = 0)
Q3: BOOL (TRUE with A0 = 1 and A1 = 1 and A2 = 0)
Q4: BOOL (TRUE with A0 = 0 and A1 = 0 and A2 = 1)
Q5: BOOL (TRUE with A0 = 1 and A1 = 0 and A2 = 1)
Q6: BOOL (TRUE with A0 = 0 and A1 = 1 and A2 = 1)
Q7: BOOL (TRUE with A0 = 1 and A1 =1 and A2 = 1)
DEC_8 is an 8-bit decoder module If A0 = 0 and A1 = 0 and A2 = 0, the D
input is pased to output Q0, if A0 = 1 and A1 = 1 and A2 = 1 the D is
connected to Q3. In other words, Q0 = 1 if D = 1 and A0 = 0 and A1 = 0
A2 = 0.
The following diagram illustrates the logic of the module:
Logical connection:
Q0 = D & /A0 & /A1 & /A2 Q1 = D & A0 & /A1 & /A2
Q2 = D & /A0 & A1 & /A2 Q3 = D & A0 & A1 & /A
Q4 = D & /A0 & /A1 & A2 Q5 = D & A0 & /A1 & A2
Q6 = D & /A0 & A1 & A2 Q7 = D & A0 & A1 & A2
Type Function: REAL
Input X: DWORD (input)
Output REAL (output value)
DW_TO_REAL copies the bit pattern of a DWORD (IN) to a REAL. These bits
are copied without regard to their meaning. The function REAL_TO_DW is
the inverse so that the conversion of REAL_TO_DW and then DW_TO_REAL
result in the output value. The IEC standard DWORD_TO_REAL function
converts the value of the DWORD to a REAL value.
Type Function: DWORD
Input B3: Byte (input byte 3)
B2: Byte (input byte 2)
B1: Byte (input byte 1)
B0: Byte (input byte 0)
Output DWORD (DWORD result)
BYTE_OF_BIT creates from 4 individual bits (B0 B3) a DWORD.
A DWORD is composed as follows: B3-B2-B1-B0.
Type Function: DWORD
Input W1: WORD (Input WORD 1)
W0: WORD (Input WORD 0)
Output DWORD (DWORD result)
DWORD_OF_WORD creates from 2 separate WORDS W0 und W1 a
DWORD.
A DWORD is composed as follows: W1-W0.
Type Function
Input IN: BYTE (Gray coded value)
Output Byte (Binary Value)
GRAY_TO_BYTE converts a Gray-coded value (IN) in a byte.
Type Function: BYTE
Input IN: INT (input)
Output BYTE (BCD coded output value)
INT_TO_BCDC converts the input value IN to a BCD coded output value.
Type Function module
Input X1 X5: BOOL (line inputs)
Setup RELEASE: BOOL (a key code when you press and
release of a key generated)
Output CODE: Byte (output for key code)
TP: BOOL (TP is TRUE for one cycle when a new
Key code is present)
Y1 Y4: BOOL (line outputs)
MATRIX is a matrix keyboard controller for up to 4 columns and 5 rows.
With each PLC cycle on the MATRIX column switch the output further for a
column so that the lines Y1 to Y4 are queried one by one. For each co-
lumn, the row inputs X1 to X5 are queried and if a button is pressed, the
corresponding key code is displayed on the output. The output of TP is a
cycle set to TRUE if the output CODE indicating a new value. If the setup
variable RELEASE is set to TRUE, then for pressing and releasing a button
each sent a key code. If RELEASE is set to FALSE, a key code is generated
only when a button is a pressed. The key code of the output is as follows:
Bit CODE Output
7 1 when key is pressed, 0 when key is released
6 Line number Bit 2
5 Line number Bit 1
4 Line number Bit 0
3 Always 0
2 Row number Bit 2
1 Row Number Bit 1
0 Row Number Bit 0
The matrix controller is wired as follows:
This simple circuit can analyze up to 20 (4 * 5) keys. However, it should be
noted here that only in cases a number of keys can be pressed simulta-
neously. The controller can handle with this circuit, several buttons in a co-
lumn in any doubt, but not when keys are pressed simultaneously on dife-
rent columns. The wiring may be extended by each button is decoupled
via diodes, and thus the in fuence of di ferent
columns to one another is prevented. In the circuit with diodes, any num-
ber of keys at a time and be evaluated safely. The outputs of the matrix
controller continuously scan the rows of the keyboard matrix. On every
PLC cycle one line is read. If in a row more keys have been pressed or
changed, the changes are displayed as codes of the following cycles. The
module stores the individual key codes and gives each cycle consisting of
only one code so that no code can be lost.
The following timing diagram shows the scanning of rows of keys:
Type Function: BOOL
Input D0: BOOL (Bit 0)
D1: BOOL (Bit 1)
A0: BOOL (address)
Output BOOL (D0, when A0 = 0 and D1, when A0 = 1)
MUX_2 is a 2-bit Multiplexer. The output corresponds to D0 when A0 = 0
and it corresponds to D1, if A0 = 1
Logical connection: MUX_2 = D0 & /A0 + D1 & A0
Type Function: BOOL
Input D0: BOOL (input 0)
D1: BOOL (input 1)
D2: BOOL (input 2)
D3: BOOL (Input 3)
Output BOOL (D0, if A0 = 0 and A1 = 0, etc. )
MUX_4 is a 4-bit Multiplexer. The output corresponds to D0 when A0 = 0
and A1 = 0 It corresponds to D3, if A0 = 1 and A1 = 1.
Logical connection: MUX_4 = D0 & /A0 & /A1 + D1 & A0 & /A1
+ D2 & /A0 & A1 + D3 & A0 & A1
Type Function: BOOL
Input IN: BYTE (BYTE input)
Output BOOL (output is TRUE if parity is even)
PARITY calculates even parity over the input byte IN. The output is TRUE if
the number of true bits in the byte (IN) is odd.
Type Function module
Input CB: BYTE (input)
E: BOOL ( Enable Input)
SETUP PIN: STRING(8) (String to be tested )
Output TP ( Trigger Output)
PIN_CODE checks a stream of bytes for the presence of a specifc se-
quence. If the sequence is found, this is indicated by a TRUE at output TP.
In the following example, two modules PIN_CODE be used to decode two
CODE_SEQUENCES of a matrix keyboard.
Type Function: DWORD
Input IN: REAL (input)
Output DWORD (output value)
REAL_TO_DW copies the bit pattern of a REAL (IN) in a DWORD. These bits
are copied without regard to their meaning. The function REAL_TO_DW is
the inverse so that the conversion of REAL_TO_DW and then DW_TO_REAL
result in the output value. The IEC standard function REAL_TO_DWORD
converts the REAL value to a fxed numerical value and is rounded at the
lowest point of the DWORD.
Type Function: DWORD
Input D: DWORD (input)
L: INT (number of bits to be rotated)
Output DWORD (output value)
REFLECT reverses the order specifed by the number of L BitsBits in a
DWORD. The most signifcant bits than specifed by the length L remain
unchanged.
Example: REVERSE(10101010 00000000 11111111 10011110, 8)
results 10101010 00000000 11111111 01111001
Example: REVERSE(10101010 00000000 11111111 10011110, 32)
results 01111001 11111111 00000000 01010101
the following example in ST would reverse all the bytes in a DWORD X, but
the byte order remains:
FOR i := 0 TO 3 DO
REVERSE(X, 8);
ROR(X,8);
END_FOR
Type Function: BYTE
Input IN: BYTE (BYTE input)
Output BYTE (Byte Output)
REVERSE reverses the order of the bits in a byte. Bit7 of IN becomes bit 0,
bit 6 to bit 1, etc.
Example: REVERSE(10011110) = 01111001
Type Function: DWORD
Input IN: DWORD (input data)
N: INT (number of bits to be shifted)
Output DWORD (Result)
SHL1 shifts the input DWORD for N bits to the left and flls the right N bits
with 1. In contrast to the IEC standard function SHL, which flles when pu-
shing with zeros, at SHL1 is flled with ones.
Example: SHL1(11110000,2) results 11000011
Type Function: DWORD
Input IN: DWORD (input data)
N: INT (number of bits to be shifted)
Output DWORD (Result)
SHR1 pushes the input to N bits to the right and flls the left N bits with
1's. In contrast to the IEC standard function SHL, which flles when pushing
with zeros, at SHR1 is flled with ones.
Example: SHR1(11110000,2) results 11111100
Type Function: WORD
Input IN: WORD (input data)
Output WORD (result)
SWAP_BYTE exchanges the High and Low Bytes in a WORD.
Example: SWAP_BYTE(16#33df) = 16#df33.
Type Function: DWORD
Input IN: DWORD (input data)
Output DWORD (Result)
SWAP_BYTE2 reverses the order of bytes in a DWORD.
Example: SWAP_BYTE2(16#33df1122) = 16#2211df33.
Type Function: WORD
Input B1: Byte (input byte 1)
B0: Byte (input byte 0)
Output Word (Word Score)
WORD_OF_BYTE composes a Word of 2 separate bytes B0 and B1.
Type Function: WORD
Input IN: DWORD (DWORD input)
Output WORD (output WORD)
WORD_OF_DWORD extracts a word (W0 W1) from a DWORD.