Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

Join our "Ask Me About" community webinar on May 20th at 9 AM CET and 5 PM CET to explore cybersecurity and monitoring for Data Center and edge IT. Learn about market trends, cutting-edge technologies, and best practices from industry experts.
Register and secure your Critical IT infrastructure

Function vs Function blocks

HVAC and Pumping Forum

Support Forum for HVAC and pumping machines, Modicon M17x and EcoStruxure Machine Expert HVAC software for chillers, AHU, CRAC units for datacenters or process chillers applications - from design, implementation to troubleshooting and more, by Schneider Electric.

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • Industrial Automation
  • HVAC and Pumping Forum
  • Function vs Function blocks
Options
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
FedericoM
Commander FedericoM Commander
67
Bastian_Schmitz
Admiral Bastian_Schmitz Admiral
47
LeTomas
Lt. Commander LeTomas Lt. Commander
14
View All

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Solved Go to Solution
Back to HVAC and Pumping Forum
Solved
otrotabi
Lt. Commander otrotabi
Lt. Commander

Posted: ‎2022-06-21 05:28 AM . Last Modified: ‎2022-06-21 05:29 AM

0 Likes
8
5162
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-21 05:28 AM . Last Modified: ‎2022-06-21 05:29 AM

Function vs Function blocks

I realize this subject has many answers on Google so I apologize for posting it, but still the main reason for choosing a function over a funcion block is not clearly answered I think.

 

So, I need to create a function (or a function block) to validate a password. I plan to define 4 password levels:  0-User 1-Maintenance 2-OEM 3-Developer which will give a USINT output based on each input, and according to that level it willl let some variables and screens be accesed at the HMI.

 

So basically I think I could either use a FC or a FB.  Intuitively I would assume that FCs use less PLC resources. Is that the reason for choosing that ?

 

 

Labels
  • Labels:
  • HVAC
  • Tags:
  • ecostruxure
  • english
  • hmi
  • hvac
  • TM172
Reply

Link copied. Please paste this link to share this article on your social media post.

  • All forum topics
  • Previous Topic
  • Next Topic

Accepted Solutions
FedericoM
Commander FedericoM Commander
Commander

Posted: ‎2022-06-21 05:40 AM

0 Likes
7
5157
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-21 05:40 AM

Hi,

 

the main differences are the followings:

 

Functions: 1 output, n input

Function Blocks: m output, n input.

 

Function input are not supporting complex types (at least in version 1.4.0)

 

Function blocks are declared as instance of an object, so the internal memory is static, while the one of the functions is allocated in the stack.

It means every time you call a function the local variable are reset, while a FB instance mantains the value reached at previous execution.

So FBs use more RAM because each instance requires a dedicated local memory allocation.

 

If you need internal states, like the integral part of a PID, i.e. your output depends on input and previous states, you need a FB.

 

Federico 

See Answer In Context

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

Replies 8
FedericoM
Commander FedericoM Commander
Commander

Posted: ‎2022-06-21 05:40 AM

0 Likes
7
5158
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-21 05:40 AM

Hi,

 

the main differences are the followings:

 

Functions: 1 output, n input

Function Blocks: m output, n input.

 

Function input are not supporting complex types (at least in version 1.4.0)

 

Function blocks are declared as instance of an object, so the internal memory is static, while the one of the functions is allocated in the stack.

It means every time you call a function the local variable are reset, while a FB instance mantains the value reached at previous execution.

So FBs use more RAM because each instance requires a dedicated local memory allocation.

 

If you need internal states, like the integral part of a PID, i.e. your output depends on input and previous states, you need a FB.

 

Federico 

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

otrotabi
Lt. Commander otrotabi
Lt. Commander

Posted: ‎2022-06-21 08:24 AM . Last Modified: ‎2022-06-21 08:24 AM

In response to FedericoM
0 Likes
6
5142
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-21 08:24 AM . Last Modified: ‎2022-06-21 08:24 AM

Thanks for your answer.  As I expected, basically it takes less PLC resources, right ?

 

Actually i have always used FB, as default. But since I am trying to work with TM171 as well, I´d better start using FC when I can.

 

I just developed my first FC and included a TON timer there. I could not understand why it was not working until it dawned on me that it will not, right ?

 

 

 

 

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

FedericoM
Commander FedericoM Commander
Commander

Posted: ‎2022-06-23 01:45 AM

In response to otrotabi
0 Likes
2
5116
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-23 01:45 AM

Hi,

 

you can't declare FB instances inside a Functions for the reason explained before.

A FB has internal states declared in a static ram while Functions use temporary ram allocated just for the function execution.

 

If you do it, you should get a compiler error related to invalid data type used in the function.

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

otrotabi
Lt. Commander otrotabi
Lt. Commander

Posted: ‎2022-06-23 04:09 AM

In response to FedericoM
0 Likes
1
5110
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-23 04:09 AM

Thank you. Yes, I understood why this attached function (FC) will not work. It does not keep track of time, so it only works if you define it as a FB. However, regarding your last comment, the compiler does not throw any errors or warnings about a FB being used inside a FC. I am using 1.4.0.

 

 

FUNCTION PasswordManager: USINT

VAR
	PasswTimer : TON;	(* After time elapses resets output to cero *)
END_VAR

VAR_INPUT
	i_uiHmiPassword : UINT;	(* Password entered at HMI *)
	i_uiLevel1Password : UINT;	(* Password stored in Eeprom level1 - Installer *)
	i_uiLevel2Password : UINT;	(* Password stored in Eeprom level2 - OEM *)
	i_uiLevel3Password : UINT;	(* Password stored in Eeprom level3 - Developer *)
	i_uiDate : TypeDataTime;	(* Current date *)
	i_usiPassCfg : USINT;	(* Configuration of password check *)
	i_uiTimePassword : UINT;	(* Time to enable password level <> 0 in seconds *)
END_VAR

IF i_uiHmiPassword = 0 THEN
	PasswordManager := 0;
	RETURN;
END_IF;

CASE i_usiPassCfg OF
	0: IF i_uiHmiPassword  = i_uiLevel1Password THEN
			PasswordManager := 1;
		ELSIF i_uiHmiPassword  = i_uiLevel2Password THEN	
			PasswordManager := 2;
		ELSIF i_uiHmiPassword  = i_uiLevel3Password THEN	
			PasswordManager := 3;
		ELSE
			PasswordManager := 0;
		END_IF;
		
	1: //Date dependent password if usiPassCfg = --- SAMPLE CODE
		IF i_uiHmiPassword = (i_uiDate.daymonth * 2 + i_uiDate.dayweek * 3 + i_uiDate.month * 4 + i_uidate.year)THEN
			PasswordManager := 1;
		ELSIF i_uiHmiPassword = (i_uiDate.daymonth * 3 + i_uiDate.dayweek * 4 + i_uiDate.month * 5 + i_uidate.year)THEN
			PasswordManager := 2;
		ELSIF i_uiHmiPassword = (i_uiDate.daymonth * 4 + i_uiDate.dayweek * 5 + i_uiDate.month * 6 + i_uidate.year)THEN
			PasswordManager := 3;
		END_IF;

END_CASE;	

IF PasswordManager < 3 THEN // If developer signs in, will allow everything till PLC is reset or password is changed
	PasswTimer(IN := TRUE, PT := i_uiTimePassword * 1000);
	IF PasswTimer.Q THEN
		PasswordManager := 0; //Resets Password
		PasswTimer( IN := FALSE); //Resets timer
	END_IF;
END_IF;		

 

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

FedericoM
Commander FedericoM Commander
Commander

Posted: ‎2022-06-23 05:13 AM

In response to otrotabi
0 Likes
0
5102
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-23 05:13 AM

It seems a problem of the simulator, if I compile for a real target I have the error.

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

Bastian_Schmitz
Admiral Bastian_Schmitz Admiral
Admiral

Posted: ‎2022-06-27 12:28 PM

In response to otrotabi
0 Likes
2
4988
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-27 12:28 PM

If you want save ressources here some tips

1. Global Variables need ressources, Status and EEPROM variables not. If you use instead of global vars status you can save space.

2. If you use your own FCs/FBs then use always the smalles possible data types. If you use INT instead of REAL you will save 50% space (16/32Bit). 

3. If you need STRING vars, reduce the char number of the suitable minimum

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

otrotabi
Lt. Commander otrotabi
Lt. Commander

Posted: ‎2022-06-27 12:59 PM . Last Modified: ‎2022-06-27 12:59 PM

In response to Bastian_Schmitz
0 Likes
1
4983
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-27 12:59 PM . Last Modified: ‎2022-06-27 12:59 PM

Thanks for your tips. Some further questions, I hope you don´t mind.

 

• Is IL worth learning ? According to wikipedia it is deprecated and will no longer exist sometime in the future. I noticed most (if not all) of the  FB/FCs available in both basic and basic addons libraries are written in IL so I am curious to know what would happen then.

 

• I´ve also noticed these libraries are organized following an XML structure. Is it compatible with some other programs ? Codesys maybe ? How do you create a folder structure for libraries ?

 

• Are some of the OSCAT libraries worth importing ? It seems there are hundreds of different functions and function blocks available.

 

Regards

 

 

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

Bastian_Schmitz
Admiral Bastian_Schmitz Admiral
Admiral

Posted: ‎2022-06-27 01:08 PM

In response to otrotabi
1 Like
0
4978
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2022-06-27 01:08 PM

Hello 

Personally I see now reason to use IL/AWL, I would expect ST is alltime more up to date. I learn IL/AWL 10 years ago and I use is than this time exactly 0 times. Maybe I´m wrong but I would expect IL/AWL is an old fashion langugage for people which are near to retierment 🙂

 

You can excahnge data between Codesys and ESME HVAC via PLCopenXML format. You could find a documentation to this topic here. I hope that will help you.

Normally you could convert FCs/FBs from OSACT to ESME HVAC. I started with a general conversion but I find not enough time. Normally you need "only" to adjust sometimes the syntax.

 

  • Tags:
  • english
Reply

Link copied. Please paste this link to share this article on your social media post.

Preview Exit Preview

never-displayed

You must be signed in to add attachments

never-displayed

 
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of