Issue
- If the result of a divide by zero is sent to a physical AO, Vista Workstation will display this value as -2. The physical output, however, will be sending out the maximum specified voltage (default 10V).
-
In Menta simulation mode, if a divide by zero scenario is simulated, the following error will pop up:
tam32
Division by zero - Connected to a controller viewing live Menta, a divide by zero equation will result in a displayed value of 1.#QNAN. All subsequent equations using this value will also output 1.#QNAN.
Environment
- Xenta programmable controllers
- Xenta 280, 281, 282, 283, 300, 301, 302, 401, 401:B
- Menta
Cause
Division by zero results in an invalid value that is interpreted differently by the controller's physical outputs, the Menta application, and the Vista Workstation. The application will continue to run, but any output affected by the invalid value will not act as expected.
Division by zero is not usually intentional (there's no equation that says "A/0"). Instead, it is usually the result of an unforeseen sequence of events where complex equations result in a 0 in the denominator of an equation, and simulations did not ever produce this unique situation.
Resolution
To troubleshoot whether a divide by zero is occurring:
- The best solution is to connect live to the controller with a serial cable and watch the live Menta. Look for any values that read 1.#QNAN and trace it back to the source.
- If live Menta is no available, the simulation mode can be helpful. Recreate the scenario as best as possible with all inputs set to the real life instance.
To prevent a divide by zero error:
Never allow an equation to write to the denominator of a division equation without programming divide by zero prevention.
- Add an expression block prior to the division equation that says "if the value is zero, then output a safe value"
- Add a max block to the input that compares the value with 0.0001, so that a zero will never pass through.