Beginner having troubles with TwinCAT 3 basics

Lamaman

Member
Join Date
May 2021
Location
Estonia
Posts
1
Hello!
I'm a complete beginner to programming and i have a project i'm working on in TwinCAT 3 since i'm using a Beckhoff PLC.

One of the problems i have, is this:
Variable1 :=TRUE; //test
IF Variable1= TRUE
THEN Variable2 := TRUE;
Variable3:= TRUE;
ELSE Variable2:= FALSE;
Variable3:= FALSE;
END_IF

I have defined all the variables. If i start the program , then only variable2 reacts to change in variable1. Variable3 stays false.
I have tried adding an AND before Variable3, but that makes no change.

I'm new to this forum and i hope what i'm explaining makes sense.
I have managed to solve some problems myself but can't wrap my head around this one. Seems to be a simple logic task but it wont work.

Anyway, can anyone tell where seems to be the problem?
 
Hello!
I'm a complete beginner to programming and i have a project i'm working on in TwinCAT 3 since i'm using a Beckhoff PLC.

One of the problems i have, is this:


I have defined all the variables. If i start the program , then only variable2 reacts to change in variable1. Variable3 stays false.
I have tried adding an AND before Variable3, but that makes no change.

I'm new to this forum and i hope what i'm explaining makes sense.
I have managed to solve some problems myself but can't wrap my head around this one. Seems to be a simple logic task but it wont work.

Anyway, can anyone tell where seems to be the problem?


The statements are executed in order, first if to elsif.........else. A true condition causes the program to executed the code for this specific condition then *breaks" out and continues at the end_if.


Edit: use a breakpoint and step into the code to see order of execution, while changing the value of different tags.
 
Last edited:
What happened the topic started a few weeks ago for YouTube TwinCat tutorials. Can't seem to find it and it was quite good. Look for alltwincat on Google and YouTube.
 
Your original code should work. If Variable3 isn't turning on, make sure it isn't being overwritten somewhere else. Just to clean it up a bit:
Code:
Variable1 := TRUE; //test

IF Variable1 THEN
   Variable2 := TRUE;
   Variable3 := TRUE;
ELSE
   Variable2 := FALSE;
   Variable3 := FALSE;
END_IF
It isn't necessary to say 'IF Variable1=TRUE'... since it's a boolean variable it will evaluate to true or false without the equal sign.

You could get the same functionality with this:
Code:
IF Variable1 THEN
   Variable2 := Variable3 := TRUE;
ELSE
   Variable2 := Variable3 := FALSE;
END_IF
or this:
Code:
Variable2 := Variable3 := Variable1;
 
I still can't find the topic! But here's link to his youtube
This guy is also very good and is now doing some motion control tutorials. He has basic stuff in his channel, just browser for it.
 

Similar Topics

Hi all, Writng a FB in ST on Beckhoff TC for a pulser which turns on and off on a cycle, is paused by turning bControlInput to FALSE, but resumes...
Replies
6
Views
248
So to start off: I have no experience with PLC's, but I'm good at figuring stuff out, but I need some help to know if my PLC is just dead in the...
Replies
2
Views
114
Dear all, First of all thanks for letting me join this forum. I just need some help in one of my programming exercises. Being a beginner...
Replies
6
Views
608
I am trying to connect to SLC5/03 using an FTDI usb to rs232 with female to female converter at 1 end... however I can not connect to it ... the...
Replies
8
Views
1,269
First time poster here so long story short i built my own trainer at work so i could toy around with various things and test things and learn...
Replies
25
Views
2,146
Back
Top Bottom