static int ADC_AdaptPGA(signed long data, int pga)

{

for (auto a = 0; a < pga; ++a) {

if (abs(data) > (0x6aaaaaa >> a)) { /* 0x6aaaaaa = 500mV ADC code */

pga = a;

}

}

for (auto a = 7; a > pga; --a) {

if (abs(data) < (0xcaaaaaa >> a)) { /* 0xcaaaaaa = 950mV ADC code */

pga = a;

}

}

return pga;

}

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

Can you help me to explain how 0x6aaaaaa is equal to 500 mv in ADC code ? I understand how to convert from ADC reading back to raw voltage but I tried to put this value into my equation, it is different than 500 mV.

Thanks

hi dante2608:

(0x6aaaaaa/0xfffffff)*1.2V=0.5V

(0xcaaaaaa/0xfffffff)*1.2V=0.95V