Overflow and Underflow of analog measurements against references

This article applies to:
Dolphin based modules performing analog measurements

QUESTION

What will happen with my analog measurements result value after scaling, when the value was under the negative reference or above the positive reference?

ANSWER

The behavior of the scaling function is that:

  • underflow will result in values increasing again 1,2,3…. (the value is lower then the negative reference, the result is the absolute value of -1,-2,-3 -> 1, 2, 3 )
  • overflow will do the same e.g. for 8bit 256,257,258 (after trunk to 8 bit) -> 1,2,3…

Overflow and underflow should be not a common application scenario, therefore please plan your references carefully so this state will not occur. Altough there might be situation where this can happen, so it is good at least detecting this situation so the application will not provide wrong measurements. In Dolphin you can detect this state by simply comparing the unscaled measurements.

     sint16 s16negref;
     sint16 s16posref;
     sint16 s16adio1value;
     uint16 u16adio1value;

     io_enableAnalog(1); // configuring hardware for analog measurement no VGA, increase current to Analog current
     io_ulpMeasAnalog(RVDD, &s16posref); // measure positive reference against internal voltage
     io_ulpMeasAnalog(RVSS, &s16negref); // measure negative reference against internal voltage
     io_ulpMeasAnalog(GPIO1_ADIO_1, &s16adio1value); // measure ADIO_1 against internal voltage
     io_enableAnalog(0); // restoring previous configuration for radio functionality and reduce current to CPU current
     
     if(s16posref<s16adio1value)
     {
         // error handling for overflow
     }
     else if (s16negref>s16adio1value)
     {
         // error handling for underflow
     }
     else
     {
         // all is ok
         io_ulpScaleAnalog(s16posref, s16negref, s16adio1value, s16negref, 8, &u16adio1value); // scale and calculate result for ADIO_1
         ....
     } 

FAQ Single Template