6.3.1 Introduction to SFC Language
6.3.1.1 SFC basic knowledge
-
SFC provides a means to link a set of steps and transitions to each other through directed connections to write programs in the format of a sequence program. Each step is associated with a set of actions, and each transition is associated with a transition condition.
-
SFC requires the storage of status information of elements such as steps. Baosky IDE only supports FB can be programmed with SFC. PRG and FC cannot be programmed with SFC
-
A SFC structured network is divided into a series of steps and transitions. They are evaluated and executed in a loop. A step is always active or inactive. Each time through the loop, all conversions are evaluated, and the result is either TRUE or FALSE. The list of active steps for a pending loop depends on the calculated values of the transformations on which these steps depend.
- Reasonable division of steps
Clearly define each step: Each step should represent a distinct control state or operation. Ensure steps are properly divided to avoid overly complex or ambiguous steps.
Avoid too many or too few steps: Excessive steps can make the program overly lengthy and difficult to manage, while insufficient steps may result in unclear or ambiguous program logic. Therefore, when designing an SFC diagram, balance the number of steps to ensure the logic is clear and concise. - Transition condition (Transition) settings
Clearly defined transition conditions: Transitions act as bridges between steps, and each transition must have clearly defined conditions. These conditions should be measurable and verifiable to avoid vague or undefined conditions that may lead to logical errors.
Priority of condition evaluation: If multiple transition conditions are met simultaneously, the SFC program should clearly define which condition takes precedence to prevent priority conflicts.
Avoid unnecessarily complex conditions: Overly complex transition conditions may lead to debugging difficulties and runtime errors. Conditions should be as concise and intuitive as possible. - Activation and deactivation of steps
Properly control step activation: Ensure steps are activated at the appropriate time. For example, after a step is executed, it should be deactivated promptly to prevent it from continuing to occupy system resources.
Avoid unnecessary repeated activation: If a step does not require reactivation, you should ensure that it will not be activated repeatedly to prevent unnecessary system overhead. - Use of parallel steps
Appropriate use of parallel steps: SFC allows multiple steps to be executed simultaneously, but care must be taken to manage interactions and dependencies between parallel steps to avoid resource conflicts or deadlocks.
Synchronization in parallel execution: If parallel steps depend on the same inputs or outputs, proper synchronization must be ensured to prevent race conditions and conflicts. - Avoid overly complex steps and transfers
Modular design: Avoid overly complex steps by simplifying operations into independent small tasks. Complex logic can be broken down into sub-steps or modules to improve readability and maintainability.
Streamlined process design: Minimize the use of nested steps and transitions. Complex logic can complicate debugging and maintenance. - Prevention of deadlocks and infinite loops
Avoid deadlocks: Deadlocks can occur in SFC, especially when transition conditions between steps are improperly configured. Ensure each step has clearly defined transition conditions and that no conflicting conditions hinder progression to the next step.
Prevent infinite loops: Ensure proper exit conditions are defined for each step or transition to prevent the program from entering infinite loops. Each step should have a clearly defined end condition. - Event driven and time delay processing
Appropriate use of time delays: SFC allows the use of timers to control time delays, but over-reliance on delays should be avoided. Excessive delays may result in delayed control responses, while insufficient delays may lead to unstable control.
Event-triggered control: Prefer event-driven control over fixed time intervals to improve the flexibility and real-time performance of the program. - Error handling mechanism
Implement robust fault handling: Design appropriate error handling mechanisms at each step or transition. For example, use error flags, fallback steps, etc. to ensure the system responds appropriately when a failure occurs.
Exception handling design: Ensure that when an exception occurs, the system can recover from the error state in an orderly manner rather than entering an undefined state. - Testing and Verification
Incremental verification: After completing the SFC program design, perform single-step and incremental debugging to verify whether each step and transition condition functions as expected.
Simulation and testing: Use simulation tools or test on actual hardware to validate the program logic and ensure there are no omissions or errors. - Documentation and Comments
Annotate steps and transitions: Although the graphical design of SFC diagrams is intuitive, it is still recommended to provide detailed annotations for key steps, transition conditions, inputs, and outputs to facilitate future modifications and maintenance.
Comprehensive documentation: For more complex SFC diagrams, it is best to provide detailed design documents describing the system's working principles, logical flow, and functions of each step to facilitate collaboration among team members.