关于AD7689数据采集的问题

        大家好,我现在用TI的DSP28335通过SPI与AD7689通讯,读出的数据变化非常大,也没有规律(比如0,540,2048,3680,4,1024等等),AD7689配置寄存器是0xF104。请问哪位能指导一下,或者有没有程序参考一下,谢谢!

Parents
  • //Head files

    #include <ADuC7026.H>

    #include "functions.h"

     

    #define
    SET_CNV()                                       
    GP1DAT = (GP1DAT |
    0x00040000)           
    //P1.2->CNV             
    -- P3.40: Brown  -- A17

    #define
    CLR_CNV()                                       
    GP1DAT = (GP1DAT & 0xFFFBFFFF)

    #define
    SET_CS()                                           
    GP1DAT = (GP1DAT |
    0x00800000)           
    //

    #define
    CLR_CS()                                          
    GP1DAT = (GP1DAT &
    0xFF7FFFFF)           

    #define SET_SCK() GP1DAT = (GP1DAT | 0x00100000) //P1.4->SCK -- P3.38: White   -- A9

    #define
    CLR_SCK()                                        
    GP1DAT = (GP1DAT &
    0xFFEFFFFF)           

    #define
    MISO_BIT                                        
    (GP1DAT &
    0x00000020)                             
    //P1.5->MISO -- P3.35: Grey     -- B11

    #define
    SET_MOSI()                                     
    GP1DAT = (GP1DAT |
    0x00400000)           
    //P1.6->MOSI -- P3.34: Green

    #define
    CLR_MOSI()                                     
    GP1DAT = (GP1DAT & 0xFFBFFFFF)

     

    #define
    LED2_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFEFFFF)           
    //P4.0->LED2

    #define
    LED2_OFF()                                     
    GP4DAT = (GP4DAT | 0x00010000)

    #define
    LED3_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFDFFFF)           
    //P4.1->LED3

    #define
    LED3_OFF()                                     
    GP4DAT = (GP4DAT | 0x00020000)

    #define
    LED4_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFBFFFF)           
    //P4.2->LED4

    #define
    LED4_OFF()                                     
    GP4DAT = (GP4DAT | 0x00040000)

     

    volatile unsigned char
    Timer1_flag;         // Timer1 interrupt
    flag

    ///////////////////////////////////////////////////////////////////////////////////////////////////////

    void AD7689_gpiospiwrite_L14bitword(unsigned short
    data)           //CS low for
    reading 1 word from the first channel

    {

                 
    int i=0;

                 
    unsigned short temp=0;

                 
    temp = data;

    //Initial CNV=0, SCK=0

                 
    temp = temp << 2;

                 
    for (i=0;i<16;i++)

                 
    {

                                
    if(0x8000 == (temp & 0x8000))

                 
                                
    SET_MOSI();

                                
    else

                                               
    CLR_MOSI();

                                
    temp = temp << 1;

                                
    SET_SCK();           //rising
    edge for write in

                                
    CLR_SCK();

                 
    }

                 
    CLR_MOSI();                    
    //AD7689 SDI should be idle low

    }

     

    unsigned short AD7689_gpiospireadword_writeL14bitword(unsigned
    short data)    //CS low for reading 1 word from the first
    channel

    {

                 
    int i=0;

                 
    unsigned short temprev = 0, tempsend = 0;

    //CNV=0, SCK=0

                 
    tempsend = data;

                 
    tempsend = tempsend << 2;

                 
    for (i=0;i<14;i++)

                 
    {

                                
    temprev = temprev << 1;

                                
    if (MISO_BIT!=0)

                                               
    temprev = temprev + 1;

                                
    else

                                               
    ;

     

                                
    if(0x8000 == (tempsend & 0x8000))

                                               
    SET_MOSI();

                                
    else

                                               
    CLR_MOSI();

                                
    tempsend = tempsend << 1;

                                
    SET_SCK();

                                
    CLR_SCK();          //falling edge
    for MSB-1, ...

                                
    CLR_MOSI();       //MOSI idle low

                 
    }

                                
    for (i=14;i<16;i++)

                 
    {

                                
    temprev = temprev << 1;

                                
    if (MISO_BIT!=0)

                                               
    temprev = temprev + 1;

                                
    else

                                               
    ;

                                
    SET_SCK();

                                
    CLR_SCK();          //falling edge
    for MSB-1, ...

                 
    }

                 
    return temprev;

    }

     

    void AD7689_gpiospiread_word(unsigned char
    *data)        //CS low for reading 1 word from
    the first channel

    {

                 
    int i=0;

     

    //          
    CLR_CS();           
    //CS falling edge output first MSB

                 
    for (i=0;i<8;i++) //CNV falling for MSB

                 
    {

                                
    *data = (*data) << 1;

                                
    if (MISO_BIT!=0)

                                               
    *data = (*data)+1;

                                
    else

                                               
    ;

                                
    SET_SCK();           //

                                
    CLR_SCK();          //SCK falling
    edge for MSB-1, ...

                                
    delay1us(10);

                 
    }

                 
    data++;

                 
    for (i=0;i<8;i++)

                 
    {

                                
    *(data) = (*(data)) << 1;

                                
    if (MISO_BIT!=0)

                                               
    *(data) = (*(data))+1;

                                
    else

                                               
    ;

                                
    SET_SCK();                        
    //

                                
    CLR_SCK();          //intially low

                                
    delay1us(10);

                 
    }

    //          
    SET_CS();

                 
    data--;

    }

    ///////////////////////////////////////////////////////////////////////////////////////////

     

    void ADuC7026_Initiate(void)

    {

    /*         
    */

    }

                                

    void AD7689_Initiate(void)

    {

                                
    int i=0;

                                
    CLR_SCK();          //initially low

                                
    CLR_CNV();//intially high

                                
    //idle conv after power up

                                
    SET_CNV();

                                
    delay1us(10);      //delay 4us, tCONV > 2.2us for no
    BUSY Indicator

                                
    CLR_CNV();

                                
    //Configuration Register:

                                
    //[13] = 1: overwrite contents of register.

                                
    //[12:10] = 111: Unipolar, INx referenced to GND.

                                
    //[9:7] = 111: IN7

                                
    //[6] = 1: full BW.

                                
    //[5:3] = 110:External reference 5V, driver disabled, temperature disabled.

                                
    //[2:1] = 11 :scan from IN0 to CFG[9:7].

                                
    //[0] = 1:do not read back contents of configuration.

                                
    AD7689_gpiospiwrite_L14bitword(0x3FC7);//8 ch selected in sequencer, full bandwidth,
    external REF,

                                
    delay1us(10);

                                
    for (i=0;i<1;i++)  //delay one phase

                                
    {

                                               
    SET_CNV();

                                               
    delay1us(10);      //delay 4us, tCONV > 2.2us for
    no BUSY Indicator

                                               
    CLR_CNV();

                                               
    delay1us(10);

                                
    }

    }

     

    int main (void)

    {

    //          
    unsigned char HByte=0, LByte=0;

                 
    unsigned char combuf[4]={0};

                 
    unsigned long T1_LD=0;

                 
    unsigned long CNVNum = 0, convnum=0,convcount=0;

                 
    unsigned char
    adcbuf_2Byte[2]={0};          //1
    word

                 
    unsigned short adcrevbuf=0;

                 
    unsigned char CHNum = 8;

     

                 
    ADuC7026_Initiate();                                                  
    //ADuC7026 Initiation

                 
    AD7689_Initiate();

    /*** UART ***/

                 
    COMIEN0 =
    0x01;                                                                                      
    //Enable Receive Buffer Full Interrupt

                 
    IRQEN =
    0x00004000;                                                
                 
    // Enable UART interupt

     

                 
    while(1)

                 
    {

                                                              
    Intcount=0;

                                                              
    convcount=0x08;

                                                              
    convnum=CNVNum;

                                                              
    while (convnum)

                                                              
    {

                                                                             
    LED3_ON();

                                                                             
    LED4_ON();

                                                                             
    adcbuf_2Byte[0] = 0;

                                                                             
    adcbuf_2Byte[1] = 0;

                                                                             
    SET_CNV();

                                                                             
    delay1us(10);      //delay 4us, tCONV > 2.2us for
    no BUSY Indicator

                                                                             
    CLR_CNV();

                                                                                            
    if (convcount%CHNum==0)//IN0

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==1)//IN1

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==2)//IN2

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==3)//IN3

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==4)//IN4

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==5)//IN5

                                                                                            
    {

                                                              
                                
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==6)//IN6

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==7)//IN7

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else

                                                                                            
    {;}

                                                                                            
    putchar(adcbuf_2Byte[0]);//MSB byte     

                                                                                            
    putchar(adcbuf_2Byte[1]);

     

                                                                                            
    convnum--;

                                                                                            
    convcount++;

                                                              
    }//while

                                               
       LED3_OFF();

                                               
       if (convcount==CNVNum)

                                                              
    LED4_OFF();                                    
     
                             

                                               
    }//else if (0x11 == combuf[0])

     

                 
    }

                 
    return 0;

    }

Reply
  • //Head files

    #include <ADuC7026.H>

    #include "functions.h"

     

    #define
    SET_CNV()                                       
    GP1DAT = (GP1DAT |
    0x00040000)           
    //P1.2->CNV             
    -- P3.40: Brown  -- A17

    #define
    CLR_CNV()                                       
    GP1DAT = (GP1DAT & 0xFFFBFFFF)

    #define
    SET_CS()                                           
    GP1DAT = (GP1DAT |
    0x00800000)           
    //

    #define
    CLR_CS()                                          
    GP1DAT = (GP1DAT &
    0xFF7FFFFF)           

    #define SET_SCK() GP1DAT = (GP1DAT | 0x00100000) //P1.4->SCK -- P3.38: White   -- A9

    #define
    CLR_SCK()                                        
    GP1DAT = (GP1DAT &
    0xFFEFFFFF)           

    #define
    MISO_BIT                                        
    (GP1DAT &
    0x00000020)                             
    //P1.5->MISO -- P3.35: Grey     -- B11

    #define
    SET_MOSI()                                     
    GP1DAT = (GP1DAT |
    0x00400000)           
    //P1.6->MOSI -- P3.34: Green

    #define
    CLR_MOSI()                                     
    GP1DAT = (GP1DAT & 0xFFBFFFFF)

     

    #define
    LED2_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFEFFFF)           
    //P4.0->LED2

    #define
    LED2_OFF()                                     
    GP4DAT = (GP4DAT | 0x00010000)

    #define
    LED3_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFDFFFF)           
    //P4.1->LED3

    #define
    LED3_OFF()                                     
    GP4DAT = (GP4DAT | 0x00020000)

    #define
    LED4_ON()                                      
    GP4DAT = (GP4DAT &
    0xFFFBFFFF)           
    //P4.2->LED4

    #define
    LED4_OFF()                                     
    GP4DAT = (GP4DAT | 0x00040000)

     

    volatile unsigned char
    Timer1_flag;         // Timer1 interrupt
    flag

    ///////////////////////////////////////////////////////////////////////////////////////////////////////

    void AD7689_gpiospiwrite_L14bitword(unsigned short
    data)           //CS low for
    reading 1 word from the first channel

    {

                 
    int i=0;

                 
    unsigned short temp=0;

                 
    temp = data;

    //Initial CNV=0, SCK=0

                 
    temp = temp << 2;

                 
    for (i=0;i<16;i++)

                 
    {

                                
    if(0x8000 == (temp & 0x8000))

                 
                                
    SET_MOSI();

                                
    else

                                               
    CLR_MOSI();

                                
    temp = temp << 1;

                                
    SET_SCK();           //rising
    edge for write in

                                
    CLR_SCK();

                 
    }

                 
    CLR_MOSI();                    
    //AD7689 SDI should be idle low

    }

     

    unsigned short AD7689_gpiospireadword_writeL14bitword(unsigned
    short data)    //CS low for reading 1 word from the first
    channel

    {

                 
    int i=0;

                 
    unsigned short temprev = 0, tempsend = 0;

    //CNV=0, SCK=0

                 
    tempsend = data;

                 
    tempsend = tempsend << 2;

                 
    for (i=0;i<14;i++)

                 
    {

                                
    temprev = temprev << 1;

                                
    if (MISO_BIT!=0)

                                               
    temprev = temprev + 1;

                                
    else

                                               
    ;

     

                                
    if(0x8000 == (tempsend & 0x8000))

                                               
    SET_MOSI();

                                
    else

                                               
    CLR_MOSI();

                                
    tempsend = tempsend << 1;

                                
    SET_SCK();

                                
    CLR_SCK();          //falling edge
    for MSB-1, ...

                                
    CLR_MOSI();       //MOSI idle low

                 
    }

                                
    for (i=14;i<16;i++)

                 
    {

                                
    temprev = temprev << 1;

                                
    if (MISO_BIT!=0)

                                               
    temprev = temprev + 1;

                                
    else

                                               
    ;

                                
    SET_SCK();

                                
    CLR_SCK();          //falling edge
    for MSB-1, ...

                 
    }

                 
    return temprev;

    }

     

    void AD7689_gpiospiread_word(unsigned char
    *data)        //CS low for reading 1 word from
    the first channel

    {

                 
    int i=0;

     

    //          
    CLR_CS();           
    //CS falling edge output first MSB

                 
    for (i=0;i<8;i++) //CNV falling for MSB

                 
    {

                                
    *data = (*data) << 1;

                                
    if (MISO_BIT!=0)

                                               
    *data = (*data)+1;

                                
    else

                                               
    ;

                                
    SET_SCK();           //

                                
    CLR_SCK();          //SCK falling
    edge for MSB-1, ...

                                
    delay1us(10);

                 
    }

                 
    data++;

                 
    for (i=0;i<8;i++)

                 
    {

                                
    *(data) = (*(data)) << 1;

                                
    if (MISO_BIT!=0)

                                               
    *(data) = (*(data))+1;

                                
    else

                                               
    ;

                                
    SET_SCK();                        
    //

                                
    CLR_SCK();          //intially low

                                
    delay1us(10);

                 
    }

    //          
    SET_CS();

                 
    data--;

    }

    ///////////////////////////////////////////////////////////////////////////////////////////

     

    void ADuC7026_Initiate(void)

    {

    /*         
    */

    }

                                

    void AD7689_Initiate(void)

    {

                                
    int i=0;

                                
    CLR_SCK();          //initially low

                                
    CLR_CNV();//intially high

                                
    //idle conv after power up

                                
    SET_CNV();

                                
    delay1us(10);      //delay 4us, tCONV > 2.2us for no
    BUSY Indicator

                                
    CLR_CNV();

                                
    //Configuration Register:

                                
    //[13] = 1: overwrite contents of register.

                                
    //[12:10] = 111: Unipolar, INx referenced to GND.

                                
    //[9:7] = 111: IN7

                                
    //[6] = 1: full BW.

                                
    //[5:3] = 110:External reference 5V, driver disabled, temperature disabled.

                                
    //[2:1] = 11 :scan from IN0 to CFG[9:7].

                                
    //[0] = 1:do not read back contents of configuration.

                                
    AD7689_gpiospiwrite_L14bitword(0x3FC7);//8 ch selected in sequencer, full bandwidth,
    external REF,

                                
    delay1us(10);

                                
    for (i=0;i<1;i++)  //delay one phase

                                
    {

                                               
    SET_CNV();

                                               
    delay1us(10);      //delay 4us, tCONV > 2.2us for
    no BUSY Indicator

                                               
    CLR_CNV();

                                               
    delay1us(10);

                                
    }

    }

     

    int main (void)

    {

    //          
    unsigned char HByte=0, LByte=0;

                 
    unsigned char combuf[4]={0};

                 
    unsigned long T1_LD=0;

                 
    unsigned long CNVNum = 0, convnum=0,convcount=0;

                 
    unsigned char
    adcbuf_2Byte[2]={0};          //1
    word

                 
    unsigned short adcrevbuf=0;

                 
    unsigned char CHNum = 8;

     

                 
    ADuC7026_Initiate();                                                  
    //ADuC7026 Initiation

                 
    AD7689_Initiate();

    /*** UART ***/

                 
    COMIEN0 =
    0x01;                                                                                      
    //Enable Receive Buffer Full Interrupt

                 
    IRQEN =
    0x00004000;                                                
                 
    // Enable UART interupt

     

                 
    while(1)

                 
    {

                                                              
    Intcount=0;

                                                              
    convcount=0x08;

                                                              
    convnum=CNVNum;

                                                              
    while (convnum)

                                                              
    {

                                                                             
    LED3_ON();

                                                                             
    LED4_ON();

                                                                             
    adcbuf_2Byte[0] = 0;

                                                                             
    adcbuf_2Byte[1] = 0;

                                                                             
    SET_CNV();

                                                                             
    delay1us(10);      //delay 4us, tCONV > 2.2us for
    no BUSY Indicator

                                                                             
    CLR_CNV();

                                                                                            
    if (convcount%CHNum==0)//IN0

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==1)//IN1

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==2)//IN2

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==3)//IN3

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==4)//IN4

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==5)//IN5

                                                                                            
    {

                                                              
                                
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==6)//IN6

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else if (convcount%CHNum==7)//IN7

                                                                                            
    {

                                                                                            
                 
    AD7689_gpiospiread_word(adcbuf_2Byte);

                                                                                            
    }

                                                                                            
    else

                                                                                            
    {;}

                                                                                            
    putchar(adcbuf_2Byte[0]);//MSB byte     

                                                                                            
    putchar(adcbuf_2Byte[1]);

     

                                                                                            
    convnum--;

                                                                                            
    convcount++;

                                                              
    }//while

                                               
       LED3_OFF();

                                               
       if (convcount==CNVNum)

                                                              
    LED4_OFF();                                    
     
                             

                                               
    }//else if (0x11 == combuf[0])

     

                 
    }

                 
    return 0;

    }

Children