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

AD7714

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
bloureiro



Joined: 26 Feb 2007
Posts: 6

View user's profile Send private message

AD7714
PostPosted: Thu Oct 04, 2007 8:43 am     Reply with quote

Hi make this driver for a multi-channel acquisitions and works fine.



Code:

//*************************************************************
// Routines for AD7714
// write_adc_byte()
// adc_init()
// read_adc_word()
// read_adc_value()
//*************************************************************

//configure PIC ports
#define ADC_DRDY  PIN_B1
#define ADC_DO    PIN_B2
#define ADC_DI    PIN_B3
#define ADC_RESET PIN_B4
#define ADC_CS    PIN_B5
#define ADC_CLK   PIN_B0

void write_adc_byte(int data)
{
   int i;
   output_low(ADC_CS);
   for(i=1;i<=8;++i)
   {
      output_low(ADC_CLK);
      output_bit(ADC_DI, shift_left(&data,1,0));
      output_high(ADC_CLK);
   }
   output_high(ADC_CS);
}

void adc_init(int8 filterH,int8 filterL)
{
   output_low(ADC_RESET);
   output_high(ADC_CLK);
   output_high(ADC_CS);       //Set high to AD7714 chip select low pin
   output_high(ADC_RESET);    //Set high to AD7714 reset low pin
   delay_ms(1000);
   write_adc_byte(0x27);      //to com register, channel & filter Hi  antes 24--------27 datasheet
   write_adc_byte(filterH);   //to filter hi register  0xCF  ------------------------ 4F datasheet
   write_adc_byte(0x37);      //to com.register, channel & filter low  antes 30-------37 datasheet
   write_adc_byte(filterL);   //to filter low register  00 antes----------------------A0 datasheet
   
 
   write_adc_byte(0x10);         //to com register, channel & mod register
   write_adc_byte(0x20);         //to mod register, self test
   while ( !input(ADC_DRDY) );
   while ( input(ADC_DRDY) );
   write_adc_byte(0x11);         //to com register, channel & mod register
   write_adc_byte(0x20);         //to mod register, self test
   while ( !input(ADC_DRDY) );
   while ( input(ADC_DRDY) );
   write_adc_byte(0x12);         //to com register, channel & mod register
   write_adc_byte(0x20);         //to mod register, self test
   while ( !input(ADC_DRDY) );
   while ( input(ADC_DRDY) );
}



int32 read_adc_word()
{
   int i;
   int32 data;
   output_low(ADC_CS);
   for(i=1;i<=24;++i)
   {
      output_low(ADC_CLK);
      output_high(ADC_CLK);
      shift_left(&data,3,input(ADC_DO));
   }
   output_high(ADC_CS);
   return data;
}



int32 read_adc_value(int canal)
{
   int32 value;
   
   switch(canal)
   {
      case 1:
      write_adc_byte(0x58);         
      break;

      case 2:
      write_adc_byte(0x59);         
      break;

      case 3:
      write_adc_byte(0x5A);break;

      case 4:
      write_adc_byte(0x5B);break;

      case 5:
      write_adc_byte(0x5E);break;
   }
   
   while ( !input(ADC_DRDY) );
   while ( input(ADC_DRDY) );
   
   value=read_adc_word();

   return value;
}

float convert_to_volts(int32 temp){
   return (float)temp*0.0000000745;//ref 1,25V
}




To chose the sampling frequency you will need write the registers of filter
in the adc_init(int8 filterH,int8 filterL).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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