Sign in to follow this  
Followers 0
ChanThien

How to use real number in Simatic S7

21 posts in this topic

I have tried many times to use real number but i wasn't successful. If anyone know to use it , please tell me!!!!!!!!!!! Thanks for your helps.

Share this post


Link to post
Share on other sites
Give an example of what you are doing, what you expect to see and what you are getting. Then perhaps someone can help.

Share this post


Link to post
Share on other sites
For example , i wanted to use sqrt( ) function to calculate in my algorithm. So , this function require to operate on real number

Share this post


Link to post
Share on other sites
ChanTien, first - in S7 world real numbers are represented acc. to the IEEE 754 standard, this means - among other things - that their size is 32 bits (dword). In Symbol Table or block interface table you can define variable of type REAL. For storing of the real numbers also variables of type dword or dint can be used (however in LAD editor option for checking operands type must be switched off). second - Step7 contains few instructions to convert between DINT and REAL numbers. Tell us which Step7 language you use, so we can show you some examples.

Share this post


Link to post
Share on other sites
Hello ChanThien. You need to learn how to use the online help in STEP7. If you are editing a block, then in the Help menu there will be the following entries: Help on LAD Help on STL Help on FBD. Under each of these you can browse further down to find the desired instruction. Try to follow Floating Point Instructions .. Overview of Floating Point Math instructions and then select Square Root. I recommend that you keep it in LAD or FBD. If you need to know how it looks in STL, then create the code in LAD or FBD and then switch the view to STL.

Share this post


Link to post
Share on other sites
I tried to program on Step 7 5.3 , but when i monitored , it didn't show desired value ( correct number ). I just used simulator to monitor . I entered input value from M register , then convert it to real number ( used function Integer number to Float number). Edited by ChanThien

Share this post


Link to post
Share on other sites
ChanThien. Post your code (STL). If you are using an MD value formatted as a REAL allready, then you do not have to convert it. To sort out what goes wrong, we need to see your code.

Share this post


Link to post
Share on other sites
ChanThien, it's very important to remember that real numbers (and respective functions) "tired" CPU! It's better to use Integer...... Ciao

Share this post


Link to post
Share on other sites
varlux That is a very simplistic way to look at it. He has to do a square root, so as far as I see it there is no better way than using a REAL.

Share this post


Link to post
Share on other sites
JesperMP, you're righ I guess that ChanThien uses an HMI. In this case, i prefer it for calculations (to free CPU). Ciao

Share this post


Link to post
Share on other sites
What if the HMI is disconnected or shutdown. Do you want the proces to stop too ?edit: I think that you should not worry about making a few floating point calculations. Todays S7 PLCs have quite good floating point processing, even the small ones. It is better to do it the simple way, rather than jumping through hoops to try and use INTs in stead of REALs. One thing that you can do is to execute the calculations conditionally in stead of cyclically (this is what I do). Edited by JesperMP

Share this post


Link to post
Share on other sites
Many systems can't run without panel...... Edit: Every application has particularity answers, and for this application JesperMP is right. Ciao Edited by varlux

Share this post


Link to post
Share on other sites
hi, everybody! i proposed this topic with the purpose that using real number on PLC is possible or not. Before, i had made " Automatic Weighing System " . I read analog signal from loadcell , converted into digital and operated caculation on integer. So , when spending caculating many times , error is larger and larger. Therfore , i wanted to use real number to able to reduce error in caculating process. Edited by ChanThien

Share this post


Link to post
Share on other sites
An example of how it can be done // Take an Integer between 0 - 27648 (0-20mA) and change scale to 0 - 500Kg L PIW 500 // Integer weight value ITD // Integer to Double Integer DTR // Double Integer to Floating Point L 5.000000e+002 // Multiply by 500 *R L 2.764800e+004 // Divide by 27648 /R RND // Round to a Double Integer T MW 500 // Value will be between 0-500 so can be stored in single word

Share this post


Link to post
Share on other sites
In this case i purpose you to multiply your integers X1000 or X10000. Then, you must divide for the same number. Ciao

Share this post


Link to post
Share on other sites
*sigh* Please, do not think that I am after you, but this is horrible. You are trying to argue why he should use INTs in stead of REALs. If you multiply with 10000, then you have an original input value range of max -3.. +3. Outside these values you will saturate the calculation after multiplying with 10000. You get similar problems with rounding errors if you try to divide to accomodate large numbers. This problem, and the unnecessary added complexity is a classic example of why it is in most cases faster, simpler, safer, BETTER to use floating points from the outset.

Share this post


Link to post
Share on other sites
Edit: Some case, when it's opportune, I work with INTEGER, and I multiply these values X10 or X100 NO WAY!

Share this post


Link to post
Share on other sites
Will you two make sure ChanThien's question about how to use the reals is solved before you have it out over whether real or integers are better? Thanks TW

Share this post


Link to post
Share on other sites
OK, but to figure out what goes wrong we need to have a look at ChanThiens code.

Share this post


Link to post
Share on other sites
Guys I think we need to see what Values are being read from this test. ChanThien, can you post a screen dump of the Online View of the code where this Incorrect Value being displayed? Also, If you showed us the code it might help matters. I had a similar issue when working with STL working with Doubles, I was testing the code... // Set up Maximum loops L MD 50 T #_max OPN "Logic_Data1" // Open DB50 For Access. // Start processing A M 0.0 // Switch JCN NLp // Loop conditions. Comp: L MD 100 L #_max <I JCN NLp // no Loop L MD 100 // Reload _i // Start Location. LAR1 // Start with Address register 1 LAR2 // Actual String L DBB [AR1,P#68.0] // Load opend db.dbb80.0+_i - _ist byte in Act String T MB [AR2,P#70.0] // Transfer it to byte array L MD 100 + 8 // Increment _i( + 8 bits) T MD 100 JU Comp // Jump to Compare NLp: NOP 0 And had to add the +8 as placing +10 simply added 10 Bits to MD100 instead of Adding 10 to the answer. (3rd Last Line). This Threw me as I thought I would have had to add W#2# before the value to achieve this.

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