Today, I'm bringing you some useful information. When learning Siemens 200 PLC programming instructions, you've definitely encountered many problems, such as writing the correct instructions but not being able to use them properly, which often leaves you confused. Okay, enough chit-chat, let's get started!
1: When using a timer with self-reset to create a continuously repeating timer, why does it appear to work irregularly when calling other functions or subroutines?
Please note the descriptions of the three timer refresh rules in the "S7-200 Siemens PLC System Manual".
When using timers in this way, the timer's setting and resetting may not match the program scan cycle, potentially causing the aforementioned problems. For short-duration timed tasks, the "timer interrupt" function should be used for greater reliability.
2: I wrote a program that uses a timer. It compiles successfully, but why does it show an error when I download it to the CPU?
This situation often arises from a mismatch between the timer number and the timer type. Refer to the help table for examples; for instance, T7 can only be used as TONR, not TON or TOF.
3: The longest timer interrupt (SMB34/SMB35) is 255ms. How can a longer timer be implemented?
T32/T96 interrupts can be used, with a maximum delay of 32.767 seconds. Even longer interrupt delays can be achieved by counting the number of interrupt entries within the timer interrupt service routine.
4: What if there aren't enough timer interrupts?
Each timer interrupt service routine does not necessarily have to handle only one timed task; several tasks can be placed in one timer interrupt service routine.
For tasks with different time intervals, the greatest common divisor of their time intervals can be calculated and used as the timer interrupt setting. The interrupt service routine counts interrupt events and uses this count to program different tasks accordingly.
5: When using subroutines, why can an action only be executed once, or why can certain states not be terminated?
If an action cannot be repeated, or a state cannot be ended (like being locked), and these functions are related to subroutines, check if there are conditions for calling the subroutine. If the conditions for calling the subroutine are no longer valid after the aforementioned action is executed, or after entering a certain state, and cannot be "activated" again, and the instruction to exit the aforementioned state or reset happens to be within the subroutine, the above phenomenon will inevitably occur.
6: Why do variables defined as type OUT in a subroutine with formal parameters interfere with each other when the subroutine is called multiple times?
That's because formal parameters defined as type OUT are involved in calculations within the subroutine. All parameters of this type should be defined as type IN_OUT.
7: Why do computational tasks related to interrupt service routines sometimes produce incorrect results?
This phenomenon is often caused by an improper mechanism for transferring data between the main (sub) program and the interrupt program.
An interrupt routine may be executed at any time. If the main program (or subroutine) is operating on the data used by the interrupt routine at that time, the intermediate results may be carried over to the interrupt routine, causing changes in the calculation results. Similarly, data generated in the interrupt routine also has a similar effect on the calculations in the main (sub) program.
8: The interrupt service routine does not appear to be executing?
You can add a test segment to the interrupt routine, such as using SM0.0 (usually "1") to set an output point (using the Set instruction) and observe whether the interrupt service routine is entered. If the interrupt routine does not execute, the most common reason is a problem with initialization (connecting the interrupt event and the interrupt routine), or that interrupts are not enabled. You should perform initialization once using SM0.1 (or edge trigger), and then enable interrupts.
9: How to perform "clock synchronization" when connecting TP170, TP170micro and S7-200?
The default clock format of the TP170 differs from the time and date format read by the clock instructions of the S7-200 Siemens PLC. The read clock needs to be formatted to synchronize with the TP170. This is explained in the online help of the TP170 configuration software, ProTool.
10: How does a high-speed counter occupy an input point ?
High-speed counters occupy digital input points on the CPU as needed, based on their defined operating modes. Each counter occupies a fixed number of input points according to its operating mode. Input points not used in a certain mode can still be used as ordinary input points; input points occupied by counters (such as external reset) are still accessible in the user program.
11: Why is the high-speed counter not working properly ?
The HDEF instruction must be called using the initial scan memory bit SM0.1 in the program, and it can only be called once. Calling it with SM0.0 or executing the HDEF instruction a second time will cause a runtime error, and the counter settings from the first HDEF instruction execution cannot be changed.
12: How to address a high-speed counter ? Why can't the current count value be read from SMDx?
The current value can be read directly by addressing different high-speed counters using HC0; HC1; HC2; HC3; HC4; HC5, or the current value of the high-speed counter can be monitored directly by entering the above addresses in the status table. SMDx does not store the current value.
The high-speed counter's count value is a 32-bit signed integer.
13: How to reset a high-speed counter to 0?
A high-speed counter with an external reset mode is selected. When the external reset input signal is valid, the high-speed counter is reset to 0. Alternatively, it can be reset using the internal program. This involves setting the high-speed counter to an updateable initial value, setting the initial value to 0, and then executing the HSC instruction to reset the high-speed counter to 0.
14: After a reset, is the value of the high-speed counter reset to its initial value or to "0" ?
An external reset will reset the current value to 0 instead of the initial value; an internal reset will reset the current value to the initial value. If you set an updatable initial value but do not assign a new value to the initial value special register during the interrupt, it will be assigned the initial value set during initialization after the HSC instruction is executed.
15: Why do initial and preset values applied to the high-speed counter have no effect, or produce unexpected results ?
High-speed counters can have their settings changed during initialization or operation, such as initial values and preset values. The operating steps should be as follows:
1) Configure update options for control bytes. Set the corresponding control bit in the control byte to "1" to update the specific setting data; otherwise, leave the corresponding control bit unset.
2) Then, the required values are sent to the initial value and preset value control register.
3) Execute the HSC command
16: What type of CPU should be used to utilize the PTO/PWM generator function?
A CPU with 24VDC transistor output should be used; a CPU with relay output is absolutely unacceptable.
17: What is the amplitude of the PTO or PWM output?
The PTO or PWM output amplitude is 24V (active high, common negative terminal connected). If you want to achieve other output voltage amplitudes, you need to add a converter yourself.
18: During the execution of a PTO pulse train, can you change its period value using the PLS instruction?
No, the period value can only be changed after the PTO output is terminated.
19: How to force stop PTO or PWM output?
The PTO or PWM output can be stopped immediately by programming to clear the enable bit SM66.7 or SM76.7 in the control byte and then executing the PLS instruction.
20: Why is the output signal indicator light on, but there is no good voltage waveform output, or sometimes pulses are lost?
The minimum load of the PTO or PWM output must not be less than 10% of the rated load; that is, when the output is at a high level, the load current must not be less than 140mA.