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

Vref - a few questions?

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



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Vref - a few questions?
PostPosted: Wed Oct 19, 2005 9:14 pm     Reply with quote

The compiler has the function SETUP_VREF() for the internal reference for the A/D. Using the two expressions given in that section the following table in Excel shows the multiple choices for Vdd = to 5 Volts. Do the values look correct?

VDD=> 5

Value........VREF_LOW......VREF_HIGH
0..............0.000.............1.250
1..............0.208.............1.406
2..............0.417.............1.563
3..............0.625.............1.719
4..............0.833.............1.875
5..............1.042.............2.031
6..............1.250.............2.188
7..............1.458.............2.344
8..............1.667.............2.500
9..............1.875.............2.656
10............2.083.............2.813
11............2.292.............2.969
12............2.500.............3.125
13............2.708.............3.281
14............2.917.............3.438
15............3.125.............3.594

In the 16F877A.h file there are the expressions shown below. Are these the same expressions used to calculate the above values. If not how are these used?

// Constants used in setup_vref() are:
#define VREF_LOW 0xa0
#define VREF_HIGH 0x80
// Or (with |) the above with a number 0-15
#define VREF_A2 0x40

Questions:
1. What is VREF_A2 and what does it mean.
2. I assume that the lack of any statement sets VREF to VDD.
3. How does one enable an external Vref and I assume that this would
be at pin AN2/Vref+.
4. How does one setup Vref- and is it Vss or ground
when no statement is made.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 19, 2005 9:56 pm     Reply with quote

Most of your questions can be answered by looking in this
section of the 16F877A data sheet:
Quote:
13.0 COMPARATOR VOLTAGE
REFERENCE MODULE


First, you should understand that all that the setup_vref()
function does is to stuff values into the CVRCON register.
See Section 13.0 of the 16F877A data sheet for info on that register.

Quote:
1. What is VREF_A2 and what does it mean.

It sets bit 6 of CVRCON = 1. From the data sheet:
Quote:
bit 6 CVROE: Comparator VREF Output Enable bit
1 =CVREF voltage level is output on RA2/AN2/VREF-/CVREF pin
0 =CVREF voltage level is disconnected from RA2/AN2/VREF-/CVREF pin


Quote:
2. I assume that the lack of any statement sets VREF to VDD.

The following section tells you the maximum voltage that you
can set as the comparator Vref. It's 0.75 x Vdd in both cases.
Quote:
bit 5 CVRR: Comparator VREF Range Selection bit
1 = 0 to 0.75 CVRSRC, with CVRSRC/24 step size
0 = 0.25 CVRSRC to 0.75 CVRSRC, with CVRSRC/32 step size

Note that CVRSRC = the Vdd voltage.

Quote:

3. How does one enable an external Vref and I assume that this would
be at pin AN2/Vref+.

Answered above in question 1.

Quote:
4. How does one setup Vref- and is it Vss or ground
when no statement is made

Note that Vref- is part of the A/D module. It's not part of the
Comparator Vref module, which questions 1 through 3 were about.
To configure the A/D converter to use an external Vref- is done
with the CCS function setup_adc_ports(). The parameters for
this function are given in the 16F877A.H file. Refer to the chart
for the ADCON1 register, in sectoin 11.0 of the 16F877A data sheet
for an explanation of the settings given in the 16F877A.H file for
the setup_adc_ports() function.
Guest








Vref does not equal all Vref Aha!
PostPosted: Thu Oct 20, 2005 12:15 am     Reply with quote

I clearly did not understand the difference. Thanks for the clarification.
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