Hi there! I have a strange question: can I use timer with variable time (not fixed - 1s, for example with "t" seconds, where I can write any value on "t")?
Hi. Sorry for the late response. Sure, you can, and it is not a strange question! You need to declare a variable of type Time. then write values to it within your program (or in the visualization) and use that variable as the preset time of the timer.
Hi Tohid, I am trying to implement a delay of for example 5seconds. What I tried is make a TON and then an if loop so it looks like this: my_ton : TON; my_ton(IN:= TRUE, PT := T#5s) label1: counter1 := counter1+1; IF NOT(my_ton.Q) THEN (*As long as Q is low, go back untill Q is high (so after 5 JMP label1; seconds) *) END_IF But for some reason it doesn't recognise the label. Do you know how to solve this. I also tried doing this with a while loop but that makes my PLC crash. Thanks in advance! Bart
Hi Brat, I think you can do this in a much easier way, like this: my_CTU: CTU; my_Ton: TON: my_Ton(IN:= not my_Ton.Q, PT:= T#5s); // You will have pulses of 5 seconds width, because output of the timer is used as its input. my_CTU(CU:= my_Ton.Q, PRESET:= reset, PV:=5); Try this and let me know if it works! Regards, Tohid
Hi Tohid, thanks for your fast answer. I tried this code and if I understand it correctly, this code increments the CU every 5 seconds? What I actually wanted is a delay like the function "Sleep(ms)" in C. So imagine this is the code 1. 2.Some code 3. Wait(5 seconds) (*I want the code here to wait 5 seconds and do 4. absolutely nothing *) 5. 6.Some Other Code 7.Some Other Code 8.Some Other Code 9. 10. So I want the code to do nothing at point 3 and wait for 5 seconds before executing the code at line 4. When I run your code the my_ton.Q value stas FALSE for the entire time. Thanks a lot! Kind regards, Bart
I see. I guess you have tried this one? my_ton(IN:= TRUE, PT := T#5s); while (not my_ton.Q) DO tempVar:=true; end_while What is the error that you receive when you run the code with the IF statement? I see that you do not have a ";" at the end of the line calling the timer. Is that the reason?
Yes I tried it with the while loop but then my PLC crashes. The ";" I wrote in my code but I just forgot it to write here on youtube. I mailed to the company and they told me the JMP instruction doesn't work with the software I'm working with so that is my error. Thanks for your help anyways!
Hi there i am new to codesys i am trying to run an output say a motor for a set time but i cannot find the right funtion block/timer for this can you help me out
@@TohidAlizadehthank you very much for your help! the problem is that my trigger signal (input) stays true, I would like to stop the timer with another Trigger
Thanks for your comment. I thiunk I wanted the Start to be False at the beginning, so the motor does not start before we take an action. Though, since we have the visualization here, the value of the start will be taken from the visualization element here, so the initial value provided will not be important.
Hi, can you make a video on "Encoder programing and simulation with Codesys Structure Text? " I searched a lot, but couldn't find it. It will be much helpful...
Hi there! I have a strange question: can I use timer with variable time (not fixed - 1s, for example with "t" seconds, where I can write any value on "t")?
Hi. Sorry for the late response. Sure, you can, and it is not a strange question! You need to declare a variable of type Time. then write values to it within your program (or in the visualization) and use that variable as the preset time of the timer.
@@TohidAlizadeh OK, Thanks a lot!
is it possible to connect CODESYS with any PLC software???????? for example, Im using WECON PLC EDITOR
I am not sure about this. In general, if the PLC supports CODESYS, CODESYS will be its main software, I believe.
Hi Tohid, I am trying to implement a delay of for example 5seconds. What I tried is make a TON and then an if loop so it looks like this:
my_ton : TON;
my_ton(IN:= TRUE, PT := T#5s)
label1: counter1 := counter1+1;
IF NOT(my_ton.Q) THEN (*As long as Q is low, go back untill Q is high (so after 5
JMP label1; seconds) *)
END_IF
But for some reason it doesn't recognise the label. Do you know how to solve this. I also tried doing this with a while loop but that makes my PLC crash.
Thanks in advance!
Bart
Hi Brat,
I think you can do this in a much easier way, like this:
my_CTU: CTU;
my_Ton: TON:
my_Ton(IN:= not my_Ton.Q, PT:= T#5s); // You will have pulses of 5 seconds width, because output of the timer is used as its input.
my_CTU(CU:= my_Ton.Q, PRESET:= reset, PV:=5);
Try this and let me know if it works!
Regards,
Tohid
Hi Tohid,
thanks for your fast answer. I tried this code and if I understand it correctly, this code increments the CU every 5 seconds?
What I actually wanted is a delay like the function "Sleep(ms)" in C.
So imagine this is the code
1.
2.Some code
3. Wait(5 seconds) (*I want the code here to wait 5 seconds and do
4. absolutely nothing *)
5.
6.Some Other Code
7.Some Other Code
8.Some Other Code
9.
10.
So I want the code to do nothing at point 3 and wait for 5 seconds before executing the code at line 4.
When I run your code the my_ton.Q value stas FALSE for the entire time.
Thanks a lot!
Kind regards,
Bart
I see. I guess you have tried this one?
my_ton(IN:= TRUE, PT := T#5s);
while (not my_ton.Q) DO
tempVar:=true;
end_while
What is the error that you receive when you run the code with the IF statement? I see that you do not have a ";" at the end of the line calling the timer. Is that the reason?
Yes I tried it with the while loop but then my PLC crashes. The ";" I wrote in my code but I just forgot it to write here on youtube. I mailed to the company and they told me the JMP instruction doesn't work with the software I'm working with so that is my error.
Thanks for your help anyways!
Nice to hear that you have managed to solve the problem. Please let us know the solution, if you do not mind. What did you use at the end?
Hi there i am new to codesys i am trying to run an output say a motor for a set time but i cannot find the right funtion block/timer for this can you help me out
+preetparmar I think you can do this using a Pulse Timer (TP) easily.
thanks i couldn't find it before but i found it now your video are just brilliant
Hello,
is there any way to stop the turn on delay?
For example using a stop button means stop counting the time-> motor won't turn on
If the input to the timer becomes False, it will stop automatically, unless it is a retentive one.
@@TohidAlizadehthank you very much for your help! the problem is that my trigger signal (input) stays true, I would like to stop the timer with another Trigger
@@Flofet You may have that second one in series with the original one. So whenever one of them becomes False, the timer stops.
why 'START:BOOL:=FALSE'
Thanks for your comment. I thiunk I wanted the Start to be False at the beginning, so the motor does not start before we take an action. Though, since we have the visualization here, the value of the start will be taken from the visualization element here, so the initial value provided will not be important.
@@TohidAlizadeh thank you so much
Rica ederim!
Hi, can you make a video on "Encoder programing and simulation with Codesys Structure Text? " I searched a lot, but couldn't find it. It will be much helpful...
Hi, thanks for your comment and suggestion. I will work on this, even though I am replying after 3 years 😉
Post a video using jump command program and also traffic signal program
I think I already have videos covering these topics!