.. _safety_flags:

Safety Flags
============

The safety flags are represented in software by the following enums

.. doxygenenum:: safety_flag

The safety flags can be temporarily or permanent. Some temporary flags are reset automatically, once the error condition disappears. Others have to be explicitly cleared. 
The safety weights (if a flag stops the PID controller, or triggers the panic mode) are configured by default as described below. However, it will be possible to override these weights by
setting config entries in the safety memory.

.. todo:: Change docu of config entires in memory

----------------------------------------------------------------------------------------------------------------------------------

.. _safety_flags_adc_overflow:

ERR_FLAG_MEAS_ADC_OVERFLOW
--------------------------

``ERR_FLAG_MEAS_ADC_OVERFLOW`` is triggered in case of an overflow in the signal path of the measurement ADC. This should never happen unless there is a bug in the software.

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
yes        no            yes           no
========== ============= ============= ===========

----------------------------------------------------------------------------------------------------------------------------------

.. _safety_flags_adc_off:

ERR_FLAG_MEAS_ADC_OFF
---------------------

``ERR_FLAG_MEAS_ADC_OFF`` signals that the measurement ADC for the PT1000 sensor is deactivated. This flag is automatically cleared by the firmware
once the ADC is started.

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
no         yes           yes           no
========== ============= ============= ===========

----------------------------------------------------------------------------------------------------------------------------------

.. _safety_flags_adc_watchdog:

ERR_FLAG_MEAS_ADC_WATCHDOG
--------------------------

``ERR_FLAG_MEAS_ADC_WATCHDOG`` is used as a wire break detection mechanism. This flag is set when the PT1000 measurement ADC detects an invalid resistance measurement.

.. seealso:: :ref:`ADC Watchdog<firmware_meas_adc_watchdog>`

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
no         no            yes           no
========== ============= ============= ===========

----------------------------------------------------------------------------------------------------------------------------------

.. _safety_flags_adc_unstable:

ERR_FLAG_MEAS_ADC_UNSTABLE
--------------------------

``ERR_FLAG_MEAS_ADC_UNSTABLE`` is set if the Moving Average Filter of the PT1000 ADC detects a bigger deviation between input and filtered output value.
The flag is automatically cleared by the controller as soon as the unstable condition is not met anymore. For this, the filter input to filter output difference has to stay below a certain threshold for a defined amount of samples.

.. seealso:: :ref:`firmware_meas_adc_filter`

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
no         yes           no            no
========== ============= ============= ===========


.. _safety_flags_safety_mem_corrupt:

ERR_FLAG_SAFETY_MEM_CORRUPT
---------------------------

``ERR_FLAG_SAFETY_MEM_CORRUPT`` is set during the initialization of the controller, in case a corrupted safety memory is encountered.
In this case the error memory is reinitialized and the flag is set in the error memory. Afer a reboot it will stay asserted until the 
safety backup memory is cleared.

.. seealso:: :ref:`backup_ram`

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
yes        no            yes           no
========== ============= ============= ===========


.. _safety_flags_stack:

ERR_FLAG_STACK
---------------------------

``ERR_FLAG_STACK`` Shutdown of the controller, in case a corrupted safety memory is encountered.
This error is not recoverable and will trigger the panic mode.

.. seealso:: :ref:`safety_stack_checking`

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
yes        no            yes           yes
========== ============= ============= ===========

.. _safety_flags_timing_pid:

ERR_FLAG_TIMING_PID
---------------------------

``ERR_FLAG_TIMING_PID`` is set if the timing monitor of the PID controller detects a violation in the sample frequency.
The flag is recoverable and only shuts down the PID and therefore the oven control output.

.. seealso:: Timing Monitor

========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
no         no            yes           no
========== ============= ============= ===========

.. _safety_flags_overtemp:

ERR_FLAG_OVERTEMP
---------------------------

``ERR_FLAG_OVERTEMP`` is set if the :ref:`pt1000_processing` detects an overtemperature.
The default limit is set to:

.. doxygendefine:: SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC

However, it is possible to configure the limit and permanenty store it in the EEPROM since hardware version v1.3.


========== ============= ============= ===========
persistent self-clearing Stops PID     Panic Mode
========== ============= ============= ===========
no         no            yes           no
========== ============= ============= ===========
