+ Reply to Thread
Results 1 to 2 of 2

Thread: Stragling to read ADC value from AD7794

  1. #1
    mohanchandra Newbie
    Join Date
    Mar 2009
    Posts
    11

    Default Stragling to read ADC value from AD7794

    Hi
    I am interfaced ADU812 with AD7794.Controller and ADC are communicating
    properly.I am reading status of ADC register.

    In this register, RDY (7 bit of STATUS REGISTER) bit always high.
    while(1)
    {
    SPI_SendAdc(CR_STATUSREG); //Read Status of Register
    send_bit_serial(status=SPI_ReadADC());
    send_byte('C');
    NextLine();
    if(!(status&0x80))
    break;
    }
    or
    SPI_SendAdc(CR_DATA_RD);//
    while(RDY_ADC==1);//wait till RDY_ADC=0
    Problem: RDY_ADC pin(MISO) it is continously high. How we know completion of conversion



    Anybody give me a solution for this problem and also if i get ADC value then
    how i convert this adc to normal temparature.(V ref: 1.7v internal reference voltage).



    I am waiting for your positve reply

    Regards
    Mohanchandra


    I am trying to read the internal temparature value.Code is pasted below


    sbit ADC_CHIP_SELECT = P0^0 ;
    sbit RDY_ADC = P3^3;
    #define CS_LOW ADC_CHIP_SELECT = 0;
    #define CS_HIGH ADC_CHIP_SELECT= 1;
    #define CR_MODE_WR 0x08 //00001000
    #define CR_CONFIG_WR 0x10 //00010000
    #define CR_DATA_RD 0x5C //01011000//single conversion read
    #define MODEREG_HIGH 0x20 //mode register Sinle conversion.64KHz internal clock
    #define MODEREG_LOW 0x10
    #define CONFIGREG_HIGH 0x10 //Configuration register,unipolar with 1.17 ref voltage,channel
    #define CONFIGREG_LOW 0x86//temp sensor
    #define CR_STATUSREG 0x40 //01000000
    void main()
    {
    unsigned int i;
    unsigned char ucCount=5,status;
    serial_init();
    Spi_Initialization();
    while((ucCount--)>1)
    {
    P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x00;
    for(i=0;i<20000;i++);
    P0 = 0xFF; P1 = 0xFF; P2 = 0xFF; P3 = 0xFF;
    for(i=0;i<20000;i++);
    send_byte('A');
    }
    //=========================Writing operation====================
    CS_LOW; //enable
    for(i=0;i<1000;i++);
    SPI_SendAdc(CR_MODE_WR); //Mode register
    SPI_SendAdc(MODEREG_HIGH);
    SPI_SendAdc(MODEREG_LOW);

    SPI_SendAdc(CR_CONFIG_WR); //Configuration register
    SPI_SendAdc(CONFIGREG_HIGH);
    SPI_SendAdc(CONFIGREG_LOW);

    CS_HIGH; //disable
    for(i=0;i<10000;i++);
    //=========================Reading operation====================
    //Read mode register
    while(1)
    {
    CS_LOW; //enable
    for(i=0;i<1000;i++);
    /*while(1)
    {
    SPI_SendAdc(CR_STATUSREG); //Read Status of Register
    send_bit_serial(status=SPI_ReadADC());
    send_byte('C');
    NextLine();
    if(!(status&0x80))
    break;
    }*/
    //Dispaly data in NextLine
    //================================================== ========
    SPI_SendAdc(CR_DATA_RD);
    while(RDY_ADC==1);//wait till RDY_ADC=0

    send_bit_serial(SPI_ReadADC()); //24 bit adc data
    send_bit_serial(SPI_ReadADC());
    send_bit_serial(SPI_ReadADC());
    CS_HIGH; //Disable
    send_byte('B');
    NextLine(); //Dispaly data in NextLine
    for(i=0;i<10000;i++);
    }

    }
    //================================================== ====================

    void serial_init()
    {
    TMOD=0X20; //Timer 1....Mode 2...Auto Reload
    TH1=0XFD; //Baud Rate 9600 FD
    SCON=0X50; //Mode 1..8 bit data,..1 stop bit,..1 start bit
    TR1=1;
    RI=0;
    TI=0;
    }

    void send_byte(unsigned char add)
    {
    SBUF=add;
    while(TI==0);
    TI=0;
    }
    void Spi_Initialization()
    {
    SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0

    }
    //Next line dispaly
    void NextLine()
    {
    send_byte(0x0D);
    send_byte(0x0A);
    }
    //Send data to ADC device throug SPI Communication Protocal
    void SPI_SendAdc(unsigned char SPI_DATA)
    {
    ISPI=0; //cler the flagh
    SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
    while(ISPI==0); //wait till flag will set
    ISPI=0;

    }
    //Read data from ADC
    unsigned char SPI_ReadADC()
    {
    unsigned char ucData=0;
    ISPI=0; //cler the flagh
    SPIDAT=0; //load the 8 bit data to SPI data register
    while(ISPI==0); //wait till flag will set
    ucData=SPIDAT;
    return(ucData);
    }
    //send bitwise digital data to serial
    void send_bit_serial(unsigned char ucData)
    {
    unsigned char ucCount=0;
    for(ucCount=0;ucCount<8;ucCount++)
    {
    if((ucData<<ucCount)&0x80)
    send_byte(0x31);
    else
    send_byte(0x30);
    }

    }
    Last edited by mohanchandra; 15th June 2009 at 06:41 AM. Reason: Not proper


  2. #2
    AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent AtomSoft Excellent
    Join Date
    Feb 2008
    Location
    Brooklyn, NY US
    Posts
    3,744

    Default

    Hey i know nothing of that controller but this seem ODD... why have 2 different SPI type functions. I think this one below should be fine but the one below it .. how does it send data through SPI?
    Code:
    void send_byte(unsigned char add)
    {
    SBUF=add;
    while(TI==0);
    TI=0;
    }
    void Spi_Initialization()
    {
    SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0
    
    Code:
    //Send data to ADC device throug SPI Communication Protocal
    void SPI_SendAdc(unsigned char SPI_DATA)
    {
    ISPI=0; //cler the flagh
    SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
    while(ISPI==0); //wait till flag will set
    ISPI=0;
    
    }
    
    Maybe you should send data through the first one only?
    also you are aware that :

    send_bit_serial(status=SPI_ReadADC());

    is sending 8 bytes rights? (not bits)
    AtomSofts eBay Store
    AtomSoftTech: C18 TIPS & TRICKS v9 PDF

    My Name: Jason Lopez
    My BLOG | My YouTube Videos!
    My Favorite Store:
    dipmicro Electronics
    Trading and Selling...? Check out Dipmicro Trading/Selling Forum:
    Electronic Components & Tools Exchange

+ Reply to Thread

Similar Threads

  1. how can i read NTC?
    By Hesam Kamalan in forum General Electronics Chat
    Replies: 3
    Latest: 6th June 2008, 08:43 PM
  2. How To Read This
    By codan in forum General Electronics Chat
    Replies: 24
    Latest: 26th April 2008, 04:58 PM
  3. How to read from the ADC port?
    By Lac in forum Micro Controllers
    Replies: 6
    Latest: 11th August 2006, 07:59 PM
  4. Need for Help in vb.net..... please read
    By cena in forum Micro Controllers
    Replies: 9
    Latest: 14th April 2006, 09:32 AM
  5. PLEASE READ
    By sia in forum Electronic Projects Design/Ideas/Reviews
    Replies: 14
    Latest: 14th October 2005, 09:46 AM

Tags for this Thread