mitryan

Q02H Analog Signal scaling GX Works 2

12 posts in this topic

Hi, i'm pretty new to the programming environment of the GX works 2 and i would like to do scaling of my analog signal from Q64AD module. The signal is 4-20mA and the range of i would like to have 0-100PSI, i can't seem to find any scaling on the manual.

Share this post


Link to post
Share on other sites

You will scale with math instructions in the CPU.  The module offers a couple input resolutions. 

Q64ADN (newer version) if I recall had a user configurable range.

1 person likes this

Share this post


Link to post
Share on other sites

 I believe, that he is looking for the SCL instruction.

As i recall, this function is not supported by Q00 and Q00J PLCs.

This is why i ask for the main cpu model...

 

 

Share this post


Link to post
Share on other sites

SCL is useful for creating a scale which is non-linear.  It's a bit complex if all you need to do is convert 0-4000 into 0-100.  Math is far easier.

As I mentioned, some of the newer cards have a user selectable range so it can be done in the card before the program ever sees it.

2 people like this

Share this post


Link to post
Share on other sites

i remember missing so much this function while trying to do taper tention on a winder... stuck with one FX3G.:kewl:

Share this post


Link to post
Share on other sites

hmmmm... i am not impressed how easily people get "stuck".:shrug:

this is a very common and straight forward task. it is easy to do on any platform using nothing but high school math. in tend to roll my own functions because i don't like incompatibilities that specialized instructions bring. this way i don't care what the target platform is. just quickly adapt library and my programs will run on any controller. 

there are different ways to go about this, depending on specific application needs, or computational optimization but assuming one wants generic universal scaling with parameters and without clipping, one may proceed as follows:

assuming input signal and domain are:
in
in_low
in_hi

and output signal and range are:
out 
out_low
out_hi


and knowing basic linear equation in intercept form
y=mx+b

one can write following:

intercept is
b=out_lo 

for line, slope is simply change of Y over change of X
m=(y2-y1)/(x2-x1)

or if use range and domain 
m=(out_hi-out_lo)/(in_hi-in_low)

but can also be expressed relative to "in" and "out":
m=(out-out_low)/(in-in_low) 

the only thing left is to combine everything and you get the universal linear scaling formula where domain and range can be simple to parametrize.

rearrange last equation from:
m=(out-out_low)/(in-in_low) 
to
(in-in_low)*m=(out-out_low) 

then substitute in previous m expression to get:
(in-in_low)*(out_hi-out_lo)/(in_hi-in_low)=(out-out_low) 

and finally isolate "out" to get: 
out = (in-in_low)*(out_hi-out_lo)/(in_hi-in_low) + out_low

and that's it... universal formula for linear scaling with parameters.

now you can use PLC of your choice to implement that equation. and this is easy because equation only uses basic math operations which are available on every controller.

if clipping of output is also required, simply check if scaled output is in range. if range is exceeded trim the value to range limits.

5d47b185aaa0e_LinearScaling.thumb.jpg.70

2 people like this

Share this post


Link to post
Share on other sites
2 minutes ago, panic mode said:

hmmmm... i am not impressed how easily people get "stuck".:shrug:

this is a very common and straight forward task. it is easy to do on any platform using nothing but high school math. in tend to roll my own functions because i don't like incompatibilities that specialized instructions bring. this way i don't care what the target platform is. just quickly adapt library and my programs will run on any controller. 

Dear panic mode,

I'd like to take your attention to a one thing. A calculation using the traditional math equation will give a correct result only for limited range of integers (the subtraction of in_max/in_min and/or out_max/out_min should not give a result outside the range of -32768 - 32767). If it's necessary to operate with a full range of integer values (16-bit AD/DA analog modules), another integer arithmetics should be used, that requires more math operations.

Share this post


Link to post
Share on other sites

Of course, that is why this is generic and not optimal for each and every scenario ( and no solution will be perfect for all cases).

But i also never claimed that this equation must be implemented using integers. This can be implemented in floating point or fixed point format.

The point is than one does not need to feel stuck just because something is not available as s canned and ready to use instruction. Eord programmable  in PLC means things can be done in software. I merely showed the way.

2 people like this

Share this post


Link to post
Share on other sites

Posted (edited)

Yes, for linear scaling basic math is straightforward, but in my case with taper tension you have to spread a curve over winding roll diameter.

With different materials from 1mm thickness cardboard to few microns plastic film the curve range and coordinate points number and location differs drastically.

Add the variety of customer requirements and the nightmare is right there! :)

This is where multi point coordinate SCL function comes in handy big time!

Edited by glavanov

Share this post


Link to post
Share on other sites

Hi already solved, thanks for the replies. The main CPU model is Q02H and the analog module is Q064AD, i did mathematical operations for the scaling that i wanted since no direct scaling instruction is available for gx works 2.

Share this post


Link to post
Share on other sites

Posted (edited)

Why didn't you just download the FB from the mitsubishi site for scaling ?

 

Edited by Gambit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now