scalling issues

Here it is for an FX2N/FX2NC with its particular floating-point instructions. It works; like I said, that is an implementation detail.

Caveats
  • The D> D300 D100Z1 in the six binary rungs should be DECMP D300 D100Z1 M7(being careful to avoid M10!),
    • but then I would have had to fiddle around with M9, and I am a lazy sod,
    • Anyway, D> ...is functionally equivalent,
      • as long as all the floating-point table entries are non-negative,
        • because exponent bits are more significant than mantissa bits.
  • The DMOV D200Z0 D308 could be DEADD D200Z0 K0 D308 to show the floating-point value, but it moves the bits either way.
i have try the program but its has some flaw to it....the D300 is the input value of the scale voltage right? I assign the D300 to the voltage scale and its goes error....i think because its overlapping with the input data in the register.....this is my theory idk its right or wrong.....need your feedback....

p/s :: I don't know anything...im just a baby
 

Attachments

  • binary search 2.png
    binary search 2.png
    11.4 KB · Views: 6
  • binary search 3.png
    binary search 3.png
    9.6 KB · Views: 6
  • binary search 1.png
    binary search 1.png
    9.2 KB · Views: 5
I have modified @parky torr calculator....i make it to output 2 decimal point value and addressing the power point for each register....so i use two D register to output the value in the hmi....

p/s :: I don't know anything...im just a baby
 

Attachments

  • torr calculator 3.png
    torr calculator 3.png
    20.3 KB · Views: 5
Brian, there is another problem with your code, It's fine when you first download it, then if you stop the PLC (well the simulator i.e. switch it to stop) then back to run it all goes belly up the returned values are not correct.
I'm not sure what you mean about making it 2 decimal places, If you mean display the torr value on the HMI to 2 decimal places you should not have to do anything apart from the HMI setting for that field set it to 2 decimal places.
 
i have try the program but its has some flaw to it....the D300 is the input value of the scale voltage right? I assign the D300 to the voltage scale and its goes error....i think because its overlapping with the input data in the register.....this is my theory idk its right or wrong.....need your feedback....

p/s :: I don't know anything...im just a baby

There is no flaw, the code is correct. This is only a minor, somewhat confusing, inconsistency in how the bits are displayed in Gx Work 2 online mode.

TL;DR

The D> instruction compares two 32-bit signed integer values, and even though memory references D300 and D100Z1 both point to 32-bit single-precision floating-point values, the result of the comparison will be correct because of the nature of the IEEE-754 single-precision floating-point representation.
  • (D300,D301) comprises 32-bits
  • Those 32-bits in (D300,D301)
    • represent an integer decimal value of 1092576870 when those 32-bits are interpreted (and displayed) as a signed integer value
      • as they are in the first of your images: 1733489283126.png
        • because the D> instruction interprets 32-bit (DN,DN+1) registers as integers,
  • But those SAME32 bits in (D300,D301)
    • represent a floating-point decimal value of 9.9625* when those SAME 32-bits are interpreted and displayedas an IEEE-754 single-precision floating-point value
      • as they are in the second of your images: 1733489325416.png
        • because the DESUB instruction interprets 32-bit (DN,DN+1) registers as floating-point,
The point here is that the bits are the same in all cases; the only issue is how those bits are displayed by Gx Works 2 online mode.

* or 9.960, since the bits changed between when the first and second images were captured

The first attached image shows that the 32-bit integer 1092576870 in decimal is equivalent to 0x411f666 hexadecimal,

The second attached image shows that the 32-bits of that 0x411f666 hexadecimal (=1092576870 decimal) value represent 9.9625 when interpreted as an IEEE-754 single-precision floating-point value.
 

Attachments

  • 1733490239196.png
    1733490239196.png
    72.5 KB · Views: 2
  • 1733490278112.png
    1733490278112.png
    78.9 KB · Views: 2
Nice one Brian, how about more comments also when printing remove the cross ref etc. it distracts from the code.
I am still trying to get my sea legs navigating around GxW2!

Where do I add comments to the rungs? Are those "Statements" or "Notes?"

And what part is the cross-reference?

And do you have a bet with other forum members about how many more posts you can get my OCD to add to this thread :ROFLMAO: ?
 
Brian, there is another problem with your code, It's fine when you first download it, then if you stop the PLC (well the simulator i.e. switch it to stop) then back to run it all goes belly up the returned values are not correct.
You have to [Onlinine]=>[Write to PLC]=>[Device memory {✔}]=>[Execute] to reload the memory (I have to do that every time I start the simulator as well). Is there a better way to handle this? Why doesn't GxW2 download the memory to begin with?
 
Why doesn't GxW2 download the memory to begin with?

In my experience, most PLC manufacturers don't download memory automatically. Probably the reason most programmers prefer online edits with AB.

At very least, the many Japanese PLCs I've dealt with, the memory transfers are a separate function.

You have to [Onlinine]=>[Write to PLC]=>[Device memory {✔}]=>[Execute] to reload the memory

I don't remember this. This looks like an added function since I've used GXW2 last. Maybe 8 years ago.
 
Everything is fixed. The logic was correct before, so it is still the same functionally, but I refactored to use DECMP instead of D>, and DEADD instead of DMOV, to manipulate GxW2 Online mode into displaying floating-point values instead of integers apropo the meanings of the 32-bit D registers being manipulated.

I haven't the patience to get [Print...] to do what I want, so I am attaching images of the relevant rungs instead, , plus a .ZIP archive with the project file
  1. Initialization rung
  2. Binary search rung
    1. repeated six times,
    2. with step sizes of 64 (32 table elements from bottom to top of step) down to 2 (1 table element from bottom to top of step)
  3. Intermediate calculation rung
    1. → differences (Volt-Vlo; Phi-Plo; Vhi-Vlo) in preparation for final calculation in next rung
    2. "Measured" voltage (D300) value of 9.955V is in range of last interval of table between 9.95V (D100Z0 = D190) and 10.00V (D100Z1 = D192)
  4. Final calculation rung
    1. → interpolated pressure from those differences in the final step
    2. Also calculation of µTorr (microTorr) so more digits are shown for lower pressures.
      1. Another way to do this would be to multiply all values from the table's Torr column by 106
  5. ZIP archive with .gxw project file
    1. I extended the Latch Start/End from D100 to D401,
      1. so the Simulator can toggle between RUN and STOP mode without losing anything,
        1. but the Device data must still be written when the simulator is initially started;
          1. I assume it would be the same with a physical FX CPU PLC?
 

Attachments

  • 1733501801903.png
    1733501801903.png
    33.2 KB · Views: 3
  • FX_binary_search.zip
    177.9 KB · Views: 0
  • 1733501931804.png
    1733501931804.png
    34.4 KB · Views: 3
  • 1733501892881.png
    1733501892881.png
    36.7 KB · Views: 3
  • 1733501839412.png
    1733501839412.png
    31.4 KB · Views: 4
So many questions to answer.
I know you have to download the registers, it was that just putting the simulator in stop should not reset the registers.
To get rid of the cross ref to the right when you print there are tick boxes to decide what to print GX in ladder mode is not very intuitive when trying to set up the print, so it takes a little patience to get it right.
The rung comments if you click on these buttons it puts it in comment editor mode depending if you are doing I/O, rung etc. if you click the balloon button it brings up the comments etc. in plc etc.
TBH try in FBD/LAD it is far better you can add comments all over the place, it displays the memory tags as symbols so as soon as you type the first letter it brings up the tag no need to worry about actual registers you can edit in the global label before hand i.e. symbol & then add the type & physical address
or if you just add a symbol name in the field above the contact or register field then it brings up a box with either local or global labels settings locals only allow access within the local block globals can be accessed by all programs it also gives you a list of ones already configured also you can display not only the symbol but also the actual register/bit. another thing if you do not give it a physical address at compile time it automatically allocates the address from the reserved area but there are drawbacks these cannot be accessed by external equipment like HMI etc. The local variables are useful as although they are not destroyed on exiting the block they can be re-used so in effect very handy for interim things like a maths result wherethe result is used on further logic.
I have not had time to look indepth of your code but it could be that those variables are being reset on a stop, however, I think they do not only on power up but I will check.
By the way what is M9 for ? loads of duplicate outs & no contacts also why M10 Use M8000 always on

1733512669678.png
 
Here you are Brian It works properly now in the simulator it does appear that the registers no in latch area do rest on a stop, I don't normally notice it as on a real FX3U plc you can write during run so I set the PLC D registers to 0-511 retentive. I also removed all those M9's & replaced M10 with M8000 also changed the comment to 2x 8 instead of 4x 8 as this reduces the expansion of the rungs but does limit the amount of chars for a symbol
 

Attachments

  • FX_binary_searchV2.zip
    178.8 KB · Views: 2
Here you are Brian It works properly now in the simulator ...
It was already working properly in the simulator as of Post #71.

I have the trial version (1.600A) and cannot open your FX_binary_searchV2.gxw.

I made more cosmetic changes (e.g. M8k; 1x8 Device Comments - thanks for that tip!); see the file attached to this post.

The Coil on M9 seemed to be necessary at the time because I could not get this branch logic
  • ---[< Z1 K402]---[D> D300 D100Z1]---[MOV Z1 Z0]
to compile, but now it seems to work fine. Anyway, that [D> ...] logic is now moot because I switched to using the DECMP instruction, so the floating-point value of the 32 bits of D300 is now displayed (in online mode) instead of the decimal integer value for the same bits.
 

Attachments

  • FX_binary_search.zip
    177.9 KB · Views: 1
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.
 

Attachments

  • FX Binary Search Modified.pdf
    102.8 KB · Views: 5

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