Splitting an Integer

COOPINIHO

Guest
C
I have a Mitsubishi Q01 PLC which seems not up to the job really as the functions I need are'nt supported by it.

what i'm struggling to do:

I have an integer D48 which contains the value 1234
i need to seperate this integer into sepearte memory areas.

i.e d48 character 1 into mem d300
d48 character 2 into mem d301
etc..

I don't really know how to do this with this plc as it has very few functions.
 
Let's see, assuming all integer data types,

1234/1000 should return a value of one, your most significant digit. Put it where you need it. Careful, careful--a value of 1634 may, depending on the PLC, return a value of 2, as it rounds the result up. If the result*1000 is greater than the original value, it was rounded up--subtract one to undo the rounding and put it where you want.

Multiply the MSD by 1000 and subtract it from the original number. 1234-(1*1000)=234. Divide 234 by 100 and do the same as above but by 100's not 1000's.

Then tens till you've only the LSD left over.

It's a long way around but if this stuff was easy, they'd have women and children doing it!
 
i've heard many things but this is the first time someone actually
complained about diversity in mitsubishi instruction set. :D

to be honest i don't understand the question...
(well... there is no question!?)

since you are asking about characters, i guess you are dealing
with strings. one character is presented with 8-bit or one byte.

one D word in Mitsubishi PLC is 16-bit integer. Ok it makes sense now...

This can be done using different ways but how about the most
obvious way - boolean logic?

WAND D48 H0FF D300  (move lower 8-bit to D300)
WAND D48 HFF00 D301 (move upper 8-bit to D301)
SWAP D301 (swap upper and lower byte in D301)



------------ EDIT --------------

Maybe you want them in different order? Just swap D300 and D301...
 
Last edited:
Panic,


I don't think that's what he wants. I think he wants the 1 here, the 2 there, the 3 someplace and the 4 someplace else.

The bit distribution would work with BCD but not integer data, I think.

I just saw the part about the strings--1234 would take 2 integers for the 4 characters--I think he's got an integer.

I don't think there is a ladder tool tha does what he wants, thus the math stuff. Get a result of some math in the desired data type.

Once I had to configure a module with integer data that allowed a setpoint of 99999999. The method was to pass the 4 Msd's as one integer and the 4 Lsd's as another. Similar math was used to break them apart.
 
Last edited:
john


it looks like you are right, i tend to skip... :p

... but there is a cure. i'd probably try simple BINDA + DIS.
i sure don't remember using such instructions lately, but if some PLC
is to have something like this, it is going to be mitsubishi.
also check:
BINDA, DBINDA, STR, DSTR, DIS and UNI (should be same for
both A and Q-mode, just get the SH_NA_080039-H manual from
mitsi website www.meau.com).

COOPINIHO is just getting familiar with it and soon he will
be overwhelmed with list of instructions long some 11 pages
if i counted right (check the index).
 
Last edited:
Thanks for the advice,

Used a BCD function to split the numbers initally into actual integer characters and then the WAND function and then rotated the BCD word and extracted the number needed with AND (used as a mask) and just kept repeating until all the numbers were extracted. Abit long winded but its my fault for buying a Q01 and not the better Q02.

THANKS!
 

Similar Topics

I am close to wits end and would appreciate any new perspective. Cannot go into minutia, but here is a rough rundown of the system and issue we...
Replies
26
Views
9,239
I have to take a 16 bit N register and split some of the bits into separate integers. example: Bits 0-1 = integer with a value from 0-3 Bit 2 is...
Replies
22
Views
5,823
Would it be wise / safe to split a 24vdc input from a switch to a PLC and relay? I currently have 14 of the same type of equipment that each have...
Replies
2
Views
1,526
Any one know of way to split a 4-20 mA signal 4 ways? Do they even make such a device? Thanks
Replies
12
Views
3,625
I have an application where I need a single SSI encoder to connect to both a safety controller (SICK Flexi Soft) and a general-purpose PLC...
Replies
3
Views
2,078
Back
Top Bottom