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 CCS Technical Support

How to configure 18F2525 for bipolar A/D inputs

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



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

How to configure 18F2525 for bipolar A/D inputs
PostPosted: Mon Feb 11, 2008 11:31 am     Reply with quote

Hi all,

I am trying to use the A/D function on the 18F2525 for a bipolar input from -5V to +5V. I am reading the datasheet and it says:

The analog reference voltage is software selectable to be either the device's positive and negative supply voltage (VDD and Vss), or the voltage level on the Vref+ and Vref- pins.

But then I read the device file (18f2525.h) and it says:

#define VSS_VDD 0x00 // Range 0-Vdd
#define VREF_VREF 0x30 // Range VrefL-VrefH
#define VREF_VDD 0x20 // Range VrefL-Vdd
#define VSS_VREF 0x10 // Range 0-VrefH


There doesn't seem to be an option for a range of -Vss to Vdd. The option:
#define VSS-Vdd

seems to give a range of 0 - Vdd according to the comments.

So what is the correct #define statement to use if I want to use -Vss and Vdd supply voltages on the PIC to be my A/D lower and upper limits?

Thanks
MK
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 11:35 am     Reply with quote

You can't. The analog - reference can't be below Vss (ground). You'll have to add some analog signal conditioning prior to the PIC to turn the double-ended inputs into single-ended inputs.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 11, 2008 11:39 am     Reply with quote

newguy wrote:
You can't. The analog - reference can't be below Vss (ground). You'll have to add some analog signal conditioning prior to the PIC to turn the double-ended inputs into single-ended inputs.


Thanks for the reply.

So this line from the datasheet is wrong?

The analog reference voltage is software selectable to be either the device's positive and negative supply voltage (VDD and Vss), or the voltage level on the Vref+ and Vref- pins.
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 12:08 pm     Reply with quote

No, that line is correct. The caveat is that Vref- must be greater than or equal to Vss, and less than Vdd. Somewhere in the "electrical specifications" or similar at the back of the datasheet you'll find the note regarding Vref-. It will specify the acceptable voltage input range for this pin.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 11, 2008 12:31 pm     Reply with quote

newguy wrote:
No, that line is correct. The caveat is that Vref- must be greater than or equal to Vss, and less than Vdd. Somewhere in the "electrical specifications" or similar at the back of the datasheet you'll find the note regarding Vref-. It will specify the acceptable voltage input range for this pin.

I see. Looks like Vdd - Vss is a maximum of 7Volts so there is no way you can use +5V for Vdd and -5V for Vss. Which also means the most range you can get between Vref+ and Vref- is less than about 7volts. I think I am better off inverting the negative signal with an opamp buffer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 1:39 pm     Reply with quote

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25005
In the diagram that I posted, if you set the voltage on the bottom
resistor to +5v, then it would convert a signal with an input range
of +/- 5v to a range of 0v to 5v.

In other words, it would reduce the amplitude from 10v p/p down
to 5v p/p, and it would shift the level so it's referenced to 0v.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 12, 2008 8:57 am     Reply with quote

Thanks PCM Programmer. I am familiar with that circuit but not exactly what I want to do. My signal is coming from a particular sensor and there are two types of sensors: one with a signal from 0-5V and the other from 0 to -5V. So depending on the sensor I plug in the signal is either all positive or all negative so no I wouldn't want to shift the level.
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