Troubleshooting ST Program for Edge Detection in GX WORKS2

Question:

Having trouble getting a basic Structured Text example to work on my FX3U clone and would greatly appreciate some assistance. I have successfully created a ladder project that functions as expected, but I am encountering difficulties with an equivalent ST program. The program is straightforward: 1. Initially sets DAC output 0 to full scale upon startup by detecting a rising edge on special register M8002 (utilized as a 10v reference for a potentiometer). 2. At the rising edge of the 10ms clock register M8011, it samples analog input channel 1 (linked to the potentiometer) and saves the value in D0. 3. Upon the falling edge of M8011, the value in D0 is transferred to analog output 1. 4. During each scan cycle, the Y0 relay is activated if the value in D0 exceeds half scale, otherwise it is deactivated. The initialization of DAC channel 0 is functioning properly, but the detection of rising/falling edges on M8011 is not functioning as intended – the related code blocks are not being executed. I have attempted using LDP/LDF and PLS/PLF instructions without success. Assistance required! Updated Code: (* Check for startup condition *) IF LDP(TRUE, M8002) THEN (* Set DAC channel 0 to full scale output. THIS PART WORKS! *) D0 := HFFF; WR3A(TRUE, K0, K0, D0); END_IF; (* Check for clock rising edge *) (* IF LDP(TRUE, M8011) THEN *) PLS(M8011, M0); IF M0 THEN (* Read ADC channel 1. NEVER REACHES THIS POINT! *) RD3A(TRUE, K0, K1, D1); END_IF; (* Check for clock falling edge *) (* IF LDF(TRUE, M8011) THEN *) PLF(M8011, M1); IF M1 THEN (* Write ADC result to DAC channel 1. NEVER REACHES THIS POINT! *) WR3A(TRUE, K0, K1, D1); END_IF; (* Set/Clear Y0 output based on ADC channel 1 value *) Y0 := (WORD_TO_INT(D1) > H7FF);

Top Replies

I believe there is a difference in the use of D1 and D0 between the ladder and ST versions of the code.

Using IF statements may seem strange at first when working with pulse types in Structured Text (ST). If you do not have a PLC clone available to test the analogues, you can use the pulse types like this. It seems like you may be using GXW2 or GXDeveloper. If you encounter the ST function grayed out in GXDeveloper, you can switch to GXworks2. In GXworks2, you can use the pulse bit in the RD3A function instead of using IF statements. Here is an example of how to implement this: PLS(M8011, M3); ADD_E(M3, 1, D1, D1); PLF(M8013, M6); ADD_E(M6, 2, D3, D3); RD3A(M6, K0, K1, D10); Just a quick note, you mentioned that you are using GXW2, so there is no need for the K suffix.

To ensure proper initialization, there is no need to use LDP as M8002 already provides the initial pulse. When M8002 is true, the DAC channel 0 is set to full scale output successfully. Moving on to checking for the clock rising edge, consider using M8012 instead of M8011 as the 10 ms delay might be too fast for certain Chinese clones. Next, read ADC channel 1's value, but it seems to be a point of issue as the program never reaches this part. Following this, write the ADC result to DAC channel 1, which also seems to be unresolved. Finally, based on the value of ADC channel 1, Y0 output is set or cleared accordingly. Please note that this program has not been tested but was written based on your provided code.

Why should you opt for LDP and LDF over PLS and PLSF? Furthermore, the LDP on M8002 (First-pass bit) seems unnecessary as M8002 is always a one-shot. Nonetheless, this configuration should be effective; I have also reverted the D0 and D1 to align with the ladder diagram example. Code: (* Store instantaneous value of a 100Hz (10ms) clock in buffer *) M0 := M8011; (* Check for startup condition *) IF M8002 THEN (* Prevent first-pass scan cycle from detecting a rising edge *) M1 := M0; (* Set DAC channel 0 to full scale output. This adjustment is successful! *) D1 := HFFF; WR3A(TRUE, K0, K0, D1); END_IF; (* Detect clock rising edge *) IF M0 AND NOT M1 THEN (* Read ADC channel 0 *) RD3A(TRUE, K0, K1, D0); END_IF; (* Detect clock falling edge *) IF M1 AND NOT M0 THEN (* Write ADC result to DAC channel 0 *) WR3A(TRUE, K0, K1, D0); (* Adjust Y0 output based on ADC channel 0 value *) Y0 := (WORD_TO_INT(D0) > H7FF); END_IF; (* Store current clock signal value for edge detection in the next scan cycle *) M1 := M0;

You can disregard the TRUE bit in the RD3A and simply utilize the pulse bit M8002 instead. This adjustment will effectively streamline operations and enhance performance.

I think the issue might be related to your utilization of the PLS and PLF instructions. These instructions are essentially pulse outputs and may not function as you're expecting here. You might try using the ST specific instructions, like R_TRIG and F_TRIG, to detect the rising and falling edges of M8011 respectively. These detect changes from false to true (rising edge) and true to false (falling edge). I'm not entirely sure without looking at your overall code, but this change might help resolve your issue.

Firstly, make sure that the M8011 register is functioning as expected in itself. One way to debug this could be to toggle a physical output on this clock to see if it's actually oscillating. Secondly, make sure that the issue is not due to variable initialization. It's a common mistake in Structured Text to forget about it and then wonder why your program is not working. Regarding the PLS and PLF instructions, they only recognise a true state for one scan so you should ensure that other operations within those conditions can be completed within one scan. If not, you might have to restructure your code.

It sounds like you've put a lot of work into this and you're almost there! Now, as for the issue you're having with the PLC not detecting the edge transitions of M8011, it reminds me of a similar problem I had. It turned out the FX3U clone does not support rising or falling edge detection on special function registers. This would explain why your PLS/M0 and PLF/M1 blocks aren't working as intended. I would suggest replacing M8011 (10ms clock pulse) with a regular M coil that's pulsed every 10ms using a timer. This way, the PLS and PLF instructions should function correctly. So, instead of checking for rising and falling edges on M8011, you would check them on your new M coil. Hope this helps!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: 1. Why is the detection of rising/falling edges on special register M8011 not functioning as intended in the provided ST program?

Answer: - The detection of rising/falling edges on M8011 might not be working due to potential issues with the usage of PLS/PLF instructions. Make sure the logic for detecting edges is correctly implemented.

FAQ: 2. What could be the reason for the code blocks related to sampling analog input and transferring values not being executed in the ST program?

Answer: - The code blocks for sampling analog input and transferring values may not be executing due to potential issues with the condition checks or the flow of the program. Review the logic and ensure proper execution flow.

FAQ: 3. How can I troubleshoot and resolve the issue with the ST program for edge detection in GX WORKS2?

Answer: - To troubleshoot the ST program, you can check for errors in the logic, verify the conditions for edge detection, and ensure the correct usage of instructions like PLS/PLF. Additionally, debugging tools provided by GX WORKS2 can be utilized to track program execution.

FAQ: 4. Is there a specific method recommended for handling edge detection in structured text programming for FX3U PLCs?

Answer: - When working with edge detection in structured text programming for FX3U PLCs, it is essential to use the appropriate instructions like PLS/PLF for capturing rising/falling edges accurately. Ensure that the conditions for edge detection are correctly set up to trigger the desired actions

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  â†’