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 CCS Technical Support

Selecting Vref on PIC12F675

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



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

Selecting Vref on PIC12F675
PostPosted: Tue Oct 19, 2004 11:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 19, 2004 11:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 19, 2004 12:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 19, 2004 1:22 pm     Reply with quote

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
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