Codesys#Let’s Use the Util.LIN_TRAFO function to linearly transform signals!

This article uses Berghof’s B-Nimis MC-Pi Plus Controller with the LIN_TRAFO Function Block from Codesys’ Util library to perform linear conversion of analogue signals. The analog signal is converted linearly.

Come on, let’s enjoy FA.

Reference Link

Codesys#Let’s Use the Util.BLINK and Trace function!

Foreword

Thank you from the bottom of my heart for visiting my technical blog and YouTube channel.

We are currently running the “Takahashi Chris” radio show with Full-san (full@桜 八重 (@fulhause) / X) which I deliver every Wednesday night.

Sharing, not hoarding, technical knowledge

We publish technical information related to factory production technology and control systems for free, through blogs and videos.

With the belief that “knowledge should be accessible to everyone,” we share practical know-how and real-world troubleshooting cases from our own field experience.

The reason we keep it all free is simple: to help reduce the number of people who struggle because they simply didn’t know.

If you’ve ever thought:

  • “Will this PLC and device combination actually work?”
  • “I’m having trouble with EtherCAT communication—can someone test it?”
  • “I want to try this remote I/O, but we don’t have the testing environment in-house…”

Feel free to reach out!If lending equipment or sharing your configuration is possible, we’re happy to verify it and share the results through articles and videos.

(We can keep company/product names anonymous if requested.)

How can you support us?

Currently, our activities are nearly all unpaid, but creating articles and videos takes time and a proper testing environment.If you’d like to support us in continuing and expanding this content, your kind help would mean a lot.

Membership (Support our radio show)

This support plan is designed to enhance radio with Mr Full.

https://note.com/fulhause/membership/join

Amazon Gift List (equipment & books for content production)

Lists equipment and books required for content creation.

https://www.amazon.co.jp/hz/wishlist/ls/H7W3RRD7C5QG?ref_=wl_share

Patreon (Support articles & video creation)

Your small monthly support will help to improve the environment for writing and verifying articles.

https://www.patreon.com/user?u=84249391

Just trying to share things that could’ve helped someone—if only they’d known.

Your support helps make knowledge sharing more open and sustainable.

Thank you for being with us.

soup01threes*gmail.com

https://x.com/3threes2

Technical knowledge shouldn’t be kept to ourselves.

Util.LIN_TRAFO

With Util.LIN_TRAFO, a linear transformation can be performed. The transformation also results in a linear approximation of the output value using the minimum and maximum values of the input.

For example, temperature sensors provide input values, which are converted into temperature values in degrees Celsius (output OUT). The range of its input values is defined by IN_MIN=0 and IN_MAX=10. The range of output (Celsius) values is defined by OUT_MIN=20 and OUT_MAX=40. Thus, for a 5 V input, the temperature in degrees Celsius converts to 10 degrees Celsius.

VAR_INPUT

INREALlogical input value
IN_MINREALMinimum input value
IN_MAXREALMaximum input value
OUT_MINREALMinimum output value
OUT_MAXREALMaximum output value

VAR_OUTPUT

OUTREALoutput (data) value
ERRORBOOLTRUE: IN_MIN = IN_MAX or IN is out of input range

Implementation

Add library

Add the library from the Library Manager.

Click Add Library.

Add the Util library.

Program

We will also use LD2 in this article: add the Block from the Toolbox to Rung1.

Add Util.LIN_TRAFO

An Empty Block like number has been added on the Editor.

Enter Util.LIN_TRAFO at ?.

Done!Util.LIN_TRAFO Block has been added.

Next, on the FB of the Util.LIN_TRAFO, click ?? and select the Util.LIN_TRAFO instance defined in the VAR area.

Done!

Finally, assign all parameters to variables.

Add ST Block

You can also execute ST code directly in the LD2 programme: add the ST Block to the Toolbar to the Rung of Empty.

Done!

Next, click on Empty Rung, which you have just added.

The Text Editor appears, so write your ST code in this area.

Done!

Result

The function Util.LIN_TRAFO could be executed without error, and Out can be Scaled according to the input values of rSensorIN.

The waveforms of the data transformation can also be viewed in Trace.

シェアする

  • このエントリーをはてなブックマークに追加

フォローする