This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Differences in programming 8-bit ADC and 12-bit ADC

Hi,

I am currently trying to modify an existing code to display 12 bit data (C8051F206) instead of 8 bit data (C8051F226).

When I download the existing codes and run the program, my LCD is able to display some values. However, when I modify the program to display 12 bit data, the LCD just show 0.000V when I adjusted the ADC input. May I know what is different in the ADC configuration that I have to change ? What is wrong with my 12 bit code?

8-bit code:

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
        unsigned int q,value,temp;
        unsigned char a,b,c,d;
        float bit_value,result;
/*------------------
// ADC Conversion
 -------------------*/

void adcdata()
{

                ADCINT = 0;


                ADBUSY = 1;
                ldelay(100);

                while(ADCINT==0);

                value = ADC0L;
                value = value*256;
                ldelay(900);

                ldelay(1000);
                ADCINT=0;
                ADBUSY=0;

}

/*------------------------------------------------------
// Bit Resolution: result = Voltage reference*(255/256)
 -------------------------------------------------------*/

void bit_resolution()
{

        bit_value = 3.2/(256);
        result = value*bit_value;
}

My 12 bit code (Left justified ADCOH:ADCOL):

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
        unsigned int q,value,value1,temp,totvalue;
        unsigned char a,b,c,d,e;
/*------------------
// ADC Conversion
 -------------------*/

void adcdata()
{

                ADCINT = 0;
                value=0;

                ADBUSY = 1;
                ldelay(100);

                while(ADCINT==0);
                value = ADC0L;
                e= 0x0F & ADC0H;
                value1=e;
                totvalue= value + value1*256;
                ldelay(900);

                ldelay(1000);
                ADCINT=0;
                ADBUSY=0;

}

Appreciate if anyone could help. Thanks!!


Parents
  • First output the counts on the display. To make sure the A2D is configured and working. Then Output more and more of the conversions. Read your code. Note that going from 8 to 12 bits can make 16 bit values overflow.
    value=value*256 is good for 8 bits, but overflows at 12.

Reply
  • First output the counts on the display. To make sure the A2D is configured and working. Then Output more and more of the conversions. Read your code. Note that going from 8 to 12 bits can make 16 bit values overflow.
    value=value*256 is good for 8 bits, but overflows at 12.

Children
No data