News:

  • May 05, 2026, 09:19:15 AM

Login with username, password and session length

Author Topic: How do I.....  (Read 12095 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
How do I.....
« on: May 04, 2013, 12:09:48 AM »
I need to build the equivalent of a very large drum.  A thousand or more steps long and 32 or possibly 64 bits wide.  So at any given moment I may know that I want to set bit 17 in steps 549-601.  I'm assuming that I'm using a block of dwords, one or two dwords per step as my bit mask.  Is there a clever way to set a certain bit in N consecutive (or every other) DINTs?  Or go with a For loop?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: How do I.....
« Reply #1 on: May 04, 2013, 08:17:54 AM »
The way I would do it , although it may not be the most clever, would be to set up 1 or 2 separate programs with stages to do your bit manipulation. Feed it parameters, like start index, bit mask, interval, length and let it do the work.  It may be more code, but I think it would be easier in stages to do the parameter manipulation to get what  you want and make it more generic to satisfy all cases.

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: How do I.....
« Reply #2 on: May 04, 2013, 10:31:37 AM »
Place the following in a Task:

FOR
V1
From: V2
To: V3
By: V4

MATH
Result: BitMaskBlock[V1]
Expression: D0 (with whatever AND OR XOR expressions you need)

NEXT

Enter the Mask in D0, your first Index in V2, the increment in V4, and the end of the increment in V3. Now just activate the Task via yor favorite method.
« Last Edit: May 04, 2013, 10:33:57 AM by plcnut »
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: How do I.....
« Reply #3 on: May 05, 2013, 11:28:15 AM »
Thanks to you both!

Given that there's nothing cleaner than a for loop, I think I'll go the opposite direction.   The basic app is that there are workpieces of varying lengths entering a conveyor.  Each piece will be processed at various stations as the conveyor passes them, which stations for a given part determined by a recipe.

When a workpiece comes in, the recipe comes with it, so I know that stations 1-12, 15, 19, etc., are used for this part.  I also know that Station 1 is X encoder counts from the entry point, and my current encoder count is Y, so Station 1 should activate at Y + X counts, so this means bit 1 in the drum should be set for some number of drum steps (encoder counts) beginning at Y + X (possibly +/- station-dependent constant Z if the station in question needs to lead or lag the leading edge of the part).

But...I don't yet know how long the part is till my photo at the entrance point tells me it sees the end of the workpiece.  So if there were some way of setting bit 1 for N steps beginning at Y + X + Z all in one instruction, I'd wait till I saw the end of the part and do it all in one shot, but if I'm limited to a for loop anyway, I think it will be cleaner to just go with the flow and set one bit at a time every time I receive an encoder count till I see the end of the part.  Same number of iterations and less logic.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: How do I.....
« Reply #4 on: May 06, 2013, 08:22:06 AM »
I misunderstood your original post. I thought you were looking for an easier way to get all the bit data stored into the PLC. But if you are inputting Recipes then that part is solved.
If you are asking how I would go about setting up my own super drum, I would probably use a WHILE WEND nested inside a FOR NEXT loop.
The FOR/NEXT would be the drum step, And the condition for the WHILE/WEND could be indexed as well with a user defined Bit Block. The condition for each step of the drum could even be saved in separate stages pointed to by the FOR Index via the JMPI instruction in a separate Program block.
The DWord user Block will contain the 'recipe' bit mask.
Clear as mud?  :D
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: How do I.....
« Reply #5 on: May 06, 2013, 10:25:27 AM »
Thanks, plcnut!  :)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.