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.

Weird performance of ADC converter in PIC16f877a

Status
Not open for further replies.

mamech

Full Member level 3
Joined
Nov 9, 2010
Messages
176
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,135
hello

I found a very strange and weird performance of custom made ADC function.

I used the following code:
Code:
int CustomADC_Read (unsigned char k) // needs to be modified to get inut from user
{
  int Adc_Result=0;          // the variable that we will use to put the result of conversion in it
  ADCON0=0b10000000;
  ADCON0 = ADCON0|k<<3;
  
  ADCON1=0b10000000;
  ADCON0bits.ADON = 1;       // start A/D converter module is powered up  so this means
  ADCON0bits.GO_DONE = 1;    //that if A/D Conversion Status bit When ADON = 1 ,
                         // then A/D conversion in progress (setting this bit starts the 
                         // A/D conversion which is automatically cleared by hardware when the A/D conversion is complete)

  
  while(ADCON0bits.GO_DONE); //this will make it looping until conversion to finish
  ADCON0bits.ADON = 0;       //switch off adc so it consumes no power
  Adc_Result = (ADRESH<<8)|ADRESL;   // shifting ADRESH 8 times so we can add it to ADRESL , an so we can get the result correctly

return Adc_Result;

}


what is really strange, is that this code works, but the limit of max conversion (when input equals reference) is not 1023, but it is a number less than 930 !! and and even sometimes in range of 600 or 700!!

this was strange enough , but what was more strange, is what was the source of the problem!

I found that the source of problem was shutting down the ADC module after conversion , using ADCON0bits.ADON = 0 !!

once I commented this line, the conversion became normal, and it reaches the limit of 1023 normally.

can anyone explains to me, what is the relation between shutting down the ADC module after conversion ends, and the weird number that I get from conversion??
 

hello,


what is really strange,

your code itself is strange ..

lets's the ADC finish his job without disturbation
... and we don't know what is the minimum delay between each call of CustomADC_Read !

the minimum could be to place
ADCON0bits.ADON = 0;
after reading the ADRESH and ADREL

We don't know your FOSC value...
Maybe you need also to add some microdelay like
_asm nop or Delay_us(xx)
between ADC init and ADC read
to stabilise Analog part of ADC
check all delay needed by the ADC convertion .. PIC Datasheet
 

lets's the ADC finish his job without disturbation
... and we don't know what is the minimum delay between each call of CustomADC_Read !
the minimum delay between calls will not affect anything . in all cases the ADC will not return to main function except if it has finished conversion.
the minimum could be to place
ADCON0bits.ADON = 0;
after reading the ADRESH and ADREL

this modification that you said, I have already tested it, and no difference between this or that.

We don't know your FOSC value...

4 Mhz

Maybe you need also to add some microdelay like
_asm nop or Delay_us(xx)
between ADC init and ADC read
to stabilise Analog part of ADC
check all delay needed by the ADC convertion .. PIC Datasheet

I will recheck about this, you may be right that this can cause this problem.
 

the minimum delay between calls will not affect anything



extract from datasheet ...
TABLE 11-1: TAD vs. MAXIMUM DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (C))

For correct A/D conversions, the A/D conversion clock
(TAD) must be selected to ensure a minimum TAD time of 1.6 µs.
After the A/D conversion
is aborted, a 2TAD wait is required before the next
acquisition is started. After this 2TAD wait, acquisition
on the selected channel is automatically started. The
GO/DONE bit can then be set to start the conversion.
 
  • Like
Reactions: mamech

    mamech

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top