Omron CP1E Barcoding

treb_ron

Member
Join Date
Sep 2019
Location
Batangas
Posts
3
Good day,

Im just a beginner to intermediate PLC programmer..
Im not familiar with data manipulation..

I have a W1 & W2 data..
W1= 03 (#3033)
W2= 95 (#3935)
395 pcs on barcode

and
W11= 22 (#3232)
W12= 30 (#3330)
2230 pcs on barcode

How can i compare this values? I will need the smaller value or equal.. should be the 395.

And then i will use the 395 value as counter max value..
 
First of all you need to convert the codes into a decimal value.
I have little experience with Omron CP processors, and do not know all the instructions, however assume this processor is limited the best way is as following.
assume you have words containing 3031, 3233, this is the ASCII equivalent of "0123" in decimal so first take the 3031 word AND it with Decimal 15 this will give you "1" and store it in a register, shift the word right 8 places, AND it with 15 this will give you "0", do the same with the second word and you will have four words with the digits 1,0,3,2 but obviously these are in wrong order, assume these are W1,W2,W3,W4 then multiply
W1 by 100, hundreds
W2 by 1000, thousands
W3 by 10, tens
W4 by nothing as this is units
Add words 1,2,3,4 gives you 0123 decimal, do this for all the values then compare for lowest.
I know Omron have these simple instructions in some form
So to re-iterate:
AND Word 1 with 15 & store in Word x
Shift Right 8 bits Word 1 to remove lower byte & put upper byte in lower byte (or swap bytes if instruction is available).
AND It with 15 & Store in word x+1
do same for word 2
You then have 4 words with decimal equivalents of the data,Multiply all words by their respective multiplier
Add them up & store decimal value You will need to find the instructions Omron have in this CPU I believe they have NASR (Bit Shift) & SWAP (swap bytes).
If I had to do this in Siemens It would look something like this

L DW 100 'first word W1 Hex 3031
L KF 15 ' Mask Decimal 15, Hex F
AW 'AND it
L KF 100 '100's Multiplier
XF ' multiply
T DW 200 'Store value 1 Hundreds
L DW 100
SRW 8 ' Shift right to get upper byte into lower byte = H0030
LKF 15 'Mask
AW
L KF 1000 ' Thousand's multiplier
XF
T DW 201 'Store value Thousands (0)
L DW 101 ' Second word W2 Hex 3233
L KF 15 ' Mask
AW ' No need for multiplier as this is units
T DW 202 ' Store Value 3
L DW 101
SR W 8
L KF 15
AW
L KF 10 ' Tens multiplier
XF
T DW 203 ' Store Value 20 (2)
L DW 200 ' Hundreds
+F ' ADD
L DW 201 ' Thousands
+F
L DW 202 ' Units
+F
T DW204 ' Decimal value 0123
In actual fact, this is just to show the steps to convert from hex (ASCII) to a decimal value, I could have done this using things like TAK instructions to reduce the use of data words or other instructions before anyone criticises it.

Edit: Garry: Good point, however, he needs a decimal value for a counter value according to the post.
 
Last edited:
No problem Garry, we have all done it, by the time a reply has been typed it's easy to forget some of the posts (especially me, I call it old age lol.) Not being familiar with the later OMRON range I don't know what instructions are available.
 
First of all you need to convert the codes into a decimal value.
I have little experience with Omron CP processors, and do not know all the instructions, however assume this processor is limited the best way is as following.
assume you have words containing 3031, 3233, this is the ASCII equivalent of "0123" in decimal so first take the 3031 word AND it with Decimal 15 this will give you "1" and store it in a register, shift the word right 8 places, AND it with 15 this will give you "0", do the same with the second word and you will have four words with the digits 1,0,3,2 but obviously these are in wrong order, assume these are W1,W2,W3,W4 then multiply
W1 by 100, hundreds
W2 by 1000, thousands
W3 by 10, tens
W4 by nothing as this is units
Add words 1,2,3,4 gives you 0123 decimal, do this for all the values then compare for lowest.
I know Omron have these simple instructions in some form
So to re-iterate:
AND Word 1 with 15 & store in Word x
Shift Right 8 bits Word 1 to remove lower byte & put upper byte in lower byte (or swap bytes if instruction is available).
AND It with 15 & Store in word x+1
do same for word 2
You then have 4 words with decimal equivalents of the data,Multiply all words by their respective multiplier
Add them up & store decimal value You will need to find the instructions Omron have in this CPU I believe they have NASR (Bit Shift) & SWAP (swap bytes).
If I had to do this in Siemens It would look something like this

L DW 100 'first word W1 Hex 3031
L KF 15 ' Mask Decimal 15, Hex F
AW 'AND it
L KF 100 '100's Multiplier
XF ' multiply
T DW 200 'Store value 1 Hundreds
L DW 100
SRW 8 ' Shift right to get upper byte into lower byte = H0030
LKF 15 'Mask
AW
L KF 1000 ' Thousand's multiplier
XF
T DW 201 'Store value Thousands (0)
L DW 101 ' Second word W2 Hex 3233
L KF 15 ' Mask
AW ' No need for multiplier as this is units
T DW 202 ' Store Value 3
L DW 101
SR W 8
L KF 15
AW
L KF 10 ' Tens multiplier
XF
T DW 203 ' Store Value 20 (2)
L DW 200 ' Hundreds
+F ' ADD
L DW 201 ' Thousands
+F
L DW 202 ' Units
+F
T DW204 ' Decimal value 0123
In actual fact, this is just to show the steps to convert from hex (ASCII) to a decimal value, I could have done this using things like TAK instructions to reduce the use of data words or other instructions before anyone criticises it.

Edit: Garry: Good point, however, he needs a decimal value for a counter value according to the post.

Thank you all for the reply..

How to AND 3031 to 15??
I dont find any AND instruction on omron..
 
Here is the manual:
https://assets.omron.eu/downloads/manual/en/v2/w483_cp1e_instructions_reference_manual_en.pdf
The function to "AND" two words is ANDW it takes two input parameters and outputs a result
See Attached images & program written in Mitsubishi GX Works, however the functions may not be the same but will give you an idea, note: I could have done this in true IEC but not sure what your software is like so is a bit long winded as in IEC you can mix functions.

Results Hex.png Results in Decimal.png
 

Attachments

  • ASCII.pdf
    31.3 KB · Views: 12
Im using an Omron PLC (CP1E) and CX Programmer..
I manage to separate all the four digits into four words by using MOVD & NSRL instruction..
All 4 digits were already a decimal value after data shifted then subtract by 48 (&48)..
Thank you all for the help..
 

Similar Topics

Hello. I have a problem with omron sysmac cp1e controller delayed start. The controller has been working on the punch press since 2016. Recently...
Replies
1
Views
766
Hi, I need to communicate omron CP1E PLC with SCADA to get the status of the machine. There is no etherent port available but an empty expansion...
Replies
2
Views
1,612
Hello... I remove one CP1E from old useless machine and I would like to use it with something else....but it is locked/have no pass/....How can I...
Replies
0
Views
1,451
hi all i have used a real time clock to turn on a bit after 1 month. the plc was off for this whole month and when i turned on the plc after a...
Replies
2
Views
1,427
We had a CP1E go bad (power issue). Installed spare and could not get it to communicate to our motion drive via add on RS485 card. Tried...
Replies
5
Views
1,509
Back
Top Bottom