View previous topic :: View next topic |
Author |
Message |
John Morley
Joined: 09 Aug 2004 Posts: 97
|
Selecting Vref on PIC12F675 |
Posted: Tue Oct 19, 2004 11:26 am |
|
|
Hi All,
I am trying to use analog inputs AN0 and AN2 on a PIC12F675 device. I also want to use a voltage reference connected to the Vref input. The header file for this device says that I can OR constants used with the SETUP_ADC_PORTS function, but this does not seem to be working correctly. Both analog inputs are working properly, but the problem is that the PIC seems to be using Vdd (+5V) for Vref instead of my 2.5V reference. Here is the new constant I created in the header file:
Code: |
#define AN0_AN2_VREF 0x4007 //| GP0 GP2 Vref
|
Here is the original header file:
Code: |
// Constants used in SETUP_ADC_PORTS() are: (These may be ORed together)
#define NO_ANALOGS 0
#define ALL_ANALOG 15 //| GP0 GP1 GP2 GP4
#define AN0_ANALOG 1 //| GP0
#define AN1_ANALOG 2 //| GP1
#define AN2_ANALOG 4 //| GP2
#define AN3_ANALOG 8 //| GP4
#define VREF 0x4002
#define VSS_VDD 0x0000
#define VSS_VREF 0x4002 //| Range 0-Vref
|
The .lst output seems to be setting the correct bit in the ADCON0 register to select Vref, so I'm not sure where to look next. Any ideas?
Thanks! _________________ John Morley |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2004 11:39 am |
|
|
Post the exact line of code that you're trying to use with the
setup_adc_ports() function, and post the version of your compiler. |
|
|
John Morley
Joined: 09 Aug 2004 Posts: 97
|
|
Posted: Tue Oct 19, 2004 12:36 pm |
|
|
Hi PCM,
Sorry, I should have included that information the first time! My compiler (PCM) is version 3.162. Here is the code that sets up and reads the analog inputs:
Code: |
setup_adc_ports(AN0_AN2_VREF);
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel(Temp_Input);
delay_ms(150); // Allow the channel to be aquired
TValue=read_adc();
delay_ms(10); // delay for the reading to be taken
set_adc_channel(Voltage_Input);
delay_ms(150); // Allow the channel to be aquired
VValue=read_adc();
delay_ms(10); // delay for the reading to be taken
|
Thanks! _________________ John Morley |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2004 1:22 pm |
|
|
There appears to be a mistake in the 12F675.H file for PCM vs. 3.162.
The following two lines are wrong.
Code: | #define VREF 0x4002
#define VSS_VREF 0x4002 //| Range 0-Vref |
They should be:
Code: | #define VREF 0x4000
#define VSS_VREF 0x4000 //| Range 0-Vref |
|
|
|
|