Convert 12 bits adc to 10 bit adc. We know that the resolution of the step size for a 12 bit is 1.22, different than the step size of 4.88 of the 10 bit. We need to take into account the extra 2 bits.

What would be the best solution. Just an idea of where to start to look into solving the problem.

movff   ADRESL,lowbyte
movff   ADRESH,highbyte
bcf     STATUS, C
rrcf    lowbyte, f
rrcf    lowbyte,W
bcf    STATUS, C
rrcf    highbyte, f
rrcf    highbyte, W
bcf    STATUS, C
  • 1
    \$\begingroup\$ We can't see your firmware so we can't give much ideas how to modify it. Obviously the part that processes the ADC reading needs to be modifief. \$\endgroup\$
    – Justme
    Dec 30 '21 at 6:36

Divide the 12-bit ADC value by 4. This will make it 10-bit.

You can use 2 right-shifts to do this.

  • \$\begingroup\$ jp314, yes so I'll need to right shift the ADRESL and ADRESH right?. And thus dividing by 4 since 4.88/1.22=4 \$\endgroup\$
    – Citi
    Dec 30 '21 at 8:04
  • \$\begingroup\$ Do not forget to reset C bit at status register. It may affect the next instruction. \$\endgroup\$
    – user263983
    Dec 30 '21 at 10:38
  • \$\begingroup\$ @Citi a 2-bit right-shift basically is the integer division by four, no need to divide it again. Note that jp314's solution would just disregard the two lowest bits, so your uC won't get 12-bit values \$\endgroup\$
    – Sim Son
    Dec 30 '21 at 16:57
  • \$\begingroup\$ @sim so I'll use RRCF to shift right and as well to clear bcf STATUS, C. Thank you \$\endgroup\$
    – Citi
    Dec 30 '21 at 18:11
  • \$\begingroup\$ @user263983, I edited my question. Is that is the right way to shift, I probably need to clear C for each shift right and not every two shifts. Thank you guys \$\endgroup\$
    – Citi
    Dec 30 '21 at 20:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.