codesys FBD question

ganutenator

Lifetime Supporting Member
Join Date
May 2002
Location
kansas
Posts
1,440
I only have one POU in the program that is written in Function Block Diagram.
It is only 12 rungs, so I could just re write it into structured text, but...

All I am trying to do is add...


Code:
IF (VariableA = 3) THEN
 VariableB:= -115;
END_IF;

But trying to do this in FBD in Codesys is :eek:

Mainly having trouble adding an EN input to the Move block is where I am stuck.
 
I do not use FBD much (we may share a preference for ST), but I would think you can right-click in the code line and either Insert-Empty-Box or Insert-Empty-Box-with-EN. The latter would be what you need.

The box with EN would then become a MOVE block which assigns the value of -115 to your VariableB.
 
I have never used Codesys, however, I assume it is IEC compliant so assume there is a pick box of functions just drop a compare & a move function onto the code.
like this:

FBD.png
 
Yes I forgot to mention what Lare has said, it will depend on the data type & in this case the functions need to be correct, for example there may be a move function that does not require the Enable pin, the same goes for the compare.
Again it may depend on the way codesys use FBD in some platforms there is no need to use a different function for say integer, float etc. as it automatically compiles the correct code, but most do have functions based on the data type examples for one platform is that the subtract has a number of forms
SUB function is integer 16 bit
DSUB is is 32 bit integer
DESUB is 32 bit float.

FBD.png
 
Funny, I tried it this afternoon in Wago software. Will try to remember to do the same again tomorrow so I can take a screenshot for you. Feel free to remind me in case I forget.
 
All I am trying to do is add...

Code:
IF (VariableA = 3) THEN
 VariableB:= -115;
END_IF;
But trying to do this in FBD in Codesys is :eek:

Mainly having trouble adding an EN input to the Move block is where I am stuck.

Why don't you use the constant 'TRUE'?

If I understood your inquiry correctly, I think what you needs is shown below:

2022-03-18_FBD_Test.png
 
Thank you for all of your help.
I gave up on FBD. Couldn't figure out how to add the EN pin.
I ended up w/ this.

The M340 Analog Input card works different than the 750-0496 one for the wago 750-862.

Customer complained about not seeing -115 psig when the wire was disconnected.

I haven't tested the code yet. This feels like a band aid and I could probably write it better. Feel fee to rag on me.

Code:
SidePressRawWord:= INT_TO_WORD(SidePressRaw);

(*masks out specialty bits B0 to B2 and B15*)
SidePressMasked:= SidePressRawWord AND 16#7FF8;

AiChan1(
	raw_real:= SidePressMasked ,
	raw_min_real:= 0,
	raw_max_real:= 32760,
	eu_min_real:= 0,
	eu_max_real:= 1450,
	limit_overflow:= FALSE,
	fail_hi:= FALSE,
	scaled_out=> side_press_real );

(*broken wire indication*)
IF SidePressRaw = 3 THEN
	side_press_real:= -115;
END_IF;

TopPressRawWord:= INT_TO_WORD(TopPressRaw);

topPressMasked:= TopPressRawWord AND 16#7FF8;

AiCh2(
	raw_real:= TopPressMasked,
	raw_min_real:= 0,
	raw_max_real:= 32760,
	eu_min_real:= 0,
	eu_max_real:= 1450,
	limit_overflow:= FALSE,
	fail_hi:= FALSE,
	scaled_out=> top_press_real);

(*broken wire indication*)
IF TopPressRaw = 3 THEN
	top_press_real:= -115;
END_IF;

OutsideTempRawWord:= INT_TO_WORD(OutsideTempRaw);

OutsideTempMasked:= OutsideTempRawWord AND 16#7FF8;

AiCh3(
	raw_real:= OutsideTempMasked,
	raw_min_real:= 0,
	raw_max_real:= 32760,
	eu_min_real:= -30,
	eu_max_real:= 120,
	limit_overflow:= TRUE,
	fail_hi:= FALSE,
	scaled_out=> outside_temp_real);

BayTempRawWord:= INT_TO_WORD(BayTempRaw);

BayTempMasked:= BayTempRawWord  AND 16#7FF8;

AiCh4(
	raw_real:= BayTempMasked,
	raw_min_real:= 0,
	raw_max_real:= 32760,
	eu_min_real:= -30,
	eu_max_real:= 120,
	limit_overflow:= TRUE,
	fail_hi:= FALSE ,
	scaled_out=> bay_temp_real);

p.s. If you are curious, I rolled my own SCP function like they had in the Allen Bradley Slc.
Feel free to critique that as well.

Code:
(* // convert the inputs to floats*)
input_real:= raw_real;
input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;

(*// calculates the slope OR rate; i.e. rise over the run*)
IF ((input_max - input_min) <> 0.0) THEN
  rate:= (scaled_max - scaled_min) / (input_max - input_min);
ELSE
  rate:= 0.0;
END_IF;

(*// calculates the offset)*)
offset:= scaled_min - (input_min * rate);

(*// performs the scaling calculation; i.e. y = mx+b*)
output_real:= (input_real * rate) + offset;

(*// IF the "Limit_En" flag is set THEN LIMIT the output TO within the scaling parameters*)
IF limit_overflow THEN
	IF output_real > scaled_max THEN
		output_real:= scaled_max;
		fail:= TRUE;
	ELSIF output_real < scaled_min THEN
		output_real:= scaled_min;
		fail:= TRUE;
	ELSE
		fail:= FALSE;
	END_IF;
ELSE
	fail:= FALSE;
END_IF;

IF fail_hi AND fail THEN
	output_real:= scaled_max;
ELSIF fail THEN
	output_real:= scaled_min;
END_IF;

scaled_out:= output_real;
 
Alfredo can you not just connect the output of the compare to the move rather than have an intermediate flag ?, never used that software but if not it is pretty poor. Also is there not a = function rather than a AND= i.e. enable.
 
parky: I do not use FBD very often. Tried but cannot add a box to the binary output of the EQ command. It may be possible, I just do not know how to do this. Tried to take a screenshot but when you take the screenshot the interesting part of the shape of the cursors do not get captured in the screen grab.
In ladder or FBD I think the equivalent of "=" is EQ. Again there may be other ways to do this.
By the way, The CODESYS environment can be donwloaded for free. And the Windows version of the soft-PLC works in demo mode for about an hour and you can stop and start the PLC again and again. So you can test this software free of charge and do not need to get RasPi or license.
 
Just downloaded it & tried, it will allow connections to other functions as this pic shows, however, I do not like the IDE, seems a bit slow, I have an I7 16g ram SSD etc. so a pretty high spec PC.

FBD.png
 
If you drop an empty box on the form then click the .... select the function you want. Seems a bit of a taxing way to drop the components on it, slow, not very informative & unlike GXWorks where you just drop all your blocks & then wire them.
 

Similar Topics

Hello, So in RSLogix 5K I would be used to doing the following: 1. Double click the left of the rung, to bring the rung text editor, will be...
Replies
4
Views
2,113
Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
6
Views
300
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
91
Hello, I am new to Codesys, and am trying to learn about it for a project we're developing. I've got a couple questions, but first a little...
Replies
1
Views
163
Hi everyone, as this is my first experience with Rockwell Software i would like to know what's the best way to make Enumerations?
Replies
10
Views
515
Back
Top Bottom