Kevin91172 (Customer) asked a question.

Loading presets in a counter using a selector switch

I got something that could be done, but don't know what function to use. Instead of using multiple counters with their preset and the selector enables the part one,2, 3, counter. I want to use the selector switch to load the preset using only one counter. Any suggestions? Trying to learn more data manipulation/funtions


  • PouchesInc (Customer)

    You can enter a variable tag nearly everywhere in Productivity that you want to instead of a constant, so your preset can simply be "CounterPreset". Then you can have some rungs that have a rising edge contact for the input you want to use, and the output of that rung would be a Copy Data instruction that has a source of whatever number you want and a destination of CounterPreset. That way when the rung goes true from the switch being flipped it will set the counter's preset to a new number.

     

    You can also do something like use normally open contacts instead of rising edge, and you can have rungs that combine switches to load a different value. Make sure the combo switches are under the single switch rungs otherwise the single switch will take priority.

     

    You could also use an HMI and a data entry field tied to the tag CounterPreset, and when you press the object on the screen and enter a number it will make your counter be that number, no physical switch inputs required.

     

     

    Expand Post
    • PouchesInc (Customer)

      You can also do things a different way if you desire. A counter doesn't have to be single-use and you don't have to care what the preset is or the done bit or any of it if you don't want to. It is just a piece of data that is counting. You can leave it to count as long as you want and base your output on various setpoints if you desire to. While this is a less common way of doing things, it is entirely valid. You are allowed to do things however you want and in whatever way you think is efficient for your code.

       

      example2 

       

      Or something like this next image for all your inputs and based on their configuration you can change the counter anywhere from 0-140 in multiples of 5

       

      example3 

      You can of course change the inputs for each switch in that instruction to be anything you want, but those numbers keep adding all the way up nicely.

      Expand Post
      • Kevin91172 (Customer)

        Ok that works great thanks, but I need to figure out how the last rung with the NC's

        enables the copy. We have a 3 position switch but only using 2 input wires, so the existing project enables the counter with 2 nc's for the one part count with no discreet input

      • PouchesInc (Customer)

        Ah, ok. If it is just a 3 position selector switch then you would have your two inputs, and make 3 rungs for it in software.

        Rung 1 is input 1, loads a value.

        Rung 2 is input 2 and loads a different value.

        Rung 3 would most likely be both inputs are off if that is how your switch works, or both inputs one if your switch works that way, and that rung loads yet another value for its output.

        Expand Post
      • Kevin91172 (Customer)

        I got it, I was over thinking and been a long day. Thanks!

  • HOST_franji1 (HOST Engineering)

    I was thinking along the lines of a Recipe index. Use a static Array indexed by the Selector value where the array contents are the various preset values, then when the "recipe" is selected, copy the SelectorPreset[Selector] value into the Preset. Data driven, not code driven. Of course, you have to ensure that the SelectorPreset array is initialized properly for each Selector value.

    • Todd Dice (Customer)

      Here's an image based on Franji's idea. I'll note Productivity does not have a zero data point, so I have a math instruction adding a 1 to the pack bits output to make the minimum pointer value 1. In the data view, when you're online to the PLC is where you place the values for each recipe.

      Screenshot 2023-02-16 145158

      Expand Post
      • PouchesInc (Customer)

        "In the data view, when you're online to the PLC is where you place the values for each recipe."

         

        As an alternative, you could also use a rung with something like a first scan bit and copy data to all the array locations with constants or other retentive tag values. Simply editing them in via Data View is easier, especially at first, but once you know your values and you want them to be saved as that and not risk losing them should your battery die then you could place them as hard-coded data in the program

        ArrayLoad

        Expand Post