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

Help in AD7714 Driver

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



Joined: 30 Jan 2007
Posts: 56
Location: Viana do Castelo - Portugal

View user's profile Send private message

Help in AD7714 Driver
PostPosted: Fri Feb 23, 2007 11:27 am     Reply with quote

Hi

I need make the driver for AD7714, for school project.

I have change the driver of AD7705 for control AD7714.
Is the first time i make a driver for SPI.

Driver:

Code:

// AD7714.c
//// Driver routines for the AD7714 chip
//Assuming a 4.9152 crystal ocsillator is used between MCLK IN and MCLK OUT

//connection pins to the PIC
#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_B6


//Operation modes (MD1, MD0 bits in Setup Register)
#define ADC_NORMAL 0x00
#define ADC_SELF 0x20
#define ADC_ZERO_SCALE 0x40
#define ADC_FULL_SCALE 0x60

//Gain settings (G2, G1, G0 bits in Setup Register)
#define ADC_GAIN_1      0x00
#define ADC_GAIN_2      0x04
#define ADC_GAIN_4      0x08
#define ADC_GAIN_8      0x0C
#define ADC_GAIN_16     0x10
#define ADC_GAIN_32     0x14
#define ADC_GAIN_64     0x18
#define ADC_GAIN_128    0x1C

//// burnout  corrente
#define ADC_BURNOUT_ON   0x02
#define ADC_BURNOUT_OFF  0x00

//Fsync (FSYNC bit in Setup Register)
#define ADC_FSYNC_RESET 0x01
#define ADC_FSYNC_START 0x00
// Function prototypes
void adc_init();
void setup_adc_device(int mode, int gain, int buffer, int fsync);
void write_adc_byte(BYTE data);
long read_adc_word();
long read_adc_value();


//initialization routine
void adc_init()
{
   output_low(ADC_RESET);    // Reset all ADC registers to their default state.
   delay_ms(10);
   output_high(ADC_RESET);

   // See Fig. 17 of AD7714 datsheet
   output_high(ADC_CLK);     // CLK line at high state
   output_high(ADC_CS);      // CS line at high state

   setup_adc_device(ADC_SELF,ADC_GAIN_1,ADC_BURNOUT_ON,ADC_FSYNC_START);
   delay_ms(10);
}


//setup the device paramaters
void setup_adc_device(int mode, int gain,int buffer, int fsync)
{
   int8 temp1;

     write_adc_byte( 0x10 ); //Communications Register set to write of Setup Register
   temp1 = mode|gain|buffer|fsync;
   write_adc_byte( temp1 ); //Setup Register info here
}


void write_adc_byte(BYTE data)
{
   int8 i;

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


long read_adc_word()
{
   int8 i;
   long data;

   output_low(ADC_CS);
   for(i=0; i<24; i++)
   {
      output_low(ADC_CLK);
      delay_us(50);
      shift_left(&data,2,input(ADC_DO));
      output_high(ADC_CLK);
      delay_us(50);
   }
   output_high(ADC_CS);
   return data;
}


// read an adc value from the channel 1
long read_adc_value()
{
   long value;
   while ( input(ADC_DRDY) ); // Loop until data is ready

   write_adc_byte(0x58);   //communications register set to read AIN1

   value=read_adc_word();

   return value;
}


Exemple:

Code:

#include "lcd.c"
#include <ad7714.c>

void main (void)
{
   int dig=0;
   long value;
   TRISD=0b00001000;
   TRISB=0b10000111;

   lcd_init();
   adc_init();

   printf(lcd_putc,"\f ola");
   delay_ms(2000);
   printf(lcd_putc,"\f");

    while(1)
    {
      value=read_adc_value();  // Read AIN1 inputs
      delay_ms(500);
      printf(lcd_putc,"\f %lu ",value);
    }
}


I have only configuration one channel. When i try read the adc the function stay in loop until data is ready.

Someone can help-me?

Thanks
bloureiro



Joined: 26 Feb 2007
Posts: 6

View user's profile Send private message

PostPosted: Mon Feb 26, 2007 5:12 am     Reply with quote

Hi

Can you see in http://www.mcu-bg.com/mcu_site/viewtopic.php?p=16057#16057
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