songyanghua
Hello, when I referenced the official document ADDING NEW BLOCKS TO OPENPLC EDITOR'S LIBRARY to create a custom block, I found an error during compilation and found that TEST was not found. After checking, I followed the requirements of each step to set it. On the Win11 system, I hope you can help me. I haven't found the reason for several days!
0e3299f2fb9758a349c83a334cb4c0dd.png17c9f4a5a9e78bda26026cd8e97fa14d.png49e31f5864b567d4db9f47ca35ae5488.png

Delete that module to pass

Reply 0 0
songyanghua
1. There is no corresponding module in this that can be used to create blocks. How to achieve a fixed time length for outputting high levels?
2.Can the minimum pulse width time range and step size, with a default value of 150ms, be set?微信截图_20231013210348.png
Reply 0 0
thiagoralves
You have 5 programming languages at your disposal. You can code anything you want with them, including this particular timer block you're talking about. I suggest you learn more about IEC 61131-3 programming if you want to move further with PLC programming.
Reply 0 0
songyanghua
You have 5 programming languages at your disposal. You can code anything you want with them, including this particular timer block you're talking about. I suggest you learn more about IEC 61131-3 programming if you want to move further with PLC programming.
May I ask what is the initial value set for this timer, ms?
Reply 0 0
songyanghua
松洋花 wrote:
请问这个计时器的初始值是多少,女士?
Is there a step size value and a minimum pulse width time range set?
Reply 0 0
thiagoralves
I got some free time and wrote you an example. I don't know if I understood exactly your timer logic, but this one activates whenever IN1 or IN2 is true, and remains active for the time period defined inside the block. I set the time period to 5 seconds to make it easier to visualize the signals on the debugger. You can define this to be whatever you want, 150ms, 10ms, anything. Accuracy is only dependent on the task cycle scan time (defined on your resource Res0) and your hardware that is running the runtime.
 
Screenshot 2023-10-13 at 10.27.13 AM.png
Screenshot 2023-10-13 at 10.29.33 AM.png
 
As you can see from the pictures, the timer output will remain active for 5 seconds after the timer is started with a positive pulse at IN1. While the timer is running, pulses at IN1 have no effect. Also, if you hold IN1 true for a long period, the timer will still generate the 5 seconds output pulse, and will only start a new pulse after IN1 has become false and true again. Here is the full source code in Structured Text for this block:
 
(* Declare timers *)
TOF1(IN := timer_1_input, PT := T#5s);
TOF2(IN := timer_2_input, PT := T#5s);

(* Logic to activate timer 1 *)
if IN1 = TRUE and started_timer_1 = FALSE then
    (* Rising edge on IN1 - starting timer *)
    started_timer_1 := TRUE;
    timer_1_input := TRUE;

elsif started_timer_1 = TRUE and TOF1.Q = TRUE then
    (* Timer has started and is running, lets make sure TOF1 input remains false *)
    timer_1_input := FALSE;
    
    
elsif started_timer_1 = TRUE and TOF1.Q = FALSE and IN1 = FALSE then
    (* Timer has expired, IN1 is false, lets reset *)
    started_timer_1 := FALSE;
    timer_1_input := FALSE;
end_if;

(* Logic to activate timer 2 *)
if IN2 = TRUE and started_timer_2 = FALSE then
    (* Rising edge on IN2 - starting timer *)
    started_timer_2 := TRUE;
    timer_2_input := TRUE;

elsif started_timer_2 = TRUE and TOF2.Q = TRUE then
    (* Timer has started and is running, lets make sure TOF2 input remains false *)
    timer_2_input := FALSE;
    
    
elsif started_timer_2 = TRUE and TOF2.Q = FALSE and IN2 = FALSE then
    (* Timer has expired, IN2 is false, lets reset *)
    started_timer_2 := FALSE;
    timer_2_input := FALSE;
end_if;

(* Set outputs *)
OUT1 := TOF1.Q;
OUT2 := TOF2.Q;
 
Attached is the full program for your reference.
Reply 0 0
songyanghua
I got some free time and wrote you an example. I don't know if I understood exactly your timer logic, but this one activates whenever IN1 or IN2 is true, and remains active for the time period defined inside the block. I set the time period to 5 seconds to make it easier to visualize the signals on the debugger. You can define this to be whatever you want, 150ms, 10ms, anything. Accuracy is only dependent on the task cycle scan time (defined on your resource Res0) and your hardware that is running the runtime.
 
Screenshot 2023-10-13 at 10.27.13 AM.png
Screenshot 2023-10-13 at 10.29.33 AM.png
 
As you can see from the pictures, the timer output will remain active for 5 seconds after the timer is started with a positive pulse at IN1. While the timer is running, pulses at IN1 have no effect. Also, if you hold IN1 true for a long period, the timer will still generate the 5 seconds output pulse, and will only start a new pulse after IN1 has become false and true again. Here is the full source code in Structured Text for this block:
 
  1. (* Declare timers *)
  2. TOF1(IN := timer_1_input, PT := T#5s);
  3. TOF2(IN := timer_2_input, PT := T#5s);
  4.  
  5. (* Logic to activate timer 1 *)
  6. if IN1 = TRUE and started_timer_1 = FALSE then
  7.     (* Rising edge on IN1 - starting timer *)
  8.     started_timer_1 := TRUE;
  9.     timer_1_input := TRUE;
  10.  
  11. elsif started_timer_1 = TRUE and TOF1.Q = TRUE then
  12.     (* Timer has started and is running, lets make sure TOF1 input remains false *)
  13.     timer_1_input := FALSE;
  14.     
  15.     
  16. elsif started_timer_1 = TRUE and TOF1.Q = FALSE and IN1 = FALSE then
  17.     (* Timer has expired, IN1 is false, lets reset *)
  18.     started_timer_1 := FALSE;
  19.     timer_1_input := FALSE;
  20. end_if;
  21.  
  22. (* Logic to activate timer 2 *)
  23. if IN2 = TRUE and started_timer_2 = FALSE then
  24.     (* Rising edge on IN2 - starting timer *)
  25.     started_timer_2 := TRUE;
  26.     timer_2_input := TRUE;
  27.  
  28. elsif started_timer_2 = TRUE and TOF2.Q = TRUE then
  29.     (* Timer has started and is running, lets make sure TOF2 input remains false *)
  30.     timer_2_input := FALSE;
  31.     
  32.     
  33. elsif started_timer_2 = TRUE and TOF2.Q = FALSE and IN2 = FALSE then
  34.     (* Timer has expired, IN2 is false, lets reset *)
  35.     started_timer_2 := FALSE;
  36.     timer_2_input := FALSE;
  37. end_if;
  38.  
  39. (* Set outputs *)
  40. OUT1 := TOF1.Q;
  41. OUT2 := TOF2.Q;
 
 
Attached is the full program for your reference.
 
I got some free time and wrote you an example. I don't know if I understood exactly your timer logic, but this one activates whenever IN1 or IN2 is true, and remains active for the time period defined inside the block. I set the time period to 5 seconds to make it easier to visualize the signals on the debugger. You can define this to be whatever you want, 150ms, 10ms, anything. Accuracy is only dependent on the task cycle scan time (defined on your resource Res0) and your hardware that is running the runtime.
 
Screenshot 2023-10-13 at 10.27.13 AM.png
Screenshot 2023-10-13 at 10.29.33 AM.png
 
As you can see from the pictures, the timer output will remain active for 5 seconds after the timer is started with a positive pulse at IN1. While the timer is running, pulses at IN1 have no effect. Also, if you hold IN1 true for a long period, the timer will still generate the 5 seconds output pulse, and will only start a new pulse after IN1 has become false and true again. Here is the full source code in Structured Text for this block:
 
  1. (* Declare timers *)
  2. TOF1(IN := timer_1_input, PT := T#5s);
  3. TOF2(IN := timer_2_input, PT := T#5s);
  4.  
  5. (* Logic to activate timer 1 *)
  6. if IN1 = TRUE and started_timer_1 = FALSE then
  7.     (* Rising edge on IN1 - starting timer *)
  8.     started_timer_1 := TRUE;
  9.     timer_1_input := TRUE;
  10.  
  11. elsif started_timer_1 = TRUE and TOF1.Q = TRUE then
  12.     (* Timer has started and is running, lets make sure TOF1 input remains false *)
  13.     timer_1_input := FALSE;
  14.     
  15.     
  16. elsif started_timer_1 = TRUE and TOF1.Q = FALSE and IN1 = FALSE then
  17.     (* Timer has expired, IN1 is false, lets reset *)
  18.     started_timer_1 := FALSE;
  19.     timer_1_input := FALSE;
  20. end_if;
  21.  
  22. (* Logic to activate timer 2 *)
  23. if IN2 = TRUE and started_timer_2 = FALSE then
  24.     (* Rising edge on IN2 - starting timer *)
  25.     started_timer_2 := TRUE;
  26.     timer_2_input := TRUE;
  27.  
  28. elsif started_timer_2 = TRUE and TOF2.Q = TRUE then
  29.     (* Timer has started and is running, lets make sure TOF2 input remains false *)
  30.     timer_2_input := FALSE;
  31.     
  32.     
  33. elsif started_timer_2 = TRUE and TOF2.Q = FALSE and IN2 = FALSE then
  34.     (* Timer has expired, IN2 is false, lets reset *)
  35.     started_timer_2 := FALSE;
  36.     timer_2_input := FALSE;
  37. end_if;
  38.  
  39. (* Set outputs *)
  40. OUT1 := TOF1.Q;
  41. OUT2 := TOF2.Q;
 
Attached is the full program for your reference.
Okay, thank you very much for giving me so much help. I will carefully read your source code. Thank you again!
Reply 0 0
songyanghua
I got some free time and wrote you an example. I don't know if I understood exactly your timer logic, but this one activates whenever IN1 or IN2 is true, and remains active for the time period defined inside the block. I set the time period to 5 seconds to make it easier to visualize the signals on the debugger. You can define this to be whatever you want, 150ms, 10ms, anything. Accuracy is only dependent on the task cycle scan time (defined on your resource Res0) and your hardware that is running the runtime.
 
Screenshot 2023-10-13 at 10.27.13 AM.png
Screenshot 2023-10-13 at 10.29.33 AM.png
 
As you can see from the pictures, the timer output will remain active for 5 seconds after the timer is started with a positive pulse at IN1. While the timer is running, pulses at IN1 have no effect. Also, if you hold IN1 true for a long period, the timer will still generate the 5 seconds output pulse, and will only start a new pulse after IN1 has become false and true again. Here is the full source code in Structured Text for this block:
 
  1. (* Declare timers *)
  2. TOF1(IN := timer_1_input, PT := T#5s);
  3. TOF2(IN := timer_2_input, PT := T#5s);
  4.  
  5. (* Logic to activate timer 1 *)
  6. if IN1 = TRUE and started_timer_1 = FALSE then
  7.     (* Rising edge on IN1 - starting timer *)
  8.     started_timer_1 := TRUE;
  9.     timer_1_input := TRUE;
  10.  
  11. elsif started_timer_1 = TRUE and TOF1.Q = TRUE then
  12.     (* Timer has started and is running, lets make sure TOF1 input remains false *)
  13.     timer_1_input := FALSE;
  14.     
  15.     
  16. elsif started_timer_1 = TRUE and TOF1.Q = FALSE and IN1 = FALSE then
  17.     (* Timer has expired, IN1 is false, lets reset *)
  18.     started_timer_1 := FALSE;
  19.     timer_1_input := FALSE;
  20. end_if;
  21.  
  22. (* Logic to activate timer 2 *)
  23. if IN2 = TRUE and started_timer_2 = FALSE then
  24.     (* Rising edge on IN2 - starting timer *)
  25.     started_timer_2 := TRUE;
  26.     timer_2_input := TRUE;
  27.  
  28. elsif started_timer_2 = TRUE and TOF2.Q = TRUE then
  29.     (* Timer has started and is running, lets make sure TOF2 input remains false *)
  30.     timer_2_input := FALSE;
  31.     
  32.     
  33. elsif started_timer_2 = TRUE and TOF2.Q = FALSE and IN2 = FALSE then
  34.     (* Timer has expired, IN2 is false, lets reset *)
  35.     started_timer_2 := FALSE;
  36.     timer_2_input := FALSE;
  37. end_if;
  38.  
  39. (* Set outputs *)
  40. OUT1 := TOF1.Q;
  41. OUT2 := TOF2.Q;
 
 
Attached is the full program for your reference.
hello,1. If you use this method, it is equivalent to writing a dead 5S PT, right? If I want to change this PT, do I need to modify the code and regenerate the module using tools to introduce it into the editor, and cannot directly modify it on the module,Can I set the minimum pulse width time range I require? I don't seem to see it in the code, only the step size of 5S?
Reply 0 0
songyanghua
微信截图_20231015113121.png
error?错误T#5S 错误
Reply 0 0
thiagoralves
Use the project file I put attached. For some reason copying code from the forum sometimes causes issues
Reply 0 0
thiagoralves
songyanghua wrote:
hello,1. If you use this method, it is equivalent to writing a dead 5S PT, right? If I want to change this PT, do I need to modify the code and regenerate the module using tools to introduce it into the editor, and cannot directly modify it on the module,Can I set the minimum pulse width time range I require? I don't seem to see it in the code, only the step size of 5S?
Yes, that’s exactly the behavior of a PT with a fixed 5s pulse width. I just wanted to demonstrate that you can write logic to achieve whatever you want. You can modify this to include your minimum pulse width, for example, by adding a TON to activate the TOF timer, or replacing the whole logic with a TON and a PT in series… there are several ways you can accomplish this.

You can modify the code and regenerate the block, or modify the generated source code in MatIEC libs directly, but the latter is way harder.
Reply 0 0
songyanghua
是的,这正是具有固定 5s 脉冲宽度的 PT 的行为。我只是想证明你可以编写逻辑来实现你想要的任何东西。您可以修改此内容以包括最小脉冲宽度,例如,通过添加 TON 以激活 TOF 定时器,或将整个逻辑替换为串联的 TON 和 PT...有几种方法可以实现此目的。

您可以修改代码并重新生成块,或者直接在 MatIEC 库中修改生成的源代码,但后者要困难得多。
Okay, two questions. 1. According to the method you mentioned, if you want to set the minimum pulse width time range of 0-5min, which part of the code should be changed to set within this range?
2. If I want the initial default PT value of the timer to be 150ms, can I change the pulse width time value without changing the code by simply dragging the module externally to set the value?
Reply 0 0
thiagoralves
You’ll have to understand the code and write whatever logic you need. Anything can be done if you’re willing to put the effort to code it.
Reply 0 0
songyanghua
You’ll have to understand the code and write whatever logic you need. Anything can be done if you’re willing to put the effort to code it.
Okay, when I tested the TP timer included in the editor again, did I find that it did not implement the minimum pulse width timer function? When the input terminal receives the rising edge of the signal, the output is set to 1, and the minimum time length for outputting high level is the minimum time length I set. After 5 seconds, it is not a problem to become FALSE. Even if the input has become 0 within the minimum time length, it is not a problem for the output to remain high. The problem is that when the minimum time length is exceeded for 5 seconds, the output should follow the input, but at this point, the output still becomes FALSE.That is to say, at t1+Pulse time as shown in the figure below, the output should also continue to maintain the same state as the input. Can you test if the functionality of this module is incomplete?21.png22.png
Reply 0 0
thiagoralves
No, the PT block was implemented correctly. That’s exactly the behavior defined in the IEC standard  https://www.fernhillsoftware.com/help/iec-61131/common-elements/standard-function-blocks/timer-pulse.html
 
PT output must become false after timer period even if input remains true.
Reply 0 0
songyanghua
No, the PT block was implemented correctly. That’s exactly the behavior defined in the IEC standard  https://www.fernhillsoftware.com/help/iec-61131/common-elements/standard-function-blocks/timer-pulse.html
 
PT output must become false after timer period even if input remains true.
Okay, I see the standard protocol and I understand what you mean. When I look at the implementation logic of TP again, could you please tell me 1. LE_ TIME and__ Time_ Add and__ Time_ What does USB represent?
2__ Time_ To_ What is the function timespec (1, 0, 0, 0, 0, 0, 0) used for and what do the parameters 1, 0, and 0 represent?
Thank you very much for your answer!23.png
Reply 0 0
Reply