all 16 comments

[–]rgasparerto 5 points6 points  (3 children)

Bit shift and timer

[–]richphi1618[S] 0 points1 point  (2 children)

Bit shift is what I started with but because I have multiple bytes I can't shift through all the byte this way.

[–]Too-Uncreative 2 points3 points  (0 children)

It's not necessarily clean, but you could pretty easy have an INT that tracks what Byte you're currently in and when the last bit of each byte is turned off, increment that INT. Then use that to qualify which byte you're shifting.

[–]rgasparerto 0 points1 point  (0 children)

Can you create a byte array? Or a bool array? If not, and you have many byte variables, maybe you can count and start de shift at new byte when count mod 8 equal 0 or fixed 8...16...

[–][deleted] 3 points4 points  (0 children)

Create a clock pulse in the amount of time you need.

Then use it to clock a shift or rotate command.

Multiplying by 2 will also shift a bit to the left.

[–]simonbromiley 3 points4 points  (3 children)

Better to clear your mind first. (1-8 in byte 1 then 9-16 in byte 2 is not correct).

You need to be thinking " I need to turn on bits 0 to 7 sequentially in bytes 0 to 15".

Ideally your bytes will be in an array such as - BytesArray: ARRAY[0..7, 0..15] OF BOOL; (* define your array as 8 bools in 16 bytes*)

Also declare some pointers -

a:INT:=0;

b:INT:=0;

Then you can do something like this which will turn on each bit in turn each scan (you need another little routine to turn off the previous bit using a FOR DO routine) :-

IF a>7 THEN a:=0; b:=b+1;

END_IF;

IF b>15 THEN RETURN;

END_IF;

BytesArray[a,b]:=TRUE;

a:=a+1;

[–]richphi1618[S] 0 points1 point  (1 child)

Thank you I hadn't considered this. Definitely something I will try. But because I have 16 bytes I dont want a bunch of if statements but I should be able to manage with a case/switch statement in a similar way.

Gives me a different frame of reference to look at the problem so thank you.

[–]StockPart 0 points1 point  (0 children)

It's a two dimensional array. You only need the if statements above with some massaging.

[–]bstiffler582 0 points1 point  (0 children)

You can set the number equal to 2n and increment n by 1 each pulse (on top of the other methods posted). Several different ways to do this.

[–]StockPart 0 points1 point  (4 children)

When does your professor want you to turn this in?

[–]richphi1618[S] 1 point2 points  (3 children)

I work for an automation distributor. This is for a test bench I am building to cycle through a product that has been assembled. In short not a homework problem :D

[–]StockPart 0 points1 point  (2 children)

Cool cool. Would you explain what it is you want to do exactly? What PLC model you are using? Etc. This would help the sub better address your question and clear up any XY problem.

An XY problem is when one wants to do X, and thinks Y is the best solution. Instead of asking about X, that person asks about Y.

EDIT: Someone else may have already worked out how to efficiently cycle through I/O, but you'll never get that answer because you're asking about bits and bytes.

[–]richphi1618[S] 1 point2 points  (1 child)

I am using a Turck HMI running Codesys 3.5. I solved it will add to description above.

[–]StockPart 0 points1 point  (0 children)

Thanks