Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: jcb on December 03, 2019, 03:56:39 PM

Title: Count (0) out of range in AVGR
Post by: jcb on December 03, 2019, 03:56:39 PM
Why would I get this error? The way I understand it there should be no way for the AVGR to be interpreted if the Count Variable is 0?

I am triggering this on a falling edge diferential inside a stage. This is on the same output rung that jmps the next stage.

V2151 = CountIfNE(0, R151, 98)

R148 = IF(V2151 != 0, AVGR(R151, V2151), 0)

MOVE 0 into V2151

Everything works fine but I hate seeing the warning on the status bar.

Thanks in advance,
John.

Title: Re: Count (0) out of range in AVGR
Post by: franji1 on December 03, 2019, 04:04:18 PM
The MATH instruction performs all branches, so IF(A, B, C) will always evaluate A, B, and C.

However, if you move the IF functionality to Ladder Logic (I like using the NOT contact for IF/THEN/ELSE in Ladder), it will do what you expect (see attachment)
Title: Re: Count (0) out of range in AVGR
Post by: jcb on December 03, 2019, 04:43:50 PM
Fixed.

Thank you.