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

A/D quick question

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



Joined: 31 Aug 2009
Posts: 17

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

A/D quick question
PostPosted: Sat Oct 24, 2009 5:38 am     Reply with quote

Hello
I've used Vref_vref at a voltmeter I made and I came up with one question.
What's the difference between:
Vref_vref
Vref_Vdd
Vref_Vss

Thnx
Ttelmah
Guest







PostPosted: Sat Oct 24, 2009 3:41 pm     Reply with quote

The ADC, internally has two connections that generate the 'range' over which it operates. VrefL and VrefH (the bottom and top of it's range). The definitons control what these are connected to.
VrefL, can be connected internally to the Vss pin, or to the separate VrefL external pin. Similarly, VrefH can be connected to Vdd or to it's external pin.
The data sheet shows details.

In the 'defines', the first value determines where VrefL comes from, and the second, where VrefH comes from.
Advantages of using an external reference, are:
You can select a voltage range that better suits your incoming signal (caveat, the PIC, normally needs something in the order of 2.5v between VrefL and VrefH to give it's full accuracy - data sheet again).
You can use a better regulated source.
You can maintain better isolation between the analog circuitry, and the digital stuff.

These all help accuracy. People who are genuinely getting 10bits or more from the ADC, _will_ be using these.

Best Wishes
Guest








PostPosted: Sat Oct 24, 2009 5:00 pm     Reply with quote

Can you or anyone mention some examples ?
For instance, when do I connect Vref- or Vref+ (and where) ?
And when do I use Vref_vref or Vref_Vdd or Vref_Vss ?

Thnx
dbsjro



Joined: 31 Aug 2009
Posts: 17

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

PostPosted: Sat Oct 24, 2009 5:09 pm     Reply with quote

So when I use Vref_Vref what does that mean?
The first Vref is for VrefL and the second for VrefL?

And when I use Vref_Vdd
The first Vref is for VrefL and Vdd for VrefL?

Shocked Exclamation
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 24, 2009 9:31 pm     Reply with quote

Quote:
So when I use Vref_Vref what does that mean?

It means you are using external Vref voltages for both Vref+ and Vref-.

Quote:
And when I use Vref_Vdd

It means Vdd is used for Vref+, and that you are supplying an external
voltage for Vref-.

Quote:

Can you or anyone mention some examples ?

Suppose that you had an analog voltage that would never be higher
than about 4.0 volts. Suppose that you wanted to make one "step" on
the A/D be an even number of millivolts. Then you could use an external
reference voltage for Vref+ of 4.096 volts. (Using VSS_VREF). This would
mean that in 10-bit mode, one "step" on the A/D would be worth 4.0 mv.

Why is that nice ? Because the math is now very easy to convert from the
raw A/D value into a voltage. Let's say you read an A/D value of 525. To
convert that to volts, just multiply it by 4. That multiply operation can be
done by the compiler with two "left-shifts". It's quick and uses very little
ROM space. 525 x 4 = 2100 mv, which is 2.100 volts.
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Sat Oct 24, 2009 9:35 pm     Reply with quote

dbsjro wrote:
So when I use Vref_Vref what does that mean?
The first Vref is for VrefL and the second for VrefL?

And when I use Vref_Vdd
The first Vref is for VrefL and Vdd for VrefL?

Shocked Exclamation


Basically, when you're using an ADC, you need to tell it what it's maximum voltage is, as well as its minimum. Think of it as setting a threshold. When you say VREF_VSS, the vref is your maximum voltage, and VSS is your minimum voltage. Vref refers to the vref pin on your pic, vss refers to the VSS pin, and VDD refers to the VCC pin. So if your PIC was powered at VDD by 5.0V, and grounded at VSS, then VDD_VSS would mean that the maximim voltage is going to be 5.0v (VDD), and the minimum voltage will be 0V (VSS, or Ground). If want to use the VREF pin on your pic as your maximum voltage, then set it as VREF_VSS.

I believe this is inaccurate, but it should give you the basic idea of how it works. If you understand it better, you can look up the correct order of VREFL and VREFH, or someone here might correct me.
_________________
Vinnie Ryan
dbsjro



Joined: 31 Aug 2009
Posts: 17

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

PostPosted: Sun Oct 25, 2009 5:22 am     Reply with quote

vinniewryan I think you are wrong.
First Vref is for Vref- and the second for Vref+.

Ok I understand it now.
I use
Code:
setup_adc_ports(AN0_VREF_VREF);

But it shows an error when I change it to
Code:
setup_adc_ports(AN0_Vss_VREF);

My program runs ok the way it is but I wanna know about the error.
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Sun Oct 25, 2009 11:25 am     Reply with quote

Try this:

Code:


setup_adc_ports(AN0 | Vss_VREF);



I simply separated the AN0 from the Vss_VREF command. If you want to add more pins using the ADC, set it up like this:

Code:


setup_adc_ports(AN0 | AN3 | AN4 | VSS_VREF);



Hope this helps! Let me know your result.
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 25, 2009 12:16 pm     Reply with quote

Quote:
setup_adc_ports(AN0 | AN3 | AN4 | VSS_VREF);

He has never posted his PIC (or his compiler version). We don't know
what ADC constants are in the .h file for his PIC.
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Sun Oct 25, 2009 12:29 pm     Reply with quote

Good point, I simply assumed he/she was using a 16F628 based on his/her previous posts.
_________________
Vinnie Ryan
dbsjro



Joined: 31 Aug 2009
Posts: 17

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

PostPosted: Sun Oct 25, 2009 1:48 pm     Reply with quote

I use 16f877
version 4.057

Code:
setup_adc_ports(AN0 | Vss_VREF);

Error 12......Udefined identifier Vss_VREF

I thing it just dosen't support it right?(The pic)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 25, 2009 1:53 pm     Reply with quote

Look in the 16F877.h file to see the list of constants that may be used
with setup_adc_ports() for that PIC. Here's the file location:
Quote:

c:\program files\picc\devices\16f877.h
dbsjro



Joined: 31 Aug 2009
Posts: 17

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

PostPosted: Sun Oct 25, 2009 2:03 pm     Reply with quote

It doesn't support it.

Anyway my job is already done.
It was just a thought.

Thnx both Cool
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