BCD conversion

bigrthanur

Member
Join Date
Mar 2007
Location
Ohio
Posts
85
Hello!

I am working on a project and have a question. I need to take a 16 bit word and convert it into bianary 1's and 0's. I will be pulling the word into a register value in a Fanuc robot. I need to take that word convert it. and distribute them.

My question is how can I do this mathmatically? Any suggestions?



Thanks
 
Are you converting your 16 bit word from BCD to binary with the result going into a word (range of values 0000 to 9999) or,
Converting a 16 bit word from binary to BCD (range 00000 to 65535)
 
Not familure with GE however some plc's you can read the indivdual bits in a word i.e. in siemens db10.dbx1.0 or in others D100.0 etc.
in mitsi mov d0 M100 k4 will move the binary value of D0 into m100-115
or you could do compare 16 times (or in a loop indirectly)
i.e.
register // 16 bit register to convert
loop int // loop counter
test int // test word
binarybit array(0..15) of binary
Start of code
move 0 loop //loop counter
mov 1 test //test word
Back:
if Register and test <> 0 then binarybit[loop] = 1
else binarybit(loop) = 0
endif
increment loop
test = test *2
if loop > 15 then exit
else goto Back

in mitsi
the code would look like the attachment (although as above you would have no need as you can transfer words into binary flags)
 
I will be taking a 16 bit BCD word say the number 4567. and converting it back to 16 bit bcd which would be:
0001000111010111


But how would I do this using a mathmatic function?
 
Is this what you have?
You have a BCD word from somewhere, and you are writing it to a Fanuc robot, and inside the robot controller you need to convert it to a 16 bit digital word.
 
Is this what you have?
You have a BCD word from somewhere, and you are writing it to a Fanuc robot, and inside the robot controller you need to convert it to a 16 bit digital word.

that is exactally what i have. I will be putting the 16 0's and 1's into various registers inside the robot. Just need a way to convert the info to the 1's and 0's.
 
Still not clear, are you converting the BCD outside the Fanuc controller, and then transferring? If so, what are you using for the conversion, excel, plc, calculator, the old mark 5 eyeball and brain?
 
Still not clear, are you converting the BCD outside the Fanuc controller, and then transferring? If so, what are you using for the conversion, excel, plc, calculator, the old mark 5 eyeball and brain?

I will be doing the conversion inside the controller using a math function That I enter in. Just need an equation that will do the math for me.
 
The answer that hits me is divide or multiply by 10 when in binary or BCD maths, or even Hex
But then I am like others and dont quite see what you want of the final result
 
First check and see if the PLC has an instruction to do it. Most do.

If it doesn't then the basic equation is:

(N & 000Fh) + (((N & 00F0h)>>4) * 10) + (((N & 0F00h)>>8) * 100) + (((N & F000h)>>12)*1000)

You probably won't be able to program that in a single equation though. To shift the bits in the PLC after anding with the mask you will most likely need to divide by 2^x where x is the number of bits to shift.

The AB PLC has an instruction to do it, but without one it would do something like what I banged out in a couple of minutes on the attached PDF.
 
First check and see if the PLC has an instruction to do it. Most do.

If it doesn't then the basic equation is:

(N & 000Fh) + (((N & 00F0h)>>4) * 10) + (((N & 0F00h)>>8) * 100) + (((N & F000h)>>12)*1000)

You probably won't be able to program that in a single equation though. To shift the bits in the PLC after anding with the mask you will most likely need to divide by 2^x where x is the number of bits to shift.

The AB PLC has an instruction to do it, but without one it would do something like what I banged out in a couple of minutes on the attached PDF.

Yes the PLC does have an instruction to do this. But The Robot controller does not. That is why i need to do the conversion inside the robot. But doesnt look like I can find an easy conversion method
 
You say "Yes the PLC does have an instruction to do this. But The Robot controller does not" If thats the case why not convert it in the PLC before you send it to the robot?
 
But doesnt look like I can find an easy conversion method
What's hard about
(N & 000Fh) + (((N & 00F0h)>>4) * 10) + (((N & 0F00h)>>8) * 100) + (((N & F000h)>>12)*1000) ?

If the robot controller has the instructions to do a bitwise AND, Division, Multiplication, and Addition, it can do it.
 
Last edited:
bigrthanur,

can you please provide more detail? for example what is the plc? it has been asked before but i have to agree: if the plc can do conversion (most do), why bother translating value in the fanuc controller?
 

Similar Topics

hi... i have an issue in s7 300 plc, while we run the machine(in idle there is no fault) , plc cpu goes in SF mode, after restart the power cycle...
Replies
2
Views
107
Hi. I’m doing a PV 1400e to PVP 7 migration and I don’t know how to convert the old 8digit BCD type from PB1400e into something that will work on...
Replies
2
Views
586
Hi there. I have a Micrologix 1100, I have 6 switches to I:0/0 through I:0/5. My plan is to use I:0/0 to I:0/3 as set for a value of 0-15. I:0/4...
Replies
3
Views
1,691
Hi all, I am quite new to PLC programming, so pardon my noob-ness. First, I have counters & timers in my program that I use to calculate total...
Replies
2
Views
3,534
Hi, I recently added a BCD to int conversion block to compare 2 MW. The CPU has a SF error.In the diagnostic area it shows BCD conversion error. I...
Replies
1
Views
5,001
Back
Top Bottom