CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC ref problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
simon630



Joined: 07 Sep 2003
Posts: 17

View user's profile Send private message

ADC ref problem
PostPosted: Mon Jan 13, 2003 5:39 am     Reply with quote

dear friends,
i am now using the adc features of 16c73 chip. because the circuit is more or less finalized, my reference voltage has to stay at 2.5v at pinA3. and the monitored analog input is tied to pinA0. this is an output pin of a battery whose rating is 4.2v. now what i want to do is to monitor this pin so that when it drops to around 3v, i will go and charge it. however, the voltages from 3v-4.2v are higher than the refenrence one. i am wondering whether the compiler provides any additional function that makes the Vref 2 times of the one it detects on the pinA3.

main(){
....
setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel(0);
while (1) {
....
value=read_adc();
} //end while
}
attached is portion of the program. thx for anybody's help in advance.
Simon
___________________________
This message was ported from CCS's old forum
Original Post ID: 10645
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: ADC ref problem
PostPosted: Mon Jan 13, 2003 1:01 pm     Reply with quote

:=dear friends,
:= i am now using the adc features of 16c73 chip. because the circuit is more or less finalized, my reference voltage has to stay at 2.5v at pinA3. and the monitored analog input is tied to pinA0. this is an output pin of a battery whose rating is 4.2v. now what i want to do is to monitor this pin so that when it drops to around 3v, i will go and charge it. however, the voltages from 3v-4.2v are higher than the refenrence one. i am wondering whether the compiler provides any additional function that makes the Vref 2 times of the one it detects on the pinA3.
:=
:=main(){
:=....
:=setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
:=setup_adc( ADC_CLOCK_INTERNAL );
:=set_adc_channel(0);
:=while (1) {
:=....
:=value=read_adc();
:=} //end while
:=}
-------------------------------------------------------------

Why don't you use the internal Vref of VDD ?
I assume you're running the PIC at +5v.
That would let you measure your analog voltage of 4.2v.

If you look at Figure 13-2 in the 16c73a data sheet,
you're currently using the setting with the CFG bits
set to 101. If you change it to use the setting for 100,
then RA3 becomes an analog input, and the Vref becomes VDD.
Since you already have an analog voltage (in effect)
of 2.5v on RA3, it's no problem. You still have the
same digital pins as before. Looks like it should work.

Use the following line to configure the PIC for that mode.
setup_adc_ports(RA0_RA1_RA3_ANALOG);
___________________________
This message was ported from CCS's old forum
Original Post ID: 10655
Sherpa Doug
Guest







Re: ADC ref problem
PostPosted: Mon Jan 13, 2003 1:13 pm     Reply with quote

:=:= i am now using the adc features of 16c73 chip. because the circuit is more or less finalized, my reference voltage has to stay at 2.5v at pinA3. and the monitored analog input is tied to pinA0.
:=Why don't you use the internal Vref of VDD ?

If you are worried that VDD may not be as stable as your 2.5V, you may be able to measure the 2.5V and correct for drift of VDD.
For example if A0 reads 123, and A3 reads 197 then
197/123=2.5V/Vbatt so Vbatt=4.0V even if VDD has drifted.

___________________________
This message was ported from CCS's old forum
Original Post ID: 10657
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: ADC ref problem
PostPosted: Mon Jan 13, 2003 1:18 pm     Reply with quote

:=:=:= i am now using the adc features of 16c73 chip. because the circuit is more or less finalized, my reference voltage has to stay at 2.5v at pinA3. and the monitored analog input is tied to pinA0.
:=:=Why don't you use the internal Vref of VDD ?
:=
:=If you are worried that VDD may not be as stable as your 2.5V, you may be able to measure the 2.5V and correct for drift of VDD.
:=For example if A0 reads 123, and A3 reads 197 then
:=197/123=2.5V/Vbatt so Vbatt=4.0V even if VDD has drifted.
----------------------------------------------------------
Or he could spend more money and put in a 1\% regulator.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10658
oscar
Guest







Re: ADC ref problem
PostPosted: Mon Jan 13, 2003 4:19 pm     Reply with quote

:=dear friends,
:= i am now using the adc features of 16c73 chip. because the circuit is more or less finalized, my reference voltage has to stay at 2.5v at pinA3. and the monitored analog input is tied to pinA0. this is an output pin of a battery whose rating is 4.2v. now what i want to do is to monitor this pin so that when it drops to around 3v, i will go and charge it. however, the voltages from 3v-4.2v are higher than the refenrence one. i am wondering whether the compiler provides any additional function that makes the Vref 2 times of the one it detects on the pinA3.
:=
:=main(){
:=....
:=setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
:=setup_adc( ADC_CLOCK_INTERNAL );
:=set_adc_channel(0);
:=while (1) {
:=....
:=value=read_adc();
:=} //end while
:=}
:=attached is portion of the program. thx for anybody's help in advance.
:=Simon

Simon,

There is a simple solution to your problem. Create a voltage divider from your battery to ground. Use two 10k Ohm resistors in series to ground from battery. This will divide your battery by two. The divided battery signal = Vbat/2 should now be connected to pin A0. What you will now do is poll your A/D (pin A0) so when you read 1.5V (half of 3V) you will activate your charger.

The voltage divider will consume less than 200uA at full battery voltage. If this current consumption is too high for your application proceed to increase the voltage divider resistor values to 20K. Raising the resistance values will increase your A/D acquisition time.....remember the A/D can be modeled as a capacitor charge circuit so if your input impedance is high then your time constant increases (keep this in mind if you have issues as you raise the impedance).


Hope this helps,
Oscar
___________________________
This message was ported from CCS's old forum
Original Post ID: 10667
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group