View previous topic :: View next topic |
Author |
Message |
cxiong
Joined: 09 Sep 2003 Posts: 52
|
Unable to use PORTE as analog input |
Posted: Thu Aug 26, 2004 11:32 am |
|
|
I try to use PORT E as Analog input. I can't use any of PORT E for
Analog input. I want to use PORTE because I have the
PIC Demo 2 plus board and RA0 already connected to
a POT, A1-A3 are connect to the LCD control signal. I try to connect
a thermistor to RE0, but there is not useable, when I use
the switch ALL_ANALOG then it screwed up the LCD.
I want to leave PORT for the LCD and use porte for
the analog.
Please help!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 26, 2004 11:44 am |
|
|
Of course you didn't tell us what PIC you're using, since we are
mind readers. And also the compiler version.
So I'll assume a 16F877.
Get the data sheet from Microchip for the 16F877.
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2046
In section 11.0 of the data sheet, look at the chart for the ADCON1
register. It lists all possible settings for Port A and Port E.
Then look at the 16F877.H file in your text editor. This file is found here:
c:\Program Files\Picc\Devices
Find the section called: Constants used in SETUP_ADC_PORTS()
Then find the constant defined by CCS that matches the configuration
that you picked from the chart in the data sheet. Then use that
constant as a parameter when you call the setup_adc_ports() function.
That's how you do it. |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Thu Aug 26, 2004 12:14 pm |
|
|
I use the PIC18F458 and I did look at the device file the CCS
defined the constant. None of them match what I need.
Either set ALL_ANALOG OR most of the constant just for
PORTA.
Here I copy it from the CCS file. Which one is the right one
for setting PORTE RE0, RE1, RE2 to analog:
Code: |
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS 7 // None
#define ALL_ANALOG 0 // A0 A1 A2 A3 A5 E0 E1 E2 Ref=Vdd
#define AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF 1 // A0 A1 A2 A5 E0 E1 E2 Ref=A3
#define AN0_AN1_AN2_AN3_AN4 2 // A0 A1 A2 A3 A5 Ref=Vdd
#define AN0_AN1_AN2_AN4_VSS_VREF 3 // A0 A1 A2 A5 Ref=A3
#define AN0_AN1_AN3 4 // A0 A1 A3 Ref=Vdd
#define AN0_AN1_VSS_VREF 5 // A0 A1 Ref=A3
#define AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF 0x08 // A0 A1 A5 E0 E1 E2 Ref=A2,A3
#define AN0_AN1_AN2_AN3_AN4_AN5 0x09 // A0 A1 A2 A3 A5 E0 Ref=Vdd
#define AN0_AN1_AN2_AN4_AN5_VSS_VREF 0x0A // A0 A1 A2 A5 E0 Ref=A3
#define AN0_AN1_AN4_AN5_VREF_VREF 0x0B // A0 A1 A5 E0 Ref=A2,A3
#define AN0_AN1_AN4_VREF_VREF 0x0C // A0 A1 A5 Ref=A2,A3
#define AN0_AN1_VREF_VREF 0x0D // A0 A1 Ref=A2,A3
#define AN0 0x0E // A0
#define AN0_VREF_VREF 0x0F // A0 Ref=A2,A3
#define ANALOG_RA3_REF 0x1 //!old only provided for compatibility
#define A_ANALOG 0x2 //!old only provided for compatibility
#define A_ANALOG_RA3_REF 0x3 //!old only provided for compatibility
#define RA0_RA1_RA3_ANALOG 0x4 //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_REF 0x5 //!old only provided for compatibility
#define ANALOG_RA3_RA2_REF 0x8 //!old only provided for compatibility
#define ANALOG_NOT_RE1_RE2 0x9 //!old only provided for compatibility
#define ANALOG_NOT_RE1_RE2_REF_RA3 0xA //!old only provided for compatibility
#define ANALOG_NOT_RE1_RE2_REF_RA3_RA2 0xB //!old only provided for compatibility
#define A_ANALOG_RA3_RA2_REF 0xC //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_RA2_REF 0xD //!old only provided for compatibility
#define RA0_ANALOG 0xE //!old only provided for compatibility
#define RA0_ANALOG_RA3_RA2_REF 0xF //!old only provided for compatibility
|
Which of the above is the right one?
NOTE: the constants are similar for both pic18f458 and pic16f877 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 26, 2004 12:23 pm |
|
|
The Port E and Port A settings are shown in the 18F458 data sheet in
Section 20. The chart shows that you can't set Port E to be analog pins
just by itself, while keeping Port A as digital.
This is a limitation of the PIC hardware. You will have to re-design
your external circuit so it will work with the Port A and Port E settings
that are listed in the data sheet. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Aug 27, 2004 8:20 am |
|
|
Are you trying to use the TC74 in position U5 on the PICdem2 plus board? |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Fri Aug 27, 2004 9:36 am |
|
|
I add more thermistors into the demo board, and I also
add a low voltage detector circuit to the demo board to monitor the
9V battery. I run out of Analog I/O due to RA1 - RA3 tied to
the LCD on the demo board. That's why I try to use PORT E. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Aug 27, 2004 10:21 am |
|
|
The best thing to do is to download the spec sheet, from Microchip, and look what configurations are possible. From what I could see if you want to use AN5, AN6 or AN7 (PINS RE0, RE1 and RE2) all of PortA will need to be set as analog pins as well.
Ronald |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Aug 29, 2004 10:39 am |
|
|
Here is a hint:
A pin can be an analog input in one part of the code and an output in another part of the code provided the changing doesn't affect the LCD. |
|
|
|