ADRESH and ADRESL registers for analog signal data acquisition

Discussion in 'Embedded Systems and Microcontrollers' started by AustinCann, Feb 9, 2011.

  1. AustinCann

    Thread Starter New Member

    Jan 30, 2011
    I had a good luck today and first time seen LEDs coming on with my code. I am now trying to switch LEDS using analogue input. I know the code but slightly confused with using registers:

    while (ADCON.Go==1)
    return (((ADRESH*256) + ADRESL) * 0.00489);
    void main ();
    if ( get_vol() <2.5)
    { PORTC=get_vol();}

    1) Lets say we acquiring data off a voltage sensor, at what point does the pic controller decide data is acquired and clear ADCON.GO to 0. Does it scan the input only once?
    2) I copied "(((ADRESH*256) + ADRESL) * 0.00489);" from a book. I however does not understand whats happening here:

    The ADFM is one means right justified. Why multiplied ADRESL with 256 and nothing with ADRESL and why multiplier with quantization step 0.00489.

    Please help!
    Kind Regards
  2. Markd77

    Senior Member

    Sep 7, 2009
    I don't know much C so someone else will have to help out with the rest.

    ADRESH is multiplied by 256 to make the two 8 bit registers into a 16 bit variable eg. if the registers contained 2 and 1, it multiples the 2 by 256 to get 512, adds the 1 and you have a value slightly over halfway on the scale.
    It's multiplied by 0.00489 to convert to volts (5/1024=0.00489).

    Note, if you never need to display in volts then it's quicker not to multiply by 0.00489 and then use 512 instead of 2.5 in the comparison.
    AustinCann likes this.