PIC18F4420 10bit A/D result to 7bit

Discussion in 'Embedded Systems and Microcontrollers' started by thejmh, Sep 10, 2009.

  1. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    Hi! I have a 10K pot used as voltage divider into AN2 and I want to use it to adjust the result value between 0-127. I can get the 10bit result, but how can I convert the 10bit result to 7bit so that I can use the whole range of pot?

    Also how can I calibrate the A/D output to be always 0-127? I measured my pot and the max value it gives to AN2 is 4.97Volts, so i miss some bits. I'd like to have a calibration routine that can measure max and min values of the pot and then always adjust the output to be 0-127, no matter what pot is used. Is this possible?
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    Hmm. The easiest way is to shift the 3 LS bits off.

    You might not need to calibrate it. Your supply might be only 4.97V, so that's what the maximum the pot can output. And if you convert with Vdd as Vref+ and Vss as Vref-, that is converted into full value. Anyway, with 7 bits the step is 5/128 = 0.03906V, not significant enough to warrant a calibration for full value.
     
  3. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    I got the 7bit result and that part is ok now.

    I'm using A/D to control midi. I would like to be able to use higher value pots, like some guitar volume or expression pedals with 250k or 500k pot. The max recommended impedance for analog sources is 2.5k, so what kind of external circuit is needed to match the input impedance?
     
  4. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    An OpAmp will do.
     
  5. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    I'm still a beginner with electronics, so can you give me somekind of schematic that I could try?
     
Loading...