Dancho Posted January 17, 2020 Report Share Posted January 17, 2020 Good morning and happy Friday to all! I am still learning the ropes of PLCs ladder logic, etc and I am hoping to get some suggestions. I am from the world of traditional code-writing and microcontrollers, so the handling of arrays and datatypes within ladder logic has been a bit of a learning curve. Here's my situation: I am using a 4-20ma signal from a laser to measure the level of a material within a tank. The tank has a rotating arm which periodically passes through the laser beam. To filter this out, I am taking a measurement every .1 seconds and writing it to the 0th element of an array (after shuffling the rest of the values). I am taking the minimum element of that array as the true level at that moment (arm in front of the beam will only make the measurement appear higher, never lower). I am taking the 'true level'/minimum measurements and writing them to another 10 element array every 0.1s, same scheme, shuffling, etc. I have a third 10 element array in order to do calculations on the rate of change from the 0th element to the 1st, 2nd, 3rd, 4th, etc. Essentially I am working to get the volumetric flow out of this tank.... The issue I'm having is that I am getting only whole numbers, and non-negative numbers. The order of magnitude and precision should be X.XX. I am only getting the integer portion, unsurprisingly. I used a formula function block and did my calculations in there. Very handy. Avoided me having to add another function block to divide by 0.1, 0.2, 0.3, 0.4 etc. (Also, that was giving me datatype errors using the MULT function block). I realize I've given a lot of details and not asked any questions directly, so here goes: 1. When is the 'right' time to use real numbers? 2. Given I only need 3 significant digits of precision, should I multiply my values by 100 or 1000 and format it on the HMI to show the decimal place? 3. If I want to know both positive and negative values, should I use multiply by 100 or 1000 AND choose 32768/2 as the zero point? As in, shift the values, so that below 16384 represents a negative volumetric flow? 4. Are there better ways to handle arrays than creating multiple arrays just to store 9 elements, then move them back to the original array, or copying a whole array just to run numeric operations? For example, is there a clever/elegant way to calculate the volumetric flow from the 0th element to the 1st, 2nd, 3rd, so on...getting 9 values and averaging, sorting, etc. to get a less noisy signal? Kindest regards! Quote Link to comment Share on other sites More sharing options...
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.