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

driver for ADS8317 ADS8320 and related 16Bit AD conversion

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



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

driver for ADS8317 ADS8320 and related 16Bit AD conversion
PostPosted: Sat Jun 05, 2010 7:09 pm     Reply with quote

Code:

//
//   generic driver for ADS83xx serial 16 bit A/D converters
//   inc ADS8317, ADS8320,   x18, x21  and many other 8 pin similar parts
//   both signed 16bit and unsigned types
//    Don Person   agw1@nycap.rr.com  GentleWind Inc.
//
//   define your control pins here - 3 are required
#define ADCstart  PIN_E0    //       
#define ADCdata   PIN_E1    //
#define ADCclock  PIN_E2    //
//     if using fast_io for E    ( suggested - I do ) then set_tris_E(0b11111010)
//     NB: this assumes you are using a WEAK resistor pullup on
//        the designated  ADCdata  PIC port pin - even if an external resistor to Vcc
//   
//   This gets one sample 16 bit unsigned word from serial A/D
//

unsigned int16  ADS83xx(void){  // SERIAL A/D  ADS8317,20 and many others
     unsigned int16 adcresult=0;
     unsigned int8 i;
     adcresult=0;
     output_HIGH(ADCclock);      delay_cycles(4);
    //        Start a conversion with a lo pulse on ADC_CONVERT
    output_low (ADCstart); // LOWER NOT-CS
   //                    NOW CYCLE TILL WE GET THE ACTIVE FIRST BIT ZERO READY
   //                    ADCclock is clock DEFLT LOW
   delay_cycles(1);     // not  needed on master clock speed s below 10 mhz
   output_LOW(ADCclock); //  clock low
   delay_cycles(1);     // not  needed on master clock speed s below 10 mhz

   for ( i = 0 ; i < 8 ; i++ ){
     output_HIGH(ADCclock);   
     IF ( !input(ADCdata)) BREAK;
     ELSE output_LOW(ADCclock);
   }
   output_low(ADCclock);   // insure lo clock for a 'break'  on HI state
   //                                           now read data
  for (i=0;i<16;i++){
     output_high(ADCclock);        //    now after rising edge
     adcresult |= input(ADCdata); //   OR input pin with 16bit int
     output_low(ADCclock);   // produce a new lo-to-high clock
     if (i !=15) adcresult=adcresult<<1;         // and shift that bit along toward MSB
  }
  //    leave ready for the  next A/D  read CYCLE
   OUTPUT_HIGH(ADCstart); // adcstart SHUT OFF CONVERTER
  return (ADCresult);
}

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