Problem with keil C code for interfacing 8051 to AD7715

Status
Not open for further replies.

7rots51

Advanced Member level 4
Joined
May 17, 2002
Messages
1,183
Helped
25
Reputation
50
Reaction score
12
Trophy points
1,318
Activity points
9,636
@d7715 problem

I wrote this ke**il c c0de for interfacing 8o51 to @D7715 ,a 16 bit sigm@ delt@ c0nverter from anal0g devices.

But It works good for several hours and I can get data from ADC,But suddenly the ADC does not give correct data it only gives 0x0000 code on any analog input.

I do not know what is the problem ? Is it noise? PCB layout? Lost sequence of serial communication?Please help me for solving this problems with sigmadelta c0nverters.

Regards



// This module provides an interface to an AD*7715.(for Interfacing AD*7715 to 8051)
//
//*******************************************************************************************************

//*******************************************************************************************************
// INCLUDE FILES
//*******************************************************************************************************
#include "REG52.h"

//*********************************************************************************************************
// I/O PINS
//*******************************************************************************************************
sbit CS = P1^2; // CS PIN of the ADC
sbit SCLK = P1^3; // SCLK PIN of the ADC
sbit DIN = P1^4; // DIN PIN of the ADC
sbit DOUT = P1^5; // DOUT PIN of the ADC

//*******************************************************************************************************
// LOCAL FUNCTION PROTOTYPES
//*******************************************************************************************************
void ADC_WrReg(unsigned char shift8);
unsigned char ADC_RdReg(void);
unsigned int ADC_Read(void);
void ADC_DataReady(void);

//*******************************************************************************************************
// FUNCTION PROTOTYPES(API FUNCTIONS)
//*******************************************************************************************************
void ADC_Init(void);
unsigned int ADC_Sample(void);

//*******************************************************************************************************
// WRITE TO A REGISTER
//
// Description : A byte is written to the AD7715 register
// Arguments : 'shift8' a byte that is written to register
// Returns : none
//*******************************************************************************************************
void ADC_WrReg(unsigned char shift8)
{
unsigned char i;

CS = 0;
for( i = 0 ; i < 8 ; i++ )
{
SCLK = 0;
if((shift8 & 0x80) == 0x80)
{
DIN = 1;
}
else
{
DIN = 0;
}
SCLK = 1;
shift8 = shift8 << 1;
}
CS = 1;
}

//*******************************************************************************************************
// READ A REGISTER
//
// Description : This function can read the content of a register.
// Arguments : none
// Returns : 'shift8' This the value of that register
//*******************************************************************************************************
unsigned char ADC_RdReg(void)
{
unsigned char i;
unsigned char shift8;

CS = 0;
shift8 = 0;
for( i = 0 ; i < 8 ; i++ )
{
SCLK = 0;
shift8 = shift8 << 1;
shift8 = shift8 & 0xfe;
if(DOUT)
{
shift8 = shift8 | 0x01;
}
SCLK = 1;
}
CS = 1;
return shift8;
}

//*******************************************************************************************************
// READ ADC DATA REGISTER
//
// Description : This function reads the adc data register
// Arguments : none
// Returns : 'sample' The value of data register is returned
//*******************************************************************************************************
unsigned int ADC_Read(void)
{
unsigned char i;
unsigned int sample;

CS = 0;
sample = 0;
for( i = 0 ; i < 16 ; i++ )
{
SCLK = 0;
sample = sample << 1;
sample = sample & 0xfffe;
if(DOUT)
{
sample = sample | 0x0001;
}
SCLK = 1;
}
CS = 1;
return sample;
}

//*******************************************************************************************************
// DRDY FLAG CHECK
//
// Description : Reads the status register and check for DRDY goes low condition
// Arguments : none
// Returns : none
//*******************************************************************************************************
void ADC_DataReady(void)
{
unsigned char adcstatus;

do{
ADC_WrReg(0x08); // Set the gain to 1,standby off,set the next operation as read of the status register
adcstatus = ADC_RdReg(); // Read statis register
}while( (adcstatus & 0x80) == 0x00); // check that is DRDY is one?if no then loop here

do{
ADC_WrReg(0x08); // Set the gain to 1,standby off,set the next operation as read of the status register
adcstatus = ADC_RdReg(); // Read statis register
}while( (adcstatus & 0x80) == 0x80); // check that is DRDY is one?if yes then loop here
}

//*******************************************************************************************************
// INITIALIZE THE AD7715
//
// Description : This is for ADC initialization (calibration and setup)
// Arguments : none
// Returns : none
//*******************************************************************************************************
void ADC_Init(void)
{
CS = 1;
SCLK = 1;
DIN = 1;
DOUT = 1;
ADC_WrReg(0x10); // Set the gain to 1,standby off,set the next operation as write to the setup register
ADC_WrReg(0x66); //set unipolar mode ,buffer on,no filter sync,confirm clock as 2.4576,set output rate to
//50Hz and do a self calibration
ADC_DataReady();
}

//*******************************************************************************************************
// GET ONE SAMPLE
//
// Description : This function reads one sample from ADC
// Arguments : none
// Returns : 'sample' A sampled value by ADC is returned
//*******************************************************************************************************
unsigned int ADC_Sample(void)
{
unsigned int sample;

ADC_DataReady(); // Check DRDY flag ,if it is zero then data is ready
ADC_WrReg(0x38); // Set the gain to 1,standby off,set the next operation as read of the data register
sample = ADC_Read(); // Read the ADC data register
return sample;
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…