Page 1 of 1

ADC problem with SK40C

PostPosted: Sat May 05, 2012 3:26 am
by MaxD
ADCON0:
bit7 - ADCS1
bit6 - ADCS0
bit5 - CHS2
bit4 - CHS1
bit3 - CHS0
bit2 - GO/DONE
bit1 - unimplemented bit
bit0 - ADON
----------------------------------------------------------
ADCON1:
bit7 - ADFM
bit6 - unimplemented bit
bit5 - unimplemented bit
bit4 - unimplemented bit
bit3 - PCFG3
bit2 - PCFG2
bit1 - PCFG1
bit0 - PCFG0
---------------------------------------------------------
According to the registers above, I set RA3 as Vref+ and RA2 as analog input:
CODE: SELECT_ALL_CODE
TRISA = 0b11111;
TRISE = 0b111;

ADCON0 = 0b10010001;
ADCON1 = 0b10000001;

__delay_ms(2);
   ADGO=1;
   while(ADGO==1)
      continue;
   return(256*ADRESH+ADRESL);

I can't get any power supply from RA3, why? If there is no power supply from RA3, then why LCD didn't show 0 value? Any problem with my register setting?

Re: ADC problem with SK40C

PostPosted: Sat May 05, 2012 9:05 am
by ABSF
Vref+ is an input pin. You're not going to get any voltage from it.

PIC_ARCH.JPG


Allen

Re: ADC problem with SK40C

PostPosted: Sat May 05, 2012 11:16 am
by holy_rainman
Doesn't that mean we have to supply voltage ranging from 0V to 5V to Vref? Does it act like a comparator? I haven't played with Vref yet...

Re: ADC problem with SK40C

PostPosted: Sat May 05, 2012 10:29 pm
by ABSF
The Vref+ of the ADC is selectable to Vdd internally or externally through RA3 by the "PCFGx" bits. The external Vref+ can be 0-5V using linear pot or a voltage reference chip such as TL431.

Allen

Re: ADC problem with SK40C

PostPosted: Sat May 05, 2012 11:35 pm
by robosang
Allen is right. :mrgreen:

1st thing, PIC does not have analog output pin, only Analog Input pin. Of course some uses PWM output to get analog voltage, still you need to do some circuitry to get that :)

2nd, don know why you want to change the Vref(+) to RA3, just tie it to VDD which is 5V normally. For cases where Vref(+) is tie to I/O pin is they wanted the Vref(+) to be other than VDD, example 2.0V, 4.0V, 1.023V.....

Re: ADC problem with SK40C

PostPosted: Sun May 06, 2012 3:16 pm
by MaxD
So in order to get voltage from Vref+, i need to add in some extra components in the circuit, else it is just an analog input with no input voltage, right?

Re: ADC problem with SK40C

PostPosted: Sun May 06, 2012 5:26 pm
by ABSF
MaxD WROTE:So in order to get voltage from Vref+, i need to add in some extra components in the circuit, else it is just an analog input with no input voltage, right?


No, you're not going to get voltage from Vref+ but you're going to give a reference voltage to Vref+.

robosang WROTE:1st thing, PIC does not have analog output pin, only Analog Input pin. Of course some uses PWM output to get analog voltage, still you need to do some circuitry to get that


What robosang was saying is that PIC does not have analog output PIN cos ADC output is in digital form stored in ADRESx. If you need analog output, you have to use another IO pin (CCP1 or ordinary IO pin) and use PWM method to convert the number stored in ADRESx or any other variables into analog form. But why do you want to do that ? This can be easily done with an op-amp..... :mrgreen:

Allen

Re: ADC problem with SK40C

PostPosted: Mon May 07, 2012 6:30 am
by MaxD
Oh, i see...thank you for your well explanation allen and robosang, thank you for your help =D