adccommunitymod (AutomationDirect) asked a question.

Timer operation - BCD vs Decimal

Created Date: September 28,2017

Created By: Jeff Grogan

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

This is a basic question about how timers use BCD versus decimal values on a DL60. I'm sure it has been asked before but I haven't quite found the answer I'm looking for. I have a test case that tries to implement a 60 second timer. In my real application, I would take the number (60 decimal) via the HMI, multiply by 10 for .1 second timer, and store 600 in V2300. This timer times out at 25 seconds because it is comparing the count to 258 (600 in BCD). It seems that the timer treats the BCD version of the preset value as decimal in the comparison. I understand that the timer must have a BCD preset value. I'm just wondering how programmers deal with this. Screenshots attached. Thanks


  • adccommunitymod (AutomationDirect)

    Created Date: September 28,2017

    Created by: Jeff Grogan

    This is a basic question about how timers use BCD versus decimal values on a DL60. I'm sure it has been asked before but I haven't quite found the answer I'm looking for.

    I have a test case that tries to implement a 60 second timer. In my real application, I would take the number (60 decimal) via the HMI, multiply by 10 for .1 second timer, and store 600 in V2300.

    This timer times out at 25 seconds because it is comparing the count to 258 (600 in BCD). It seems that the timer treats the BCD version of the preset value as decimal in the comparison.

    I understand that the timer must have a BCD preset value. I'm just wondering how programmers deal with this.

    Screenshots attached.

    Thanks

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: September 29,2017

    Created by: Mike Nash

    The way I would do it depends...

    Set the HMI to BCD for that tag if you can.

    Or

    LD V2300

    BCD

    Out V2301

    and use V2301 for the timer preset.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: September 29,2017

    Created by: franji1

    Also, the DL PLCs have two different sets of mathematic instructions, one for BCD one for Binary/Decimal. ADD is the BCD addition. ADDB ins the Binary addition. You must decide up front how you will deal with numeric data in a DL PLC. Most HMI's support BCD format, so if you are dealing with Timers/Counters in DL, you typically just want to keep everything BCD. However, if you are sourcing your data from systems that do NOT have native BCD support, then you need to use the conversion instructions (e.g. BCD converts binary to BCD, BIN converts BCD to binary).

    Also, Data View supports different numeric formats, e.g. decimal and BCD/Hex (hexadecimal is actually a superset of BCD, allowing for the hex digits A-F, but 0x100 is BCD 100 at the bit level).

    LD and OUT instructions are type UN-aware. Hence, when you LD a constant, it does NOT know the type. Hence, it supports ONLY hexadecimal for entry (the superset of any 16 bit register). So you can enter LD K0 thru LD KFFFF. For BCD, this works well. You want to load 100 BCD, just do LD K100. However, if you want to load 100 decimal/binary, you have to convert 100 decimal to hexadecimal, which is 0x64. Hence to load 100 binary, you would do LD K64 (yes, sad, sad, sad).

    However, the IBoxes MATHBIN (Binary Math) and MATHBCD (BCD Math) translate everything for you automagically, and also lets you enter mathematical expressions like you would in BASIC or Excel.

    MATHBIN "V1400 + K100 " will do a BINARY ADD the contents of V1400 and add 100 decimal (MATHBIN DOES know that all constants are binary/decimal). Similarly, MATHBCD "V1400 + K100 " will do a BCD ADD of the contents of V1400 and add 100 BCD.

    There is also a MATHR IBox for doing double word, IEEE 32 point arithmetic. Real values occupy TWO V registers.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: September 29,2017

    Created by: Do-more PE

    One other alternative is that if your HMI supports scaling (full version C-more does), use it. 0 to 60 seconds would scale 0 to 600 milliseconds.

  • adccommunitymod (AutomationDirect)

    Created Date: September 29,2017

    Created by: Jeff Grogan

    Thank you forum! I really appreciate the help.