scalling issues

Yes I like the code, after I changed the PLC parameters latch range it worked without problems I even tried it on a real FX3U & worked great, here is the modified in pdf All I have done is replaced the M10 with M8000 & removed M9.
The bee's knees. Just three branches for each binary search step is so tight: this is why I like Ladder, even though I know ST would be arguably better (e.g. those search steps could be implemented in a 6-count loop).

Even though the D> and the DMOV instructions show the integer value of the 32-bits, instead of their floating-point value, this way is so much cleaner.

Really sweet, thanks again!
 
Hi Brian, yes ST or FBD is certainly the way to go, you will find some oddities.
IN ST the Z registers are difficult to use but as it's structured rather than use them directly you create arrays for example the voltage table would be Voltage_table Array[0..49] of float & assign it to D100, when used in FBD or ST then you do not need to worry about the physical address as it knows, also rather than having to remember to increment the pointer by 2 the compiler knows it's working on floats so Voltage_Table[0] is D100-D101
Voltage_Table[1] is D102 & so on in actusl fact the compiled code uses the Z registers but automatically increments them by 2.
The other thing is the symbols unlike Ladder in a simple project cannot have spaces or reserved words so "My Float" needs to be "My_Float" also words like STOP cannot be used as it's a reserved word you have to modify it to something like E_Stop or what ever, It also makes sense if you start typing in an already created symbol then it gives you a list so you don't use the absolute address, some variables can be automatically assigned a physical address using the reserved area but you never know what that physical address is as it can change every compile although hovering over it shows the address.
Happy coding
 
I understand you guys are just fooling around but you used almost 100 floats (47 pairs?) and a binary search to find the right value.

You could have just used 160 floats instead in a one-dimensional array and picked the values without any searching. It would have been more efficient with less code and faster execution and would produce the exact same end result.

Just saying :)
 
Here you go Brian, your progrm in ST using a structured project with labels ...
I told you ladder is beautiful, even more so by comparison. And shouldn't that be a loop i.e.
Code:
...;
Offset = 32;
REPEAT
  Ptr1 := Offset + Ptr0;
  IF Ptr1 < Len_Table AND Volt > Vtable[Ptr1] THEN Ptr0 := Ptr1; END_IF;
  Ptr1 := SHR(Ptr1, 1);
UNTIL Offset < 1 END_REPEAT;
...;
 
I understand you guys are just fooling around but you used almost 100 floats (47 pairs?) and a binary search to find the right value.

You could have just used 160 floats instead in a one-dimensional array and picked the values without any searching. It would have been more efficient with less code and faster execution and would produce the exact same end result.

Just saying :)
Yes, definitely fooling around e.g. doing this in Ladder is silly of course. And eighty responses in the thread would an embarrassment if not for the exercise.

And yes, we thought of that; not bit-for-bit exact of course, but soytenly close enough.

Also, @parky already went a step beyond even that with 801 floats to use a direct lookup for the nearest 0.01V, so it's even more efficient as it eliminated the in-PLC interpolation step entirely.

Memory and CPU are cheap, so there is no one best way out of many to skin this cat.
 
lol, Offset is not in the ST instuctions, no need for a loop anyway.
And I can display all the code on screen unlike ladder with awful symbol descriptions in green with plenty of comments that don't expand the ladder length.
Also don't have to think about actual addesses and what they are just type in the name.
 
Where does the 160 floats come from ? there are possibly 1000 actual values but they are not linear
We only use 100 although there is a sort of itteration but no loop
It's actually 161.

They are suggesting doing essentially the same thing as your 801-element table, but at 0.05V increments, using the integer (value = int((Volt - 2.00) / 0.05) to find the lo element of the interval lo-hi pair, and then doing the interpolation on that hi-lo pair, instead of doing a zero-order "interpolation" accurate to 0.005V like you did.

six of one ...
 
Yeah but not really going to help I even think 0.01 is poor in reality. a little more processor time is nothing. I have just done one that is even smaller code but using a loop, the scan time is 6ms but I bet most of that is taken up with other things so not worth loosing the accuracy for a couple of ms on a brick PLC, could even do it in interupts in portions.
 
Yeah but not really going to help I even think 0.01 is poor in reality. a little more processor time is nothing. I have just done one that is even smaller code but using a loop, the scan time is 6ms but I bet most of that is taken up with other things so not worth loosing the accuracy for a couple of ms on a brick PLC, could even do it in interupts in portions.
Of course it helps when you interpolate. You get more than 0.01 resolution.

So you recalculate the original table to 161 values with 0.05V steps and put that in an array in the PLC.

Then you do
Code:
z = (volt-2) / 0.05;
value = array[int(z)] * (1+int(z)-z) + array[int(z)+1] * (z-int(z));
 
It will work, because they use the voltage to identify the interval in one calculation step, instead of the six comparisons of the binary search, then linearly interpolate within that interval.

It's a good method for linear to "something else" conversions in PLCs and wherever speed matters (like embedded systems).

For general linearization applications I like to use 101 values, corresponding to 0 - 100%.

Anyway, I've used this method many times. Exactly what order to do the calculations in would be implementation specific.
I used a weighted average for interpolation in the example above.
 

Similar Topics

Hi Guys I'm using Vijeo Designer as HMI, and we're monitoring the water levels in a water well of 6 meters deep. I created the water well in...
0
Replies
2,211
Views
Hello friends; I am new with Mitsubishi system. I need some example to handle the 4-20mA by using FX-2n-4AD which is attached with FX-1N-14M...
5
Replies
4,468
Views
Dear All; Good day. I have a flow meter range 5-70 Cm/hr and out is 4 to 20 mA. first i want to ask how i calculate that at 13 mA what is flow...
2
Replies
2,211
Views
Hi All I am doing a Tank Gauging project. In there all the tank parameter like level , temperature , pressure are coming into a master...
11
Replies
4,965
Views
i'm a newer in PLC programming... anyone please help me about how to do analog scalling in PLC, please sent me an example the ladder for this...
2
Replies
3,831
Views
Top