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 support@ccsinfo.com

AD7705 - CODICE FUNZIONANTE

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



Joined: 07 Dec 2005
Posts: 10
Location: Italy

View user's profile Send private message

AD7705 - CODICE FUNZIONANTE
PostPosted: Thu Feb 02, 2006 10:34 am     Reply with quote

//connection pins to the PIC
#define ADC_DRDY PIN_B0
#define ADC_CS PIN_B5
#define ADC_DI PIN_C5
#define ADC_DO PIN_C4
#define ADC_CLK PIN_C3

//Operation modes
#define ADC_NORMAL 0x00
#define ADC_SELF 0x40
#define ADC_ZERO_SCALE 0x80
#define ADC_FULL_SCALE 0xC0
//Gain settings
#define ADC_GAIN_1 0x00
#define ADC_GAIN_2 0x08
#define ADC_GAIN_4 0x10
#define ADC_GAIN_8 0x18
#define ADC_GAIN_16 0x20
#define ADC_GAIN_32 0x28
#define ADC_GAIN_64 0x30
#define ADC_GAIN_128 0x38
//Polar operations
#define ADC_BIPOLAR 0x00
#define ADC_UNIPOLAR 0x04
//Buffer mode
#define ADC_BUFFER_OFF 0x00
#define ADC_BUFFER_ON 0x02
//fsync
#define ADC_FSYNC_RESET 0x01
#define ADC_FSYNC_START 0x00

//update rates
#define ADC_20 0x00
#define ADC_25 0x01
#define ADC_100 0x02
#define ADC_200 0x03
#define ADC_50 0x04//no
#define ADC_60 0x05//no
#define ADC_250 0x06//no
#define ADC_500 0x07//no
//master clock
#define ADC_MASTERCLK_ENABLE 0x00
#define ADC_MASTERCLK_DISABLE 0x10
//clock divider
#define ADC_CLKDIVIDER_ON 0x08
#define ADC_CLKDIVIDER_OFF 0x00

#define ADC_CHANNEL1 0x00
#define ADC_CHANNEL2 0x01

void write_adc_byte(BYTE data)
{
BYTE i;
//output_high(ADC_CLK);//modif
output_low(ADC_CS);
spi_write(data);
output_high(ADC_CS);
}


long int read_adc_word()
{
BYTE i;
int data_low,data_high;
int16 data;
//output_high(ADC_CLK);//modif
output_low(ADC_CS);
data_high=spi_read(0);
data_low =spi_read(0);
output_high(ADC_CS);
data=make16(data_high,data_low);
return data;
}


//setup register settings
void adc7705_setup_setupregister(int adcmode, int gainsetting, int operation, int buffersetting, int fsync, int channel)
{
write_adc_byte( 0x10|channel );//Communications Register set to write of setup register
write_adc_byte( adcmode|gainsetting|operation|buffersetting|fsync );//Setup Register info here
}

//clock regster settings
void adc7705_setup_clockregister(int masterclock, int clockdivider, int clock_filterselection, int channel)
{
write_adc_byte( 0x20|channel );//Communications Register set to write of clock register
write_adc_byte( 0x00|masterclock|clockdivider|clock_filterselection );//Clock Register info here
}

//init routine
void adc7705_init()
{
adc7705_setup_setupregister(ADC_SELF,ADC_GAIN_1,ADC_UNIPOLAR,ADC_BUFFER_ON,ADC_FSYNC_START,ADC_CHANNEL1);
adc7705_setup_clockregister(ADC_MASTERCLK_ENABLE,ADC_CLKDIVIDER_ON,ADC_100,ADC_CHANNEL1);
delay_ms(3000);
adc7705_setup_setupregister(ADC_SELF,ADC_GAIN_1,ADC_UNIPOLAR,ADC_BUFFER_ON,ADC_FSYNC_START,ADC_CHANNEL2);
adc7705_setup_clockregister(ADC_MASTERCLK_ENABLE,ADC_CLKDIVIDER_ON,ADC_100,ADC_CHANNEL2);
delay_ms(3000);
}


//read an adc value from the specified channel
long int adc7705_read_value(int ch)
{
long int value;
while (!input(ADC_DRDY) );
if(ch==1) {write_adc_byte(0x38);//communications register set to read of data register of channel 1
//output_high(TX_ENABLE);printf("\r\n\write0x38\r\n");output_low(TX_ENABLE);
}
if(ch==2) {write_adc_byte(0x39);//communications register set to read of data register of channel 2
//output_high(TX_ENABLE);printf("\r\n\write0x39\r\n");output_low(TX_ENABLE);
}
while ( input(ADC_DRDY) );
value=read_adc_word();
return value;
}

//disable the a/d conversion
void adc7705_disable()
{
write_adc_byte( 0x20 );//Communications Register set to write of clock register
write_adc_byte( 0x10 );//Clock Register info here
}

//Convert the value read to volts
float adc7705_convert_to_volts(long data){
return ((float)data*2.5/0xffff);
}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 02, 2006 10:38 am     Reply with quote

1) What is the problem? Don't say "it doesn't work". Be SPECIFIC. What tests have you performed.
2) What PIC and which compiler version?
3) Use the Code button when posting code.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 02, 2006 1:39 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=25806
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