Automation for C-Bit number Copy to DS based on the number of the C-Bit Enabled...

So I'm adding some logic to my PLC. Currently, I have a Manual Keypad Entry on the C-More HMI that will write to DS100. This can be any number from 1-126 for operator input. But let's say I want to have specific values added with their own button... When it was only 3 possible values, I made a C-Bit that triggered code manually like so:

 

HMI Button triggers C1321, C1321 performs Copy 21 to DS100, reset C1321

HMI Button triggers C1342, C1342 performs Copy 42 to DS100, reset C1342

HMI Button triggers C1365, C1365 performs Copy 65 to DS100, reset C1365

 

And this works fine for 3, or even 5, but let's say I have 20 or more...

 

Is there a way to say for ANY C1301-1399, Copy 1-99 (based on which one I enabled) to DS100, Reset C1301-1399 (Resetting them all is fine) so I don't have to write the same code 99 times but change the numbers for each?

 

Edit: I appreciate the replies, but I just now realized I'm technically asking the wrong question... The end goal here is that Myself or Someone can add a button to the HMI that adds a given integer to a DS in one click (without a keypad entry) and I was trying to write code to do that the only way I know how. Since I already have code that takes DS100 and unpacks it to binary (1-127) for 7 outputs to an MP3 playback... Ah well. Unless there's a way to get C-More to set DS100 to an arbitrary number with a single button, I'll just go back to Plan B and handcode the few C-Bits I need and a subroutine to copy them over.


  • mikeexplorer (Customer)

    Have you looked at the recipe button on the Cmore? You can set a value with one button press.

     

    Selected as Best
  • Tinker (Customer)

    I think it will be easier to just write the code 99 times. The CLICK has limited indirect addressing capability so doing this in a loop would be hard.

    Possibly one could use a Shift Register, counting how far one shifted the "array' of C bits before finding one that was on. But I don't know that if that would be any easier than just writing 99 rungs, though it might be an interesting project just for the heck of it but still it might be to clever by half.

  • RedParadox (Customer)

    Yeah, I kinda thought that might be the answer... I guess maybe in the future we need a Fill Down for rungs or something... Thanks though!

  • LRJ (Customer)

    You could do it this way with a For-Next loop.

    LoadCbit_ForLoop

    • RedParadox (Customer)

      Considering I was already going to write this as a subroutine, that could work. My only question is, would it add significantly to the loop time compared to writing each line manually? Guess I might have to test... For now, I still have limited numbers that I NEED to write, it's not up to any project with 99 yet, more just thinking ahead to simplify if it gets there...

      • LRJ (Customer)

        The For-Next loop is going to increase your scan time, that's just how it is. More so than examining the equivalent number rungs of logic? I wouldn't think so. Obviously, it wouldn't have to be set to loop 99 times, just however many C-bits you are using.

         

        If you would rather avoid using a loop, you could do 31 C-bits at a time by packing them into a DD address and doing math.

        Cbits31_LogMathPack Copy 31 C-bits into a DD address. The Math performs a (modified) log base-2 and adds an offset, returning 1-31, based on the high bit position.

        I'm only packing 31 bits, and not 32, because the math doesn't return the desired result for the sign bit.

         

        Expand Post
      • RedParadox (Customer)

        Closer to what I want, and the example is very helpful, but I think in the end, I just isolate the actual numbers I need and write those lines by hand. (The honest truth is that I don't need EVERY number between 1-99, I only need SOME, but I was trying to make building the HMI something that could be done later by just dropping in a number and have them all ready to go...)

  • OkiePC (Customer)

    Trying to see the bigger picture of what you're doing, and there might be a much simpler method with indirect addressing. Are you trying to have the HMI operator make a numeric selection which results in a single value (or set of values) being written to specific memory locations like a recipe system?

     

    I would think you could just have the operator enter a value we'll call Index, and have the PLC add that to a base address and then Copy DS[base+Index] DS100. The base address might be 1000 or something to pick a block of one hundred DS registers that are not in use already, So then you just need to populate DS1001 through DS1100 with the right values.

     

    If this meets your need, then there's no need for loops or repetitive logic.

    Expand Post
    • RedParadox (Customer)

      See my edit. I already have a keypad input, I'm honestly just trying to make time saving "one click" buttons for certain numbers between 1-126(ish) that write to a DS. Currently I'm just writing manual code to do that from a C-Bit trigger, was hoping there's an automated way so I can just make the button and not need extra code for each one, but it's not too bad to do it 1 by 1. I really don't need all 126 to be "one click" anyway...

  • mikeexplorer (Customer)

    Have you looked at the recipe button on the Cmore? You can set a value with one button press.

     

    Selected as Best
    • RedParadox (Customer)

      See, THIS!!! THIS is why I came to the community, there's ALWAYS one "secret" bit of knowledge buried somewhere in the features that solves problems! THANK YOU! You just saved me quite a bit of time going forward, since I already had the code once the DS had a number. Now all I have to do is write that number to DS100 with Recipes! Woohoo!