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

16F88 ADC Driver for vs. 3.155

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

16F88 ADC Driver for vs. 3.155
PostPosted: Fri Jun 15, 2012 7:35 am     Reply with quote

Hi all,

I purchased yesterday PCM 4.132 (yeih!) since I've been using 3.155 since forever and its wasn't cutting it anymore...

In the thread below I mentioned some ADC problems I was having. My .H file was not right, the defined constants were wrong, the ADC functions were not working in general... except for read_adc() as far as I could tell.

http://www.ccsinfo.com/forum/viewtopic.php?t=48414

So I started to write my own ADC functions doing that would set/clear the required bits...

Since I now have a new compiler I don't quite need my "ADC driver" so I figured I would post it for educational purposes for others...

IT IS NOT COMPLETE - - - But it might help others. most of the functions work as far as I can tell... I got the new compiler before i got to writing a new

Read_ADC();
Power_ADC();

and others...

It would be awesome if someone finished it just for _Reference_ purposes.

I didn't post it in the library... since its not fully tested or finished... i don't think many people need this anyways...

So here it is:
Code:

#define VDD_VSS         0x00         // V+ to GND
#define VDD_VrefN       0x10         // V+ to Vref-
#define VRefP_VSS       0x20         // Vref+ to GND
#define VRefP_VrefN     0x30         // Vref+ to Vref-

#define EIGHT       0x00 //Justified
#define TEN         0x80 //Justified

#Byte ANSEL = 0x9B
#Byte ADCON0 = 0x1F
#Byte ADCON1 = 0x9F

void ADC_Resolution(int);
void ADC_Clock_Setup(int);
void ADC_Ports_Setup(int);
void ADC_Voltage_Ref(int);
void ADC_Select_Channel(int);

//--------------ADC_Ports_Setup-----------------//
// Enables the selected ADC Ports
// Uses Constants in standard .H file OR'ed
//----------------------------------------------//
void ADC_Ports_Setup(int ports)
{
   ANSEL=(ANSEL & 0x00)|ports;
}

//---------------ADC_Resolution-----------------//
// Sets the Resolution (Left or right Justified)
// Uses Constants Defined on THIS FILE
//----------------------------------------------//
void ADC_Resolution(int resolution)
{
   ADCON1=(ADCON1 & 0x7F) | resolution;
}

//--------------ADC_Clock_Setup-----------------//
// ADC conversion clock selection
// Uses Constants in standard .H
//----------------------------------------------//
void ADC_Clock_Setup(int clock)
{
   ADCON0=(ADCON0&0x3F)|clock;
}

//--------------ADC_Voltage_Ref-----------------//
// Selects the Voltage References
// Uses Constants Defined on THIS FILE
// Defined added but commented to .H file
//----------------------------------------------//
void ADC_Voltage_Ref(int ref)
{
   ADCON1=(ADCON1 & 0xC0)|ref;
}

//-------------ADC_Select_Channel---------------//
// Selects the ADC channel to sample
// Channel Values 0 to 6
//----------------------------------------------//
void ADC_Select_Channel(int channel)
{
if(channel==0)
ADCON0= ADCON0 & 0xC7;
if(channel==1)
ADCON0= (ADCON0 & 0xC7)|0x08;
if(channel==2)
ADCON0= (ADCON0 & 0xC7)|0x10;
if(channel==3)
ADCON0= (ADCON0 & 0xC7)|0x18;
if(channel==4)
ADCON0= (ADCON0 & 0xC7)|0x20;
if(channel==5)
ADCON0= (ADCON0 & 0xC7)|0x28;
if(channel==6)
ADCON0= (ADCON0 & 0xC7)|0x30;
}


EDIT:
I should clarify this was intended to be used with a 16F88.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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