Codesys 3 shift register help

Highwayrat

Member
Join Date
May 2019
Location
Uk
Posts
3
Hi

I am fairly new to codesys 3 but I'm currently trying to make a little project using 4 cameras, a sensor and a conveyor belt each camera take a pictures and gives a result 1 (pass) or 0 (fail) when a operation has been performed and the sensor triggers the first camera and also I'm trying to use this as the trigger to move the registers , I am trying to use The shift register function to store the result and move down the shift register until it gets to 5th station which will decide if its good or bad depending on the 1 or 0. I have the rest of the ios working but can't get my head around the shift register. Does anyone know how to change a boolean input in to a word and move it down the shift register and also how to extract the last bit of the shift register to get the result

Also I'm using structured text

Cheers

Highwayrat
 
Last edited:
If you only need to store 5 positions, then you could consider using five boolean vars:


Pos1, Pos2, Pos3, Pos4 and Pos5.


To shift


Pos5:=Pos4;
Pos4:=Pos3;
Pos3:=Pos2;
Pos2:=Pos1;
Pos1:=NewValue
 
I never bother with bit shift instructions unless you need to go more than 32 bits.
Use bit level addressing on a word or udint or whatever number of bits you need.

Set bit 0 when the data goes in.
Unset the highest bit at the same time (to prevent overflow).
Multiply by 2.
 
Help with SHL

Thank you everybody for your help :)
i have decided to go down the SHL Route but am having some problems

i have the results from the camera input %IX2.0 coming in as high or low on the Digital inputs, 1 for pass 0 for fail

when when i try to put the result in a shift reg it goes down the reg fine, but it wouldn't stay as a the moment i try to move the reg without a 1 on %IX2.0 input the reg resets to 00000000

i am using a external input to trigger and 1 input for camera result

and i require the first bit to move up untill it gets to 7 postion and then trigger a output depending if it a 1 or 0

my code is
**************MAIN PROGRAM ******************
PROGRAM PLC_PRG
VAR

Test_byte : BYTE ;
Ton_0 :TON;
Testoutputs :ShiftReg;
v1: BYTE :=0;
v2: BYTE :=0;
END_VAR

Program

Ton_0(IN:= NOT .GVL.Timer , PT:=T#1S);
IF Ton_0.q AND ExternalTrigger THEN
Testoutputs.SR_bit0 :=%IX2.0;
v1.1 :=Testoutputs.SR_bit0 ;

v2.0:=v1.7;
v1 :=SHL(v1, N);
v1.0 :=V2.0;
N :=N+1;
IF N>7 THEN
N:=0;

END_IF
IF V1.7 =TRUE THEN
Fail:=TRUE;
ELSE
Fail:=FALSE;
END_IF
gvl.Timer :=TRUE;
ELSIF NOT ExternalTrigger THEN

.GVL.Timer :=FALSE;

END_IF


i have also done a structure file for the bit

TYPE ShiftReg:
STRUCT
SR_bit0 : BIT;
SR_bit1 : BIT;
SR_bit2 : BIT;
SR_bit3 : BIT;
SR_bit4 : BIT;
SR_bit5 : BIT;
SR_bit6 : BIT;
SR_bit7 : BIT;
END_STRUCT
END_TYPE


if anyone has any advice i would be very grateful as its confusing me

cheers
 

Similar Topics

I was wondering if there are any other codesys users on here that have designed conveyor systems (reject stations, sorting, etc) which utilize a...
Replies
0
Views
1,840
Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
6
Views
263
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
86
Hello, I am new to Codesys, and am trying to learn about it for a project we're developing. I've got a couple questions, but first a little...
Replies
1
Views
133
Hi everyone, as this is my first experience with Rockwell Software i would like to know what's the best way to make Enumerations?
Replies
10
Views
486
Back
Top Bottom