Joined: 25 Aug 2005 Posts: 65 Location: Huntington Beach, CA
Vref - a few questions?
Posted: Wed Oct 19, 2005 9:14 pm
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?
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
Posted: Wed Oct 19, 2005 9:56 pm
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!
Posted: Thu Oct 20, 2005 12:15 am
I clearly did not understand the difference. Thanks for the clarification.
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