Join us today!

Using AND_THEN , OR...
 
Notifications
Clear all

Using AND_THEN , OR_ELSE vs AND, OR in TwinCAT

3 Posts
3 Users
2 Reactions
1,101 Views
twinControls
Posts: 114
Admin
Topic starter
(@twincontrols)
Member
Joined: 2 years ago

We will discuss the effects of using AND_THEN, OR_ELSE vs AND,OR operators in this tutorial . 

AND , AND_THEN: 

When AND operator is used , all the operands get evaluated for the corresponding condition in TwinCAT. 

IF bCondition1 AND bCondition2 AND ...... THEN ---> TwinCAT evaluates all the conditions 

IF bCondition1 AND_THEN bCondition2 AND_THEN ...... THEN ---> TwinCAT evaluates the bCondition1 first, if it is FALSE, bCondition2 doesn't get evaluated. Other operands gets executed only if the first operand of the AND_THEN is TRUE.

This operand may come in handy when dealing with pointers. Let's check the example below. Add the code in your main program: 

VAR
	pData : PVOID;
	nNumber:POINTER TO INT;
END_VAR
nNumber := pData;
IF pData <> 0 AND nNumber^ = 95 THEN
	nNumber :=5;
END_IF

 

In the code, we have assigned the value of pData to the address of the nNumber variable. Since the address of the nNumber becomes 0, this would cause an exception in TwinCAT when evaluating the nNumber^ = 95 condition. If you execute this code, you would get the exception below: 

and else exception

 

If you use AND_THEN instead, TwinCAT doesn't evaluate (nNumber^ = 95) condition since the evaluation of pData <> 0 is FALSE. Therefore, you would not get an exception in this case. 

and else no exception

 

 

OR, OR_ELSE:

When OR operator is used , all the operands get evaluated for the corresponding condition in TwinCAT. 

IF bCondition1 OR bCondition2 OR ...... THEN ---> TwinCAT evaluates all the conditions 

IF bCondition1 OR_ELSE bCondition2 OR_ELSE ...... THEN ---> TwinCAT evaluates the bCondition1 first, if it is TRUE, bCondition2 doesn't get evaluated. If the first operand of the OR_ELSE is TRUE, other operands are no longer executed. 

 

To see the effect , we have created a method called IncreaseBy and inside this method we are always returning TRUE and we are logging a warning every time the method gets executed. 

FB_Calculate.IncreaseBy():

METHOD IncreaseBy : BOOL
VAR_INPUT
	nNumber : REFERENCE TO INT;
	nIncreaseBy : INT;
END_VAR
nNumber := nNumber + 1;
ADSLOGSTR(ADSLOG_MSGTYPE_WARN, 'Increase By Method executed', '');
IncreaseBy := TRUE;

 

Add the code below in the MAIN program : 

VAR
	bSystemActive : BOOL := TRUE;
	fbCalculate : FB_Calculate;
	bStart : BOOL;
	nNumber : INT;
	
	bDo_1 : BOOL;
	bDo_2 : BOOL;	
END_VAR

IF bDo_1 THEN
	bStart := bSystemActive OR fbCalculate.IncreaseBy(nNumber,1);
	bDo_1 := FALSE;
END_IF 

IF bDo_2 THEN
	bStart := bSystemActive OR_ELSE fbCalculate.IncreaseBy(nNumber,1);
	bDo_2 := FALSE;
END_IF 

 

Every time, this line ;

bStart := bSystemActive OR fbCalculate.IncreaseBy(nNumber,1);

 gets executed, we will get the warning and the number will be increased by 1 since all the conditions get evaluated. 

 

However, in this line ;

bStart := bSystemActive OR_ELSE fbCalculate.IncreaseBy(nNumber,1);

  fbCalculate.IncreaseBy(nNumber,1) gets evaluated only if bSystemActive is FALSE. 

 

 

In this video, we can see that every time we set bDo_1 to TRUE, we would get the warning and we see the increment effect because of IncreaseBy() method getting evaluated. 

When we set bDo_2 to TRUE, we don't get a warning and the number doesn't increase because fbCalculate.IncreaseBy(nNumber,1) doesn't get executed since bSystemActive is already TRUE. 

 

 

Reply
2 Replies
rruiter
Posts: 63
(@rruiter)
Estimable Member
Joined: 2 years ago

Another example from plccoder

Reply
Posts: 1
(@mancubus0gew)
New Member
Joined: 2 months ago

generator balancing

Generator Balancing: The Importance of Dynamic Balancing Solutions

Generator balancing is a critical process that helps ensure the smooth and efficient operation of various types of machinery, particularly those with rotating elements. In industries where equipment such as crushers, fans, mulchers, augers, shafts, centrifuges, and turbines are used, balancing becomes essential for enhancing performance and prolonging equipment life.

Understanding Dynamic Balancing

Dynamic balancing involves measuring the vibrational forces that occur during the rotation of machinery and making adjustments to minimize these forces. When components are not properly balanced, they can create excessive vibrations that lead to wear and tear, ultimately resulting in costly repairs or equipment failure. The Balanset series of portable balancers and vibration analyzers, like the Balanset-1A and Balanset-4, are designed to facilitate this process effectively.

The Balanset-1A: Versatility in Balancing

The Balanset-1A is a portable balancer known for its dual-channel capability, making it suitable for dynamic balancing in two planes. This model is ideal for various machinery, offering the versatility required by different industries. Whether you need to balance a fan, a crusher, or a turbine, the Balanset-1A provides the necessary tools to achieve precision.

Balanset-4: A Step Up in Complexity

For more complex applications, the Balanset-4 features four channels designed for dynamic balancing in four planes. It is particularly effective for balancing cardan shafts and is often used in conjunction with balancing machines that have multiple supports. This advanced system ensures that all aspects of balancing are accounted for, leading to optimal performance and reliability.

Why is Generator Balancing Necessary?

Generator balancing serves multiple purposes, including the reduction of vibrations that could lead to equipment degradation. Proper balancing results in smoother operation, which is essential for maintaining energy efficiency and reducing operational noise. Additionally, it significantly cuts down on downtime caused by repairs to unbalanced equipment.

Applications and Impact of Poor Balancing

Centrifuges are a notable example of equipment that heavily relies on proper balancing. In medical and chemical industries, centrifuges separate liquids based on density. When these machines are unbalanced, the ensuing vibrations can lead to inaccurate separations and potential damage to the equipment. Regularly scheduled balancing not only prevents these issues but also extends equipment lifespan and reliability, demonstrating the importance of generator balancing in maintaining operational excellence.

DIY Balancing: Making it Accessible

For those looking to engage in generator balancing themselves, portable balancers like the Balanset-1A provide an accessible way to perform these measurements. Many users can appreciate the ease of use provided by this portable device, which comes equipped with necessary sensors and tools. Having a balancing system that is user-friendly allows operators to conduct routine checks, reducing reliance on external vendors.

Key Features of the Balanset Series

  • Portability: The compact design of Balanset devices allows for easy transport to various job sites.
  • User-Friendly: Both the Balanset-1A and Balanset-4 are designed to be intuitive, making them suitable for users with varying levels of expertise.
  • Versatile Applications: These systems can be applied to a wide range of rotors and machinery, ensuring broad usability across multiple industries.
  • Accurate Measurements: Equipped with high-precision sensors, the Balanset series delivers reliable data for effective balancing.

The Role of Vibration Analysis in Balancing

Vibration analysis is an integral part of the generator balancing process. It provides insight into the performance and condition of rotating elements. By identifying vibrations during operation, maintenance personnel can detect imbalances before they escalate into larger issues. This proactive approach aids in preventing unexpected failures and maintenance costs.

Conclusion

In the realm of generator balancing, it's evident that neglecting the importance of dynamic balancing can lead to severe operational ramifications. The Balanset series products offer an efficient and impactful solution for addressing these concerns, providing industries with the ability to enhance their equipment performance. With the aid of portable balancing devices, industries across various sectors can achieve smoother operations, elevated efficiency, and reduced wear and tear, ultimately safeguarding their investment and guaranteeing optimal functionality.

Get in Touch

If you’re looking for high-quality balancing solutions or need assistance with dynamic balancing for your equipment, reach out. Our team of experts is readily available to provide guidance, answer questions, and support you in achieving effective generator balancing.

Reply
Share: