Microchip: ADC_GetConversion

0

I'm developing an alarm and the "actions" will be performed by voltage dividers (ADCconverter).

voltdivneg = ADC_GetConversion(VOLT_DIV_NEG);
voltdivpos = ADC_GetConversion(VOLT_DIV_POS);

There are 3 states: STAND-BY, FAULT, and ALARM. Vout will be toggling between + and - .

For STAND-BY- > the voltage can be (already converted value): 4 (-) 875 (+) or 1023 (-) 150 (+). If the value is different it will enter a state that will later analyze if it is FAIL or ALARM. However, something strange happens with these lines of code (note that I set the widest ranges to guard against some discrepancies that might happen):

if((voltdivneg > 0 && voltdivneg <= 8 && voltdivpos >= 870 && voltdivpos < 890) || 
   (voltdivneg > 1020 && voltdivpos > 140 && voltdivpos < 160))
{
    status = STNDBY;
}
else
{
    status = VERIFIC;;
}

What happens? With this restriction, the positive voltage divider "escapes" from the value and becomes a value greater than 160. If I "extend" the range to 170, it rises above 170 and so on. Doing so it does not assume the STAND-BY state but rather VERIFICATION.

I have no idea what might be happening. If anyone can help, thank you.

    
asked by anonymous 19.03.2018 / 15:46

0 answers