ChanThien Posted November 2, 2006 Report Posted November 2, 2006 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. Quote
Groo Posted November 2, 2006 Report Posted November 2, 2006 Give an example of what you are doing, what you expect to see and what you are getting. Then perhaps someone can help. Quote
ChanThien Posted November 12, 2006 Author Report Posted November 12, 2006 For example , i wanted to use sqrt( ) function to calculate in my algorithm. So , this function require to operate on real number Quote
jacekd Posted November 13, 2006 Report Posted November 13, 2006 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. Quote
JesperMP Posted November 14, 2006 Report Posted November 14, 2006 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. Quote
ChanThien Posted November 14, 2006 Author Report Posted November 14, 2006 (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 November 14, 2006 by ChanThien Quote
JesperMP Posted November 14, 2006 Report Posted November 14, 2006 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. Quote
varlux Posted November 23, 2006 Report Posted November 23, 2006 ChanThien, it's very important to remember that real numbers (and respective functions) "tired" CPU! It's better to use Integer...... Ciao Quote
JesperMP Posted November 24, 2006 Report Posted November 24, 2006 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. Quote
varlux Posted November 24, 2006 Report Posted November 24, 2006 JesperMP, you're righ I guess that ChanThien uses an HMI. In this case, i prefer it for calculations (to free CPU). Ciao Quote
JesperMP Posted November 24, 2006 Report Posted November 24, 2006 (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 November 24, 2006 by JesperMP Quote
varlux Posted November 24, 2006 Report Posted November 24, 2006 (edited) Many systems can't run without panel...... Edit: Every application has particularity answers, and for this application JesperMP is right. Ciao Edited November 24, 2006 by varlux Quote
ChanThien Posted November 25, 2006 Author Report Posted November 25, 2006 (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 November 25, 2006 by ChanThien Quote
Groo Posted November 28, 2006 Report Posted November 28, 2006 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 Quote
varlux Posted November 28, 2006 Report Posted November 28, 2006 In this case i purpose you to multiply your integers X1000 or X10000. Then, you must divide for the same number. Ciao Quote
JesperMP Posted November 28, 2006 Report Posted November 28, 2006 *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. Quote
varlux Posted November 28, 2006 Report Posted November 28, 2006 Edit: Some case, when it's opportune, I work with INTEGER, and I multiply these values X10 or X100 NO WAY! Quote
TimWilborne Posted November 28, 2006 Report Posted November 28, 2006 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 Quote
JesperMP Posted November 29, 2006 Report Posted November 29, 2006 OK, but to figure out what goes wrong we need to have a look at ChanThiens code. Quote
Spanner Posted February 7, 2007 Report Posted February 7, 2007 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. Quote
Recommended Posts
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.