Jump to content

How to use real number in Simatic S7


Recommended Posts

Posted
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.
Posted
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.
Posted (edited)
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
Posted
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.
Posted (edited)
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
Posted (edited)
Many systems can't run without panel...... Edit: Every application has particularity answers, and for this application JesperMP is right. Ciao Edited by varlux
Posted (edited)
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
Posted
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
Posted
*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.
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...