View previous topic :: View next topic |
Author |
Message |
contialdo
Joined: 15 Apr 2007 Posts: 1
|
16f88 adc problem |
Posted: Sun Apr 15, 2007 2:57 am |
|
|
Hi,
I am trying to read an lm35 temperature sensor with the 16f88. It works very well if I setup the adc as:
setup_port_a( sAN0|VSS_VDD );
But then I would like to use the internal vref in order to have a different reading range, as the sensor gives 10mv/C.
If I try this code:
setup_vref(VREF_HIGH);
setup_port_a( sAN0|VSS_VREF );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
then any reading of the adc gives 1023. The same if I try with VREF_HIGH|5) or any other number.
What am I doing wrong???
Regards,
Aldo |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Sun Apr 15, 2007 5:28 am |
|
|
I think that you are confusing the comparator reference and the adc reference.
The comparator reference is separate from the comparator setup and can be output on RA2,
but in adc mode this is the external Vref- input, not what is needed.
An external reference is needed on RA3 (Vref+ in adc mode) to do what you want.
So the setup is then sAN0|VSS_VREF - this gives a range of 0 to Vref volts. |
|
|
Guest
|
|
Posted: Sun Apr 15, 2007 9:15 am |
|
|
Hi,
you could not possibly any more right... after two days struggling, I undersood my mistake some 15 minutes after posting the message! Now I am feeding an external vref and it works fine. Thank you, anyhow.
Regards
Aldo |
|
|
|