EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
<== Date ==> <== Thread ==>

Subject: Re: scalcout and calc yielding different results
From: "Marco A. Barra Montevechi Filho via Tech-talk" <tech-talk at aps.anl.gov>
To: "Mooney, Tim M." <mooney at anl.gov>, "tech-talk at aps.anl.gov" <tech-talk at aps.anl.gov>
Date: Wed, 13 Sep 2023 14:55:00 +0000
Thanks for the hint, Tim!

I did this and still got different results. The final workaround was to make a calc record get the value from CURRENT and pass a simplified value to scalcout, which decided which engineering unit to use:

record(ai, "CURRENT"){}


record(calc, "CALC") {

    field(INPA, "CURRENT CP")
    field(B, "1e-12")
    field(C, "1e-9")
    field(D, "1e-6")
    field(E, "1e-3")

    field(CALC, "F:=ABS(A);F<C?1:(F<D?2:(F<E?3:4))")
    field(PREC, "4")

    field(PINI, "YES")
    field(SCAN, "Passive")
}

record(calc, "CALC2"){

field(INPA, "CURRENT CP")

field(B, "1e-9")
field(BB, "pA")

field(C, "1e-6")
field(CC, "nA")

field(D, "1e-3")
field(DD, "uA")

field(E, "1")
field(EE, "mA")

field(CALC, "A:=ABS(A);A<B?1:(A<C?2:(A<D?3:4))")

field(PINI, "YES")
field(SCAN, "Passive")

}

record(scalcout, "CURRENTSCALEDUNIT"){

field(INPA, "CALC2 CP")

field(B, "1e-9")
field(BB, "pA")

field(C, "1e-6")
field(CC, "nA")

field(D, "1e-3")
field(DD, "uA")

field(E, "1")
field(EE, "mA")

field(CALC, "A:=ABS(A);A=1?BB:(A=2?CC:(A=3?DD:EE))")

field(OUT, "CURRENTSCALED.EGU")
field(OOPT, "Every Time")

field(PINI, "YES")
field(SCAN, "Passive")

}

record(calc, "CURRENTSCALED"){

field(INPA, "15")
field(CALC, "A")

field(PINI, "YES")
field(SCAN, "Passive")

}

Doesnt feel elegant, but it works...

From: Mooney, Tim M. <mooney at anl.gov>
Sent: 12 September 2023 18:49
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>; Marco A. Barra Montevechi Filho <marco.filho at lnls.br>
Subject: Re: scalcout and calc yielding different results
 
Hi Marko,

That's not the way you initialize the value of a scalcout-record input field.
Instead of 'field(INPB, "1e-9")', you want 'field(B, "1e-9")' and so on.

Tim Mooney (mooney at anl.gov) (630)252-5417
Beamline Controls Group (www.aps.anl.gov)
Advanced Photon Source, Argonne National Lab


From: Tech-talk <tech-talk-bounces at aps.anl.gov> on behalf of Marco A. Barra Montevechi Filho via Tech-talk <tech-talk at aps.anl.gov>
Sent: Tuesday, September 12, 2023 3:53 PM
To: tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: scalcout and calc yielding different results
 
Hi all. I happened to bump into an interesting problem. Im using calc and scalcout records to translate a very small current measurement into a more convenient unit of measurement.

After having trouble with the software showing the wrong measurement unit, i came to the conclusion that  for some reason, although calc and scalcout are both double types, they seem to have different precision for comparisons.

I have the following example, made to get a very small amount of current in Amps and decide to either display it in pA, nA, uA, etc.:

record(ai, "CURRENT"){}

record(calc, "CALC") {

    field(INPA, "CURRENT CP")
    field(INPB, "1e-12")
    field(INPC, "1e-9")
    field(INPD, "1e-6")
    field(INPE, "1e-3")

    field(CALC, "F:=ABS(A);F<C?1:(F<D?2:(F<E?3:4))")
    field(PREC, "4")

    field(PINI, "YES")
    field(SCAN, "Passive")
}

record(scalcout, "CURRENTSCALEDUNIT"){

field(INPA, "CURRENT CP")
field(PREC, "15")
field(INPB, "1e-9")
field(BB, "pA")

field(INPC, "1e-6")
field(CC, "nA")

field(INPD, "1e-3")
field(DD, "uA")

field(INPE, "1")
field(EE, "mA")

field(CALC, "A:=ABS(A);A<B?BB:(A<C?CC:(A<D?DD:EE))")

field(OUT, "CURRENTSCALED.EGU")
field(OOPT, "Every Time")

field(PINI, "YES")
field(SCAN, "Passive")

}

record(calc, "CURRENTSCALED"){

field(INPA, "15")
field(CALC, "A")

field(PINI, "YES")
field(SCAN, "Passive")

}

However, if you caput CURRENT 9.94e-10 you will see CURRENTSCALEDUNIT.SVAL=nA and CALC.VAL=1, meaning that for the calc record, 9.94e-10<1e-09 is True but for the scalcout this is false.

Is this expected?

Thanks,

Marco

Aviso Legal: Esta mensagem e seus anexos podem conter informações confidenciais e/ou de uso restrito. Observe atentamente seu conteúdo e considere eventual consulta ao remetente antes de copiá-la, divulgá-la ou distribuí-la. Se você recebeu esta mensagem por engano, por favor avise o remetente e apague-a imediatamente.

Disclaimer: This email and its attachments may contain confidential and/or privileged information. Observe its content carefully and consider possible querying to the sender before copying, disclosing or distributing it. If you have received this email by mistake, please notify the sender and delete it immediately.


References:
scalcout and calc yielding different results Marco A. Barra Montevechi Filho via Tech-talk
Re: scalcout and calc yielding different results Mooney, Tim M. via Tech-talk

Navigate by Date:
Prev: CA Client program throwed "pthread_create error" wzhy via Tech-talk
Next: how to configure compiler version timesir via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
Navigate by Thread:
Prev: Re: scalcout and calc yielding different results Mooney, Tim M. via Tech-talk
Next: CA Client program throwed "pthread_create error" wzhy via Tech-talk
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  <20232024 
ANJ, 13 Sep 2023 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·