Analog Sgnals in CodeSys V3

Luigi
2017-12-12
2017-12-24
  • Luigi - 2017-12-12

    Can anyone tell me if Codesys V3 has the ability for scaling and unscaling analog signals? Do anyone have a good example for working within CodeSys with analog signals as newbie? In TIA Portal we have function blocks, do CodeSys also have one?

     
  • Lo5tNet - 2017-12-12

    There are a lot of function blocks out there. A standard one is LIN_TRAFO but has some downfalls in my opinion. A good starting point none the less. For an example I would look in the help. If you go to Help-Index and search LIN_TRAFO it will give you everything you need to know. You can just map your inputs and scale values and you are set.

     
  • nothinrandom - 2017-12-13

    You can certainly write your own scaling function...assuming you just started Codesys:

    Create a function block and give it a name called Scale. Copy this part to the top

    FUNCTION_BLOCK Scale
    VAR_INPUT
    xEN : BOOL; ( enable )
    diInput : DINT; ( raw digital input )
    diInputMin : DINT; ( minimum value expected )
    diInputMax : DINT; ( maximum value expected )
    diOutputMin : DINT; ( minimum scaled output )
    diOutputMax : DINT; ( maximum scaled output )
    END_VAR
    VAR_OUTPUT
    xENO : BOOL; ( running )
    diScaledOutput : DINT; ( scaled output )
    END_VAR

    Now copy this part to the bottom half of screen

    diScaledOutput := (diInput-diInputMin)*(diOutputMax-diOutputMin)/(diInputMax-diInputMin)+ diOutputMin;

    For example your analog sensor reads 8000 (assuming some range between 0 and 32767), and this range represents a temperature value of 0 to 100 *C. You should set up your function block, where:
    diInput is whatever raw value you have
    diInputMin is 0
    diInputMax is 32767
    diOutputMin is 0
    diOutputMax is 100
    diScaledOutput should yield 24

    If you need decimal point, then multiply all inputs by 10, then divide by 10 at the very end and change your output from DINT to REAL

     
    πŸ‘
    1
  • Luigi - 2017-12-24

    Thank you for your explanation

     

Log in to post a comment.