JeffreyK, Darkhan
Overview
We found that some of the calculations in the recently implemented CAL_CS front-end model (see LHO alog #20360) do not produce expected results. We found this problem in the division block that takes input of significantly smaller number for denominator vs. number in the nominator.
Since this calculation is done on quantities that should change only as a result of manual input we've decided to calculate these quantities in Matlab and then export final results to EPICS. Tomorrow we will add these EPICS inputs into CAL_CS front-end model.
Details
In this section we show how this bug was identified.
Following EPICS input channels exist in the CAL_CS front-end model: REF_A_TST_REAL and REF_A_TST_IMAG. They form a complex quantity Atst = Re{ Atst } + i * Im{ Atst } = REF_A_TST_REAL + i * REF_A_TST_IMAG.
We wanted to calculate Re{ -1/Atst } and Im{ -1/Atst } as
| Atst |2 = Re{ Atst }2 + Im{ Atst }2
Re{ -1/Atst } = - Re{ Atst } / | Atst |2
Im{ -1/Atst } = Im{ Atst } / | Atst |2
When we provided both inputs (real and imaginary) with quantities their values, the quantity | Atst |2 came out to be about right, but the final values Re{ -1/Atst } and Im{ -1/Atst } were off by several orders of magnitude.
The finals values should have been
Re{ -1/Atst } = 1.39199e+16
Re{ -1/Atst } = -1.14388e+16
We don't know for sure, but it might be possible to avoid this bug by trying rearrange signals in simulink design (e.g. replace division by multiplication by inverse of the quantity or maybe some other way).
For this case we decided to calculate these final quantities in Matlab and into EPICS only final results.
Looks to me that the FE prevents divide-by-zero errors by limiting the denominator to 1E-20.