Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Looking for working code of 16F877 ADC to display a value on 3 digit LED display

Status
Not open for further replies.

latecomer

Member level 4
Joined
Jun 6, 2001
Messages
77
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Location
USA
Activity points
642
Hello all,
I'm desperately looking for working code of 16F877 ADC . I want to display the analog value on 3 digit LED display. When i display it, it works fine but when the input analog value changes, the display becomes erratic. IF it is displaying 100 as the analog value, and when i increase it then the display shows the following values.

100
101
102
99 <
104
105
106
103 <
108
109
110
107
112
113
114
111 <

Has anyone faced similar problem ???
 

read_adc adc_start_only

It is hard to say anything without looking at your code, but note that every
fourth value is displaying the fourth previous value - it's a clue.
Do you do any operations on the data from the ADC that could affect it?

/Rambo
 

pic16f877 adc noise

There may be noise on your inputs but then again it could be your code both hard ware and software must be seen here. Your 5 volt regulator might be oscillating. You might not be giving the ADC enough time to sample fully. We need to see your code.
 

pic16f877 adc left-justified

Here's the code for the ADC.

//===================================
//-----ADC intialisation function----
void ADC_init(void)
{
//---- Initialise ADC ----
ADCON1=0x09; //-- RA0-RA4 AND RE0 are Analogue inputs, rest all are digital pins on PORTA
ADCON0=0x80; //-- Reset to defaults

ADCS1=1; //--|
// |---- Sample Clock = fosc/32 = 20MHz/32 = 1.2us
ADCS0=0; //--|
ADON=1; //-- Turn ADC ON

}

//----- read the ADC on RA0 ----
unsigned long Sample_ADC(unsigned int channel)
{
unsigned long ADC_VALUE;
ADRESL=0;
ADRESH=0;

DelayUs(20);
/* CHS0=0;
CHS1=0;
CHS2=0;*/
if(channel==0)
{
CHS0=0;
CHS1=0;
CHS2=0;
}
else if(channel==1)
{
CHS0=1;
CHS1=0;
CHS2=0;
}
else if(channel==2)
{
CHS0=0;
CHS1=1;
CHS2=0;
}
else if(channel==3)
{
CHS0=1;
CHS1=1;
CHS2=0;
}
/* else if(channel==4)
{
CHS0=0;
CHS1=0;
CHS2=1;
}
else if(channel==5)
{
CHS0=1;
CHS1=0;
CHS2=1;
}*/

DelayUs(20); //-- Ensure enough Sampling time
ADGO=1; //-- Turn the ADC Converter On
while(ADGO); //-- Wait for conversion to complete
{
DelayUs(20);
}
ADC_VALUE=ADRESL;
ADC_VALUE += (ADRESH<<8);
return(ADC_VALUE); //--- return result----
}

Added after 3 minutes:

Another Query:

How do I reduce the flicker in the display ie., when the value changes in the last digit ie., 100 to 101 or so, the last digit flickers between 0 and 1 how do i reduce it ?
 

adc pic16f877

Hi

U can have a look at your hardware also.
There may be some noice generated in it. Check that.

and comming to display you can wait for sometime to get your value stablize.
for example if the value is getting changed just poll again and ensure the value is permanently changed it can be done in the software.

but I belive your fluctuation in adc values may be influenced by your hardware also just have a look.

regards
gopi
 

fluctuat on 16f877a adc

Charging time required for the ADC is typically 10uSec "PER" channel min. You are sampling 3 channels looks like only giving 20us sample time for all 3 channels. Physically, you cannot sample 3 channels in 20uSec
Try sequencing the operations.

// Example

switch (adch++) // 01xxx001
{ case 0:
adcon0=0b01000001; // set_adc_channel(0);
break;
case 1:
read_adc(ADC_START_ONLY);
break;
case 2:
adcraw[0]=adres;
adcon0=0b01001001; // set_adc_channel(1);
break;
case 3:
read_adc(ADC_START_ONLY);
break;
case 4:
adcraw[1]=adres;
adcon0=0b01010001; // set_adc_channel(2);
break;
case 5:
read_adc(ADC_START_ONLY);
break;
case 6:
adcraw[2]=adres;
adcon0=0b01011001; // set_adc_channel(3);
break;
 

10bit adc value

How do you get the values 100, 101 etc? I mean, you must do something with ADC_VALUE
before it is dispalyed?

The reason I'm wondering is because you set ADFM to 0, which means that the
result from the ADC will be left justified, i.e. the 6 lowest bits in ADRESL will be 0.
This means that the lowest value (apart from 0) from the ADC will be 0000000001000000b
which is 64. Shouldn't i rather be 1? You can try and set ADFM to 1 and see if it solves
the problem right away. If not, we also need the code for the display part... :wink:

/Rambo
 

adc channels of pic16f877a

Hello,
I'm directly taking the 10 bit ADC value and displaying it as decimal (range 0 to 1024 but displaying it in three digit display so 000 to 999)

The problem with the jumping values has been fixed when i changed the time delay from 20 micro sec to 40 micro sec.

Thanks to SAR.

Now can some one advice me on how to stop the flicker in the display ie., when the value changes, it keeps flickering between the old value and new value (the last digit in display) Can someone elaborate on techniques to avoid this ???
 

pic16f877 adc 4 channel oscillating

How often do you update your display?
In my own display routines I only update the display every 0.5 seconds, as you
don't need more frequent updates and also to save CPU time.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top