BCD2Decimal

vidi0816

Member
Join Date
Sep 2006
Location
Salatiga
Posts
18
I want to know how to :
(a)convert a BCD value to decimal Value ?
(b)convert a Decimal value to BCD value ?

I use schedule interrupt to reading Input High Speed Counter and succesfull. My problem is, how to catch up a value from schedule interrupt to Main program (as feedback system) ???

NB. I use Omron CPM2B (CPM2A/2C) PLCs

Thanks a lot.

Regards,

Adi P.Nugroho
SWCU-Indonesia
 
yes i know it

I have it, but there is just BCD convertion to HEX, manipulation with ADD,SUB,MUL,DIV only in BCD (simple or with Long BCD). there is no idea for convert to Decimal and Decimal to BCD at all.

There is no idea how to catch up a value from schedule interrupt to Main Program too.

Please help me,ASAP!

Thank you

Adi P.Nugroho
SWCU-Indonesia
 
I could be wrong here but this is the way I think of it. If using CX Programmer and you have a newer plc, define every thing as a int. Then just use the binary commands, it all comes out in the wash, hit the base 10 +/- tab so the numbers make sense and your off. If you are going to persist with bcd look at it this way BCD is binary coded decimal so it is hex but only using numbers 0-9 and no abc s. So your range is 0000 - 9999, the only time you should use it is in counters and timers. BCD math will do your head in. Things never turn out as expected. And signed BCD is even worse. Hex and binary are more or less the same thing so bcd to binary command gets you most of the way. So if you work with ints bcd to binary is the same as bcd to int. Good luck.
If I have to do a bit of math I use a script fb. Its hungry on the word count so don't do it all the time.
Good Luck
 
If the int option isn't going to work then you may want to do every thing in hex, the only time it gets messey is with negatives as you have to take the 2's complement. And a calculator with a hex to dec button is handy. Ormons don't lend them selff towards math, but it can be done.
 
How about BIN (binary) and BINL (binary long)? At the end of the day binary and hex are the same thing, it is only the way you display them that makes any difference.
If you want to do a compare, use the windows calculator to convert the values so that you can see what to compare with.
 
Actually, a BCD value already is the decimal value, but written in binary.
The value is the same, only represented in different radix. For PLC no conversion is necessary.

If the question is how to visualize the BCD in decimal, then the answer is- decode each nibble (4 bits) to decimal digit. Start from right, because the number of bits may be not multiple of 4.
 
Perhaps if vidi0816 gives a better explanation of what he is trying to do, then we could offer better solutions, sounds like he is trying to read a pulse value, and then do something in his code relative to the error, as he has posted in another thread.
 
YES...this is my solution, i just confuse about how to read a value in ladder.

Thanks for all explanation to me.
I already have a other problem with "negative multyply"
please still on me!

Best regards,

Adi P.Nugroho
SWCU-Indonesia

Sergei Troizky said:
Actually, a BCD value already is the decimal value, but written in binary.
The value is the same, only represented in different radix. For PLC no conversion is necessary.

If the question is how to visualize the BCD in decimal, then the answer is- decode each nibble (4 bits) to decimal digit. Start from right, because the number of bits may be not multiple of 4.
 
The same problem I has with CX programmer. Ladder shows parameters in hexadecimal format. I was curiuos about this.

On the top of work area there are icons to view in decimal format.

Clicking did not help me. I was sure that I see decimal numbers,but it was hexadecimal.

Numbers in decimal starts &xxx.

Till this moment not clear for me. I just moved from Siemens to OMRON.
It is neccesary to clear out. If problem persist send me e-mail. I'm going to visit Omron specialists next week.

Ramunas
 
I Think, when you want a decimal for the first time, maybe you was converted to something else, so the value is &xxxx. I think your value must be in binary first.


ramaslabas said:
The same problem I has with CX programmer. Ladder shows parameters in hexadecimal format. I was curiuos about this.

On the top of work area there are icons to view in decimal format.

Clicking did not help me. I was sure that I see decimal numbers,but it was hexadecimal.

Numbers in decimal starts &xxx.

Till this moment not clear for me. I just moved from Siemens to OMRON.
It is neccesary to clear out. If problem persist send me e-mail. I'm going to visit Omron specialists next week.

Ramunas
 
There are 3 buttons available when on line with CX-Programmer. One shows all values as decimal, one as signed decimal and the other as hex.The other option is to give the channel (usually a DM) a symbol in the symbol editor and select the display type there. There are many more options asuch as long, float, BCD etc etc.
 
Back
Top Bottom