markdevlin2015
Hi,
 
I'm trying to implement a simple SHL function block in ladder logic, I can't seem to get it to work and have tried most of the input types but im getting a wrong data type error.
 
Any help is appreciated.
 
Markthumbnail_IMG_8309.jpg
Reply 1 0
thiagoralves
What exactly do you want to do with a SHL block? It doesn't look like you know what this block is for...
Reply 0 0
markdevlin2015
I want to shift data left or right, I’m just looking for a simple explanation as I’ve not had much luck with it
Reply 0 0
thiagoralves
In that case, yes, the SHL block will shift data left, but that does not make any sense while using BOOL variables and contacts like you did. You must add a WORD (or WORD variations like DWORD) value as input and then provide how many bits you want it shifted left at the N input. The shifted WORD will be outputted at the OUT pin, for which you must place a variable to receive it.
Reply 0 0
markdevlin2015
Would you be able to give me a small example, it would be appreciated, I’ll also have a try with what you have explained
 
thanks
Reply 0 0
markdevlin2015
Can the data be provided from a digital input pin for example when a part is detected by a sensor, so that I can use a shift register to track the part
Reply 0 0
thiagoralves
As I said, it makes no sense to shift a BOOL, because a BOOL can only hold ONE bit. You will have to convert your BOOL variable to a WORD or some other data type that can be shifted.
Reply 0 0
RaynoP
@markdevlin2015 - I agree with Thiago, what exactly are you trying to accomplish? Some context is required in almost all cases, to explain to someone how something works.
I have written a small demo/example program for you, but it is your responsibility to program it, examine it and then to debug it.
 
In short, the program has a word and by default, it loads the value of 1 into the word, "wHoldingWord". You cannot move a bit in a word/register if it is filled with zeros -as what are you trying to move?
Then on the rising edge of a boolean value produced by the Flasher example of Thiago on YouTube, the loaded 1 (or bit) is shifted by the number of bits defined by "nNumberOfPlaces", to the left of the word.
The program then evaluates the the "wHoldingWord" to see when it reaches zero. If it does, it writes a "1" back into the word to keep the word moving a bit. Because you cannot move zeros :-)
 
[203128%2F8117385%2Fmceclip0]
 
Hope it helps, if not, share and we will try to assist.
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 0 0
markdevlin2015
Hi,
 
Thanks for all your help, I eventually worked it out and made my own POU shift register using Structured Text. Shown below is a snip from my program. I'm using a shift register to sort multiple parts on a production line. The Shift register remembers where the parts are. The size of the parts is also being processed using a shift register.
 
Screenshot 2023-03-19 154809.png
 
                                                            16 bit Shift Register.
 
The idea with the shift register is that a data bit either a logic 1 or 0 sampled at an input can be shifted left or right into a register on every clock pulse provided.
 
Thanks
M
Reply 0 0
RaynoP
Hi there,
 
@markdevlin2015, ah, ok, your solution required a little more than just shifting in a singular direction.
 
Well done on your solution!
 
Suggestion: you could also look at an array and move the bits forwards or backwards using a "for loop by 1 do" or "by -1 do" :-).
 
I once programmed an bottle sorter for a customer. The line scanned each bottle as it passed an laser scanner at high speed, and used a light beam to count the bottles. Then if a bottle was "rejected", a pneumatic arm pushed the bottle off the line for recycling. An array worked a lot better then as all the code inside a for loop gets scanned each PLC cycle opposed to some other methods.
 
I only joined the project recently and am busy testing the IDE. I have had a multitude of app crashes and it slows my progress and is very frustrating to begin again if code is lost.
 
Have fun and shout if you need help. I have been in the industry for a very long time and am always willing to assist!
 
PS: why a POU and not a function block?
Typically the three are used as follows:
  • A Program Organisation Unit (POU) is what the name says, it controls a part of your program flow calling functions and or function blocks or run your code straight up, or in some cases to group plant and or machine functions. Also for use at different scan cycle times to scan one part faster/slower as other parts of the code
  • A Function Block (FB) is used to replicate code you use over and over. Typically like a timer or code to control an electrical motor etc. etc.
  • A Function (FC) is used to compute one thing, hence it returns a single value, unlike the FB which can return many variables
 
RaynoP
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 0 0
markdevlin2015
Hi RaynoP,
 
Thanks again, that would be great, I'm currently designing a small PLC that will work with OpenPLC almost there with a few hardware issues to resolve. 
 
PLC.jpg
 
Regards
Mark
Reply 1 0
RaynoP
I am also busy doing the same - well, almost. I am using Regged-circuits and actual PLCs I reversed engineered as "seed ideas" (before TI brought out a variety of PLC design notes) as I have made about 4 - 7 proof of concept designs. With some success - success being the ones I had money to get built by JLPCB.
 
Your board looks like a very nice board! You like me, prefer TH-tech instead of SMT/SMDs. But I took the plunge and learned how to hand solder a fairly large variety as I don't have a heat bed/re-flow oven of sorts.
 
But let's not cross-thread too much :-). Open a thread if you willing to share and the forum can assist. Else PM me. But still, looking good.
 
Regards,
RaynoP
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 0 0
RaynoP
Running lights example in ST if you wanted. Apologies if I am cross-threading too much now.
[203128%2F8118601%2Fmceclip0]
fbFlash(
     bEnable:=true,
     tDelayTime:=T#500ms);
case nSeq of
  0:
    qOut1 := false;
    qOut2 := false;
    qOut3 := false;
    qOut4 := false;
    qOut5 := false;
    qOut6 := false;
    qOut7 := false;
    qOut8 := false;
    if bEnable then
      nSeq := 10;
    end_if;
  10:
    qOut8 := false;
    qOut1 := true;
    if fbFlash.bQ then
      nSeq := 20;
    end_if;
  
  20:
    if not fbFlash.bQ then
      nSeq := 30;
    end_if;
    
  30:
    qOut1 := false;
    qOut2 := true;
    if fbFlash.bQ then
      nSeq := 40;
    end_if;
  
  40:
    if not fbFlash.bQ then
      nSeq := 50;
    end_if;
      
  50:
    qOut2 := false;
    qOut3 := true;
    if fbFlash.bQ then
      nSeq := 60;
    end_if;
  
  60:
    if not fbFlash.bQ then
      nSeq := 70;
    end_if;
  70:
    qOut3 := false;
    qOut4 := true;
    if fbFlash.bQ then
      nSeq := 80;
    end_if;
  
  80:
    if not fbFlash.bQ then
      nSeq := 90;
    end_if;
  90:
    qOut4 := false;
    qOut5 := true;
    if fbFlash.bQ then
      nSeq := 100;
    end_if;
  
  100:
    if not fbFlash.bQ then
      nSeq := 110;
    end_if;
    
  110:
    qOut5 := false;
    qOut6 := true;
    if fbFlash.bQ then
      nSeq := 120;
    end_if;
  
  120:
    if not fbFlash.bQ then
      nSeq := 130;
    end_if;
  130:
    qOut6 := false;
    qOut7 := true;
    if fbFlash.bQ then
      nSeq := 140;
    end_if;
  
  140:
    if not fbFlash.bQ then
      nSeq := 150;
    end_if;
  150:
    qOut7 := false;
    qOut8 := true;
    if fbFlash.bQ then
      nSeq := 160;
    end_if;
  
  160:
    if not fbFlash.bQ then
      if not bEnable then
        nSeq := 0;
      else
        nSeq := 10;
      end_if;
    end_if;
end_case;
Kind regards,
RaynoP
------------------------------------------------------------
If you forever think inside the box...
You will never live outside of it.
 
Red pill or blue pill Neo? All I offer is the truth.
Follow the white rabbit.
Reply 0 0
markdevlin2015
Hi,
 
Yeah, I made this board with the help of JLJPCB, there are still a few hardware issues to resolve, but when that’s all sorted, I’ll get surface mount version made to bring the board size down and made add another couple of analogue I/O channels. This board works well for digital and analogue I/O, and have NPN, and PNP output driver side.

Regards
Mark
Reply 0 0
ist
How can I use SHL to shift between 2 bits? I want to keep track of two different objects passing through a location. I want to keep track of them like a FIFO queue.
Reply 0 0
Reply