This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

problem in reading the digital count from ADS7825 in parallel mode

Other Parts Discussed in Thread: ADS7825, ADS8684A, ADS8684

Hi All,

I am interfacing ADS7825 to AT90USB1286 in Parallel mode please see below circuit diagram. But i can't read the correct data.

Can any one tried this successfully any sample code to read the data.

i have few questions, before giving the questions let me put my work details here.

1. I connected  two nos of 2.2uF/35V Tantalum Capacitors one on 6th pin to  ground and another is on  7th pin to ground.

2. I made CONTC=0 i.e. manual mode.

3. I am using AT90USB1286 MIcro controller to read the data.

4. I connected  AGND1, AGND2 and DGND to same ground(please see below circuit diagram).

5. I am giving 0 to 1.5V to ADC Channel 1 (i.e. AIN0 )for testing purpose only. But actually i will give +/-10v to all four channels

    of ADC.

6. I measured 2.502V at Vref to ground.

MY CODE is:

/**
** crystal frequency is 11.0592Mhz
** microcontroller is AT90USB1286
** programming tool Atmel studio 6.2
**/
 
#include <avr/io.h>
#include <math.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <string.h>
#include <inttypes.h>
 
 
#define F_CPU 11059200UL
#define cnstt 0
#define slope 3276.7
 
#define LCD_DPRT PORTA        // LCD DATA PORT
#define LCD_DDDR DDRA        // LCD DATA DDR
#define LCD_DPIN PINA        // LCD DATA PIN
#define KEY_PRT PORTE        // LCD DATA PORT
#define KEY_DDR DDRE        // LCD DATA DDR
#define KEY_PIN PINE        // LCD DATA PIN
 
 
#define LCD_RSOFF PORTD&=~(1<<PD5)
#define LCD_RSON PORTD|=(1<<PD5)
#define LCD_RWOFF PORTD&=~(1<<PD6)
#define LCD_RWON PORTD|=(1<<PD6)
#define LCD_EOFF PORTD&=~(1<<PD7)
#define LCD_EON PORTD|=(1<<PD7)
 
#define A_zeroOFF PORTD &=~(1<<PD0)                        // channel selection of adc  A0 is low
#define A_zeroON PORTD |=(1<<PD0)                        // channel selection of adc  A0 is high
 
#define A_oneOFF PORTD &=~(1<<PD1)                        // channel selection of adc  A1 is low
#define A_oneON PORTD |=(1<<PD1)                        // channel selection of adc  A1 is high
 
#define RC_OFF PORTD &=~(1<<PD2)
#define RC_ON PORTD |=(1<<PD2)
 
#define BYTE_MSB PORTD &=~(1<<PD4)
#define BYTE_LSB PORTD |=(1<<PD4)
 
//unsigned int readinput;
signed int msbbits,lsbbits;
signed int i,count,cnt;
double in;
char itmp[20];
                        
void lcd_chone();
void lcd_chtwo();
void lcd_chthree();
void lcd_chfour();
void adcinit_readdata();
void lcd_init();
void lcd_print(char * str);
void lcdCommand(unsigned char cmnd);
void lcdData(unsigned char data);
void lcd_gotoxy(unsigned char x, unsigned char y);

//********************************************* Main function starts from here *******************************************//
 
int main (void)
{
    unsigned char upperNibble, keyCode,i;
    unsigned int readinput;
    DDRB=0xFF;    
    DDRD=0xF7;
    DDRE=0x00;                                            
                                    
                                            
    msbbits=0;
    lsbbits=0;    
    cnt=0;                                                        
    count=0;
    in=0.0;
    readinput=0;
    
    
    lcd_init();                                            
    _delay_ms(50);
     lcdCommand(0x01)
    
    
    
     while(1)                                            
        {
            
        lcd_chone();adcinit_readdata();
        //lcd_chtwo();adcinit_readdata();
        //lcd_chthree();adcinit_readdata();
        //lcd_chfour();adcinit_readdata();
 
        }            
                    
        }            
      
              
 
    
      
//******************************* functions of ADC Channels 1,2,3,4 respectively**************************************//
        
void lcd_chone()                        
{
    CH1_LOW;
    //lcd_gotoxy(1,1);                            
    //lcd_print(" CH1 MEASURE");
    A_zeroOFF;                                    
    _delay_us(1);                                
    A_oneOFF;                                            
    
}
 
void lcd_chtwo()
{
    CH2_LOW;
    lcd_gotoxy(1,1);                            
    lcd_print(" CH2 MEASURE");
    A_zeroON;                                    
    _delay_us(1);                                
    A_oneOFF;                                    
}    
void lcd_chthree()
{
    CH3_LOW;
    lcd_gotoxy(1,1);                            
    lcd_print(" CH3 MEASURE");                
    A_zeroOFF;                                    
    _delay_us(1);                                
    A_oneON;                                    
}
void lcd_chfour()                                
{
    CH4_LOW;
    lcd_gotoxy(1,1);                                                        
    lcd_print(" CH4 MEASURE");
    A_zeroON;                                    
    _delay_us(1);                                
    A_oneON;                                    
}
 
 
 
 
 
 
//********************************************* LCD functions **************************************//
 
void lcdCommand(unsigned char cmnd)
{
    LCD_DPRT = cmnd;                
    LCD_RSOFF;                        
    LCD_RWOFF;                                
    LCD_EON;                                
    _delay_us(1);                    
    LCD_EOFF;                                
    _delay_us(100);
}
 
void lcdData(unsigned char data)
{
    LCD_DPRT = data;                
    LCD_RSON;                         
    LCD_RWOFF;                        
    LCD_EON;                       
    _delay_us(1);                    
    LCD_EOFF;                                
    _delay_us(100);
}
 
void lcd_init()
{
    LCD_DDDR = 0xFF;
    //LCD_CDDR = 0xFF;
    LCD_EOFF;                        
    _delay_us(2000);                
    lcdCommand(0x38);                
    lcdCommand(0x0E);                
    lcdCommand(0x01);                
    _delay_us(2000);                
    lcdCommand(0x06);                
}
 
void lcd_gotoxy(unsigned char x, unsigned char y)
{
    unsigned char firstCharAdr[]={0x80,0xC0,0x94,0xD4};
    lcdCommand(firstCharAdr[y-1]+x-1);                    
    _delay_us(100);
}
 
void lcd_print(char * str)
{
    unsigned char i=0;
    while(str[i]!=0)
    {
        lcdData(str[i]);
        i++;
    }
}
 
//*****************************  16-bit DATA transferring from ADC to MC Through Parallel Mode    *****************************//
 
    void adcinit_readdata()
    {
        RC_OFF;        // RC LOW
        _delay_us(5);    // delay up to 5 Micro seconds
        RC_ON;        // RC ON
        if(PIND & 0b00001000)    // if BUSY Pin goes high then the data is ready to accumulate
        {
            BYTE_MSB;    // BYTE=1
            msbbits=PINE;    // store the data available on PORTE into  msbbits. Here,  most MSB bits are available
            BYTE_LSB;    // Byte=0
            lsbbits=PINE;    // store the data available on PORTE into lsbbits. Here, Least LSB bits are available
            count=msbbits<<8;    // right shift the data 8 times                    
            count=count+lsbbits;    // now add count=count+lsbbits to get actual 16bit signed 2's complement digital value  
                                    
            in=(count-cnstt)/slope;    
            lcd_gotoxy(1,1);                        
            ltoa(count, itmp, 10);
            lcd_print(itmp);
            lcd_gotoxy(1,2);
            dtostrf(in,10,5,itmp);lcd_print(itmp);lcd_print("V     ");
            msbbits=0;                                
            lsbbits=0;                                        
            count=0;
            in=0.0;
            
                
        }
        else
        _delay_us(10);
        
    }

Therefore my problems are:

1. I am unable read the data from ADC.

2. Are the connections between AT90USB1286 to ADS7825 right?

3. Are there any mistakes in my code?

4. If I change the delay between RC_OFF to RC_ON   from 5micro seconds to 25micro seconds and above

(see  Case 2 below)  i am getting   strange data.

Case 1:                                                                                                          Case 2:

RC_OFF;        // RC LOW                                                         RC_OFF;        // RC LOW
 _delay_us(5);    // delay up to 5 Micro seconds                 _delay_us(25);    // delay up to 5 Micro seconds
RC_ON;        // RC ON                                                             RC_ON;        // RC ON

 for example, I f i give 1V as i/p signal to AIN0 of ADS7825 it should be give  digital count 3276 for +/-10V range.

But it doesn't give that value. it is giving a random value and that too value is changing continuously.

5. If i give the delay about 5 micro seconds (see Case 1), i am not getting any data.

please tell any one where i did mistake.

thank you in advance.

excuse me for bad english,


 

  • Hi B M S RAO, 

    Sorry for late response.

    Could you please let me know if you checked /BUSY signal output of the ADS7825? Can you please upload the scope screenshot for your digital signals(R/C,/BUSY,BYTE and data)? Actually there is a timing requirement on Convst Pulse Width as below, 0.04us ≤ t1 ≤ 12us, you are implementing 5ms or 25ms for conversion on R/C pin which is not correct, please reduce it and check /BUSY signal and data. 

    No significant error with your hardware connections between ADC and CPU, but It's a better practice to have a front-end buffer before ADC because the ADS7825 has switched-Capacitor input, your signal is a voltage divided with resistor from the power supply, this could lead to a settling problem.

    We have another SAR ADC, ADS8684/ADS8684A which is 16-bit, 500ksps, bipolar input up to +/-10V ADC with single +5V power supply, it integrates Analog Front-End (AFE) and high precision internal reference with low drift.

    www.ti.com/.../ADS8684

    Regards

    Dale Li

  • hi,

    thanks for the suggestions.

    i placed my total circuit on general purpose PCB.

    i did changes on my circuit that what you suggest me in the previous post.

    Now, i am able to read the the data with+/-20mV error( i knew that because of poor routing) up to 5V only.

    But, when i tried to give beyond 5V as input signal to the AIN0(channel one of ADC) it gives unexpected value please see below,

    I/P(V)                     digital count

    1                             3328(approx)

    2                             6654(approx)

    3                              9985(approx)

    4                             13300(approx)

    5                              15926(approx)

    6                              3328(approx)

    7                              6654(approx)

    8                              9985(approx)

    9                             13300(approx)

    10                          15926(approx)

    i followed the hardware recommendations which are specified in the datasheet.

    i put delay 150ms

    i want to give I/P signal range is -10V to 10V.

    see below cod of mine

    void adcinit_readdata()

    {

    RC_OFF;                                

    _delay_us(10);                      

    RC_ON;                                

    _NOP();

    _NOP();

    _delay_us(25);    

    BYTE_MSB;                            

    _NOP();

    _NOP();

    msbbits=PINE;                                      

    BYTE_LSB;                          

    _NOP();

    _NOP();

    lsbbits=PINE;                          

    count=msbbits<<8;                        

    count=count+lsbbits;                    

    lcd_gotoxy(1,1);

    lcd_print("Digital count");

    lcd_gotoxy(1,2);

    ltoa(count, i_tmp, 10);

    lcd_print(i_tmp);lcd_print("     ");

    msbbits=0;

    lsbbits=0;

    count=0;

    }

    please refer my scope screen shots of R/C and BUSY.

    i don't know where i did mistake.

    excuse me for bad english,

    B M S RAO