There have been a number of posts asking about scaling so I thought this may help.
The formula is:
Out := ((Variable_In - ZeroIn) / (SpanIn - ZeroIn)) * (SpanOut - ZeroOut) + ZeroOut.
The Variable_IN is the raw value i.e. it could be 0-32767 or -32767 to +32767 or even 200 to 2000
or whatever the raw range is
The ZeroIn & SpanIn are the minimum & maximum of the input range as depicted by the analogue card.
SpanIn & SpanOut are the min & max of the scaled output.
Examples:
Raw in 0 to 2000
ZeroIn = 0
Span in = 2000
ZeroOut = -50
SpanOut = +150
See logic version in pic.
Note: you will need to convert integers to reals for the input variable and if required the output if needed to send it to an analogue out card.
This applies to the Zero & spans as well although these could be fixed values.
This will work in both directions doing the math in integer would not produce accurate results.
The formula is:
Out := ((Variable_In - ZeroIn) / (SpanIn - ZeroIn)) * (SpanOut - ZeroOut) + ZeroOut.
The Variable_IN is the raw value i.e. it could be 0-32767 or -32767 to +32767 or even 200 to 2000
or whatever the raw range is
The ZeroIn & SpanIn are the minimum & maximum of the input range as depicted by the analogue card.
SpanIn & SpanOut are the min & max of the scaled output.
Examples:
Raw in 0 to 2000
ZeroIn = 0
Span in = 2000
ZeroOut = -50
SpanOut = +150
See logic version in pic.
Note: you will need to convert integers to reals for the input variable and if required the output if needed to send it to an analogue out card.
This applies to the Zero & spans as well although these could be fixed values.
This will work in both directions doing the math in integer would not produce accurate results.