Conversion of analogue input into Real measurement value

lasrediel
2011-03-23
2011-04-18
  • lasrediel - 2011-03-23

    Good day all,
    i am a new comer in the forum as well as in the world of programming and more specifically with PLC programming.

    I am working actually with a wago 750-841 PLC on wich a Analogue Input module is attach (750-466) . What i am trying to do is to read from the analogue input module port the values from the sensor that will return values (numerical decimal value) according to the analogue module manual from 4096 to 32760 (lower and higher value are underflow and overflow values) as the module read from 4mA to 20 mA with a 16bits measurements.

    I am stuck in the conversion from WORD to REAL. as i want to save(archive) those input data with time stamp and TREND them later on from the archive. I checked the oscat AIN and AIN1 but still confused in how to adapt those library code to my situation.

    forgot to mention am beginning in ST

    All the help is really more then welcom!!!

    Thanks in advance

    Yan

     
  • bllueapple - 2011-03-24

    Hi Yan,

    There's a standard function block in codesys library called LIN_TRAFO which is in REAL. Try that.

     
  • shooter - 2011-03-29

    resolution is only 12 bits not 16 however wago has a 15 bits version if needed more precision.

    bit 1,2,3 are not in the analog world.
    so if you get the word in discard these bits.
    bit 15 is also not used as anaolg value.
    you can divide the word by 8 or roll it etc

    w www.oscat.de w has a good conversion for this.
    look for function AIN

     
  • lasrediel - 2011-03-30

    thanks both for the time you took for answering me. really appreciate.

    Zitat:
    resolution is only 12 bits not 16 however wago has a 15 bits version if needed more precision.
    bit 1,2,3 are not in the analog world.
    so if you get the word in discard these bits.
    bit 15 is also not used as anaolg value.
    you can divide the word by 8 or roll it etc
    http://www.oscat.de has a good conversion for this.
    look for function AIN

    Shooter

    if i got what you said right, dividing the receive value from my analogue input by 8 i shall get the REAL amperes measured value or is it in order to use the AIN oscat function?

    if not can you elaborate a little more, sorry for the incovenience but i am trying to get familiar to the PLC world and ST programming.
    And i can also use some hints on how to use efficiently the oscat function, meaning i can open them as a project and see both var set up and prg. but i must admit i am a little bit lost on how to actually use them to my benefits. sadly got no one to help me with that at work.

    heres the code that i am working on so far. any advice are more then welcom

    PROGRAM prg1
    VAR
       A1: ARRAY [0..30] OF WORD;      (*Declaring array A1 of a size of *)
       k: INT;
       avg: WORD;
    END_VAR
     IF DO1= TRUE THEN     (* those lines are for the purpose of  activating my digital output that control my relay*)
       DO1:= FALSE;
    ELSE
       DO1:= TRUE;
    END_IF
     k:=k+1;
    A1[k]:=%IW12;      (* Array A1[k] is being filled with the value provide by the Analogue input located at the bits adress "%IW12"*)
    

    Regards

    yan

    Standard Data Format AI 750 466.doc [273.5 KiB]

     
  • Rolf-Geisler - 2011-03-30

    Hello Yan,
    there is another way to read analogue inputs. See the download page of http://www.geisler-controls.de and look for the AnalogEA.lib. It provides a function block , which lets you select a input mode (such as 4..20 mA) and the resolution of AD converter. Additionally there is an input to set the range of measured physical values (e.g. the pressure of a hydraulic aggregate). Then it returns straight the physical value.
    Sorry, that documentation is still in German ...
    Maybe, that solves your problem.
    Have success
    Rolf

     
  • lasrediel - 2011-03-31

    Thank you Rolf_Geisler ,

    for the hint, strangely i was able to have the FB_AnalogIn Function block to word and initialise the value, but still not able with oscat, am probably too old

    With the FB_AnalogIn tought, i was able to initialise as per the example provide in the PDF file. of course i initialise the as per the code below i set the RAnalogIn.Ende to 2 but not sure if its ok, as the sensor got two setting (LOW: 0-2A & HIGH 0-5A) and for being able to have a return value i need to set the PAnalogIn.Resolution:=0 , but that according the the software correspond to a 16 bits ADC resolution. and the one i am using iis a 2x 16 bit measurement transmittion and 8 bits status per channel, per prior post shooter notify me that in fact the wago is using in fact 12 bits resolution (a bit confuse)

    var```

    VAR
      AnalogIn   : FB_AnalogIn;  ( FB instance for converting in physics Scheme units )
      wInput AT %IW13 : WORD;  (Input signal, as read by the ADC, the Input signal is define using the bits adress %IW12 )
     PhysWert   : REAL;  ( Physical measurement )
     bError     : BYTE;  ( Error Status Byte of Analogin )
     PAnalogIn  : TADC;  ( Parameter of the FB instance of Analogin )
     RAnalogIn  : TRange;  ( Physical range )
    END_VAR
    ( Set the properties of the AD converter and the signal.
        It may also be made ??variable with initial value
    )
    PAnalogIn.Resolution := 0;     ( 16Bit Resolution )
    PAnalogIn.SignalType := 3;     ( unipolar 0 .. +10 V )
    (  The range of physical measurement variable between 0 and +10 V )
    RAnalogIn.Anfang     :=    0.0; ( phys. initial value)
    RAnalogIn.Ende       := 2; ( phys. end value  )
    ( Analog value process)
    AnalogIn (iwIn    := wInput,     ( wInput is the analogue input )
              isADC   := PAnalogIn,
              isRange := RAnalogIn);
    PhysWert := AnalogIn.qrValue;    ( the actual measured value, in the relevant operation )
    bError   := AnalogIn.qbError;

    ```

     
  • shooter - 2011-03-31

    las rediel the above does not work correct,
    the scale is 4/20 mA not 0..10 volt

    look at the txt of the oscat.de and you can find out how to calc it.

    it does work in 16 bit calcs yes like you do in analogin however it will not be precise.

     
  • Rolf-Geisler - 2011-03-31

    Hello Yan,
    your code seems to be ok (as far, as the sensor and the analogue input speak the same language - Volts or mAmps).
    Setting the RAnalogIn.Ende to 2 converts an analogue signal of 0..10V to 0..2Amps, if you run the sensor in High mode, you will have to set RAnalogIn.Ende to 5.
    For better understanding, I made a quick and dirty translation of used data types and FB_AnalogIn interface (will include it into the download package this weekend). Sorry for my poor English ...
    Hope this will help. Have success
    Rolf

    FB_AnalogIn_English.pdf [22.94 KiB]

     
  • shooter - 2011-04-18

    dividing is not the same as shifting as divide gives something behind the comma, and you should discard it. just shift the shit and save it as a word as you did.

     

Log in to post a comment.