Sign in to follow this  
Followers 0
pete3589

Imbedded Variables in S7 SCL

7 posts in this topic

I am new to S7 programming and I come from primarily an AB RSLogix 5000 background. A good chunk of what I do involves using imbedded variables which were quite easy to use in RSLogix 5000 Structured text format. I was told to use SCL since it would be similar to AB structured text. Below is something I put together quickly. I basically want to put analog input module data into the Analog Input array I created. FUNCTION FC5 : INT // Temporary Variables VAR_TEMP i : INT; END_VAR CONST x := 400; END_CONST // Statement Section BEGIN FOR i = 0 TO 7 DO "AnalogInputBlock".AnalogInputs.PIDValue := PIW [x]; x := x+2; END_FOR; END_FUNCTION There are a whole bunch of errors in the above code, but basically I just need some garbage variables (x and i above) that increase by 1 and 2 to accomplish this and then have it loop. Am I headed in the right direction at all?

Share this post


Link to post
Share on other sites
Hi pete3589. You have probably created a DB with the desired structure "AnalogInputBlock".AnalogInputs.PIDValue AnalogInputs is probably an array. So far so good. I see 2 problems. 1st, you cannot adress a PIW via an index (PIW [x]). 2nd, to my opinion it is a bit inflexible to have to hardcode the base adress (x := 400). To do the same job I have made some code that loops all the desired number of analog channels. This I do in an SCL block with the only argument being how many channels to scan. Then before calling the SCL block I transfer the hardware adresses into the DB for further processing. L PIW 256 T "AI".Ch[1].iInputRaw L PIW 258 T "AI".Ch[2].iInputRaw L PIW 344 T "AI".Ch[3].iInputRaw etc. Remember that you have to scale the raw input values to engineering values. To pass such things as engineering value ranges, I can in either code, or from the HMI set like: L -50.0 T "AI".Ch[1].rMinRange L 150.0 T "AI".Ch[1].rMaxRange etc. Alternatively, there is a block for scaling FC105 (scales one channel at a time). You find it in the standard library under TI-S7 converting blocks. Edited by JesperMP

Share this post


Link to post
Share on other sites
Thanks Jesper. I decided to do it the way you suggested where I simply use STL to transfer the data into the array that I need. You were also spot on with what I was planning on doing with the min and max spans. This is going to be user configurable from the HMI. The one concern I have is when I set up my alarm and trip code. Basically it will cycle through my arrays which will check to see if alarming is enabled, and then determine whether the input is above or below the user entered value. I will eventually have to use an imbedded variable and I am not sure how to do this. Basically it would be something like this FOR x = 0 to 95 DO IF "AnalogInputBlock".AnalogInputs[x].OnOff THEN // If the input is turned on IF "AnalogInputBlock".AnalogInputs[x].AlarmHighEn THEN // and if there is a high alarm value entered IF "AnalogInputBlock".AnalogInputs[x].AlarmHighValue < "AnalogInputBlock".AnalogInputs[x].Value" THEN // if the scaled value is higher than the alarm value "AnalogInputBlock".AnalogInputs[x].AlarmTrigger = 1 // set the channels alarm bit End_For etc etc. I am also noticing that not many people use SCL and most use STL? I guess my Pascal / C++ background makes that seem like a better option for me.

Share this post


Link to post
Share on other sites
Hi agian pete3589 Just a comment. You code sets the High alarm but never resets it. Generally you can do IF conditions THEN alarmbit:=TRUE ELSE alarmbit:=FALSE ENDIF However a more condensed way (efficient if you may) is to write alarmbit := conditions ; That most people dont use SCL is because of the inertia in automation, and also because you have to pay extra to get SCL. Maybe the proliferation of IEC61131-3 capable PLCs which almost always have the Structured Text language (which is in principle the same as SCL) will change this.

Share this post


Link to post
Share on other sites
That is true that I did not reset the alarm bit, but I would take care of that in another portion of the code. What bothers me is that when I talk about coding AnalogInputs[x].Rvalue, it seems that there is no way to do this in Siemens. I want to physically put the [x] in my code and then change the x value when I complete a scan. Is there no way to do this, or do I need to follow a certain syntax in order to get the x recognized as a variable or tag?

Share this post


Link to post
Share on other sites
I am not sure what it is that doesnt work for you.In SCL you can most definitely write AnalogInputs[x].Rvalue (maybe it has to be AI.Inputs[x].Rvalue)and then manipulate the x value to your hearts content. "x" can be a locally declared variable, or it can be a Merker or DB variable. If it is the latter, you can write to the variable at the end of the program scan. And that can be from any block, not just an SCL block. Try to provide an example on what you want to do but cannot get to work.

Share this post


Link to post
Share on other sites
Here is an example of what I want to do. The system I am making is going to be a "standard" design and will be duplicated many times, so the hardware will always be the same but the Inputs to the various analog modules will differ, so I use an array that I will call "AnalogInputs.[x]" for each I/O. So AnalogInputs[1] might have a device connected to it, but AnalogInputs[2] may not, so I control whether the input will be On or Off in the array I created. The user can control this from the HMI. Now, if the input is off, I don't want to display it on my main taglist page. In order to do this, I check to see if each input is on or off in my analog array, if it is on, then I transfer all of the necessary data to my taglist display array, if it is not then I simply skip it. In RSLogix 5000 I did this like this. SIZE(AnalogInputs, 0, TagListSize); // Gets the size of my analog input array ii:=0; FOR i:=0 to (TagListSize-1) DO If (AnalogInputs[i].OnOff) Then // skip input if turned off TagListData[ii].Description.LEN := AnalogInputs[i].Description.LEN; // If "on" get the length of the text TagListData[ii].Units.LEN := AnalogInputs[i].Units.LEN; // based information TagListData[ii].TagNumber.LEN := AnalogInputs[i].TagNumber.LEN; cop(AnalogInputs[i].Description.DATA[0],TagListData[ii].Description.DATA[0],81); //then copy the data cop(AnalogInputs[i].Units.DATA[0],TagListData[ii].Units.DATA[0],81); // for the input name, cop(AnalogInputs[i].Tagnumber.DATA[0],TagListData[ii].Tagnumber.DATA[0],81); // units and tagnumber TagListData[ii].Value := AnalogInputs[i].RValue; // into the taglist data TagListData[ii].ChannelStatus := AnalogInputs[i].ChannelStatus; // array TagListData[ii].DataType := 0; ii:=ii+1; End_if; End_for; I am having a tough time duplicating something like the above code. It seems that every time I add my [x] that S7 has a problem and does not recognize it as a variable. Using the above code, let say this machine will only have devices connected to analog inputs 1, 3, and 7. What will happen is the analog input array will look like this AnalogInput[1] = On AnalogInput[2] = Off AnalogInput[3] = On AnalogInput[4] = Off AnalogInput[5] = Off AnalogInput[6] = Off AnalogInput[7] = On But the taglistdata array will now look like this TaglistData1 = AnalogInput[1] TaglistData2 = AnalogInput[3] TaglistData3 = AnalogInput[7] Now I will have HMI screens that display Taglistdata 1-x and will not display any inputs that are turned off. This way, the user can also add I/O, and turn it "on" from the HMI, and suddenly have a new input displayed on the HMI without having to do anything from the S7 software. The only reason why I do this is because the I/O will be changing, but the PLC is going to be a standard hardware design with a standard program that can be modified from the HMI to fit many different needs. This would of course be much easier if I had set I/O, but making the program flexible makes things much tougher.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0