2.3 Voltage Monitoring
The core function of this example is to monitor the voltage on the output of the relay using the integrated Analog-to-Digital Converter (ADC). Since this output is likely at a higher voltage than the microcontroller, a voltage divider is used to scale the signal (see the Implementation chapter for more information). The ADC runs almost continuously by being triggered every time the ADC Result High (ADRESH) register is read.
When a new ADC sample is ready, the function Relay_onADCReady
is called.
This function reads the results (triggering the next conversion) and checks to see if
the result is above the threshold (ADC_THRESHOLD_HIGH
), below the
threshold (ADC_THRESHOLD_LOW
), or neither. Then, it looks at the
current relay state to determine if the value makes sense.
For instance, if the relay is in the RELAY_CLOSED state, but the voltage is below the threshold, this would be considered a fault, as voltage is expected, but not present.