Converting from Decmial to Hex in Ladder

Thanks guys for the feedback, Ill try all the methods and see which method works best, because ultimately I'm going to create an add on instruction that will specifically work with the yaskawa v1000 VFD, but atleast now I know how to do it. @Geospark to answer your question, their is a fault code table that displays the fault codes in hex, however their are different fault codes that use the same fault code value . Example 8000 in hex could mean undervoltage fault or over current etc. so to avoid confusion of which fault code it may be if we just display the fault code, it would force the person to go look up the possible faults based on that fault code. I know we can do the same thing in the logic such that if this is the fault code then list the many possibilities it may be, so to answer your question I guess they preferred it their way.
 
@ Bernie, i tried the method you posted and it works well. However im trying to understand
how its working. Here is where i get a bit lost,

Step 1: first you AND the SourceDINT tag with 16#F000 store, then store the value in temp1
Step 2: Then we multiply temp1 by a 1000 then with that value we divide by 4096(really just shifting the value)
by 12 to the right

and the steps continue with the same SourceDINT Anded with 16#F00, then 16#F0, then 16#F, and also

My question is why are we multiplying Temp 1 fist with a 1000? then when we are Anding the SourceDINT
with 16#F00 we (Target+((Temp1*100))/256, i understand the dividing the 256 which is shifting to the right by
8 but why multiply by 100? and on top of that add that OR Target???

I hope i'm not vague, but if i can understand that then the rest will be easy, so if you habe the time please
thanks.
 
[Edit: by 'picking off' I really meant 'isolating' the nibbles. They still have their positional value. If the SourceDINT - in hex - had 5734 then the ANDing by 16#F000 gives 5000 hex.]

The algorithm is picking off the 4 bit nibbles one at a time.

let's talk about the first one, picked off by ANDing with 16#F000. Let's say the nibble had '1' - the whole DINT in hex being 1xxx.

Break out your windows calculator. Set it to 'hex' and enter '1000'. Now click 'Dec'. That '1' in the leftmost hex position is actually equal to 4096. But, in the end we will want the leftmost Decimal number to read 1000 (or 1xxx if there are other hex numbers, but let's keep it simple.

So we'll have to decrease this number by the ratio of 1000/4096, which the second instruction does. (it works for 0 and 2-9 also)

Similarly for the other nibbles. By checking we see that we will have to decrease them by the ratios of 100/256, 10/16, and finally 1/1 (no change)

It does this conversion one nibble at a time and adds the result into the final target.

have fun.
 
Last edited:
@ bernie, by any chance do you have a .pdf (reference) or a book that has a lot of sample problems examples of bit manipulation, that could even better my understanding of this? if you do please send it my way
 
In case my description was a bit confusing here's another yielding exactly the same algorithm.

AND with 16#F000 giving x000
shift 3 HEX places to the right by dividing by 1000 HEX (4096)
shift back 3 DECIMAL places to the left by multiplying by 1000

AND with 16#F00 giving 0x00
shift 2 HEX places to the right by dividing by 100 HEX (256)
shift back 2 DECIMAL places to the left by multiplying by 100

AND with 16#F0 giving 00x0
shift 1 HEX place ti the right by dividing by 10 HEX (16)
shift back 1 DECIMAL place to the left by multiplying by 10

AND with 16#F giving 000x
no shifting is necessary
 
thanks, once again, let me know if you come across good sample problems,.pdf reference or anything else that can help me master this subject
 
I can't thing of a single reference I have used. Just learning about various number systems then the concepts of right shifting by dividing and left shifting by multiplying.

Phil's tutorial (Learn PLCs above) has a section on number systems.
 
@ Okie PC by the time im done with this bit manipulation my eye sight will go from 20/20 to 0/20 from looking at these 0's and 1's lol but thanks for the link looks like it will really help
 
So... what HMI is it? Just in case it can display Hex and you're just missing it.

And if I read that correctly, what you've got is a binary-coded-decimal fault code, which can be converted to binary/decimal using the FRD instruction.

But I like the idea of the multi-state fault display device as well. That can be extremely useful.
 

Similar Topics

Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
209
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
122
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
320
Hello, did anybody know, if there exist an converting cable like the1492-CM1746-M01 (for an 1746-IB16 to an 5069-IB16), for an 1746-HSCE to an...
Replies
3
Views
390
Hello, This will be my first time converting powerflex 40's and 400's from devicenet to ethernet. I did some research, and it seems I will need...
Replies
4
Views
759
Back
Top Bottom