Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Driving AD80066 by Atmega128

Status
Not open for further replies.

Bluestar88

Member level 3
Joined
Oct 17, 2014
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
447
Hello guys,
I want to drive a AD80066 (Analog to Digital converter) using serial interface with Atmega128.
As described in Ad80066 datasheet, It has some registers that can be adjust by interface serial.
Now, I want to drive this Ic....So, I think I should make a library for Ad80066 and add it in codevision....There are some libraries for others IC in library of codevision...I never have written library for any Ic.. I want to write a library for AD80066....Would you please to help me?!
 

For more descriptions, Ad80066 has some internal register used for configuration of gain, offset and operation mode ...and it is connected to SPI atmega128...I donn't know how to adjust the registers..
 

I think I found...would you please to check it?
In page of 14 from AD80066 there are some address for internal registers..I think I should use from them and take the value of registers in the addresses ..So I think I don't need to make a library for Ad80066... Am I correct?
 

I have started to initialize AD80066. I am really interested to drive it. So I request from everyone come to discus in this thread. As described in data sheet,it has some registers that they should be configured. I connected AD80066 by SPI interface to atmega128 to fit its registers. For driving it, I used my code which I wrote it in codevision...My code is in blow...My problem is about the amount Of PINF which is output of AD80066 (D0 to D7 in connected as input of Atmega128 and I measured it as a....the amout of PINF as 112-113-114-115-116 with evey different input of AD80066 (I used Channel A for input of AD80066)...The output of AD80066 is same as 0 1.2 volt and 2.5 volt...Why!...My code is here...

Code:
#include <mega128a.h>
#include <spi.h>
#include <delay.h>
#include <stdio.h>


#define CDSCLK1 PORTE.3
#define CDSCLK2 PORTE.4
#define ADCCLK PORTE.5



#define DELAY_NS(x)

int Flag;
int k;
int i;
float a[100];
// Declare your global variables here


#ifndef RXB8
#define RXB8 1
#endif

#ifndef TXB8
#define TXB8 0
#endif

#ifndef UPE
#define UPE 2
#endif

#ifndef DOR
#define DOR 3
#endif

#ifndef FE
#define FE 4
#endif

#ifndef UDRE
#define UDRE 5
#endif

#ifndef RXC
#define RXC 7
#endif

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)





// USART1 Receiver buffer
#define RX_BUFFER_SIZE1 8
char rx_buffer1[RX_BUFFER_SIZE1];

#if RX_BUFFER_SIZE1 <= 256
unsigned char rx_wr_index1,rx_rd_index1,rx_counter1;
#else
unsigned int rx_wr_index1,rx_rd_index1,rx_counter1;
#endif

// This flag is set on USART1 Receiver buffer overflow
bit rx_buffer_overflow1;

// USART1 Receiver interrupt service routine
interrupt [USART1_RXC] void usart1_rx_isr(void)
 {
char status,data;
status=UCSR1A;
data=UDR1;

    if (data=='u')
    {
    
      }
    
    
    
    
        
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
   {
   rx_buffer1[rx_wr_index1++]=data;
#if RX_BUFFER_SIZE1 == 256
   // special case for receiver buffer size=256
   if (++rx_counter1 == 0)
      {
#else
   if (rx_wr_index1 == RX_BUFFER_SIZE1) rx_wr_index1=0;
   if (++rx_counter1 == RX_BUFFER_SIZE1)
      {
      rx_counter1=0;
#endif
      rx_buffer_overflow1=1;
      }
   }
}

// Get a character from the USART1 Receiver buffer
#pragma used+
char getchar1(void)
{
char data;
while (rx_counter1==0);
data=rx_buffer1[rx_rd_index1++];
#if RX_BUFFER_SIZE1 != 256
if (rx_rd_index1 == RX_BUFFER_SIZE1) rx_rd_index1=0;
#endif
#asm("cli")
--rx_counter1;
#asm("sei")
return data;
}
#pragma used-
// Write a character to the USART1 Transmitter
#pragma used+
void putchar1(char c)
{
while ((UCSR1A & DATA_REGISTER_EMPTY)==0);
UDR1=c;
}
#pragma used-



void Desiable (void)
{
 
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 125.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x52;
SPSR=0x00;

      PORTB.0=0 ;               //Congiguration Bit
      spi(0x00); 
      //delay_us(1);
      spi(0x0F);
      PORTB.0=1 ;     
      
       PORTB.0=0 ;               //Mux bit
       spi(0x10); 
       //delay_us(1);
       spi(0x08);
       PORTB.0=1 ;

      }


void Enable (void)
{
 
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 125.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x52;
SPSR=0x00;

      PORTB.0=0 ;               //Congiguration Bit
      spi(0x00); 
      //delay_us(1);
      spi(0x0E);
      PORTB.0=1 ;     
      
       PORTB.0=0 ;               //Mux bit
       spi(0x10); 
       //delay_us(1);
       spi(0x08);
       PORTB.0=1 ;   
       
       PORTB.0=0 ;               //Gain A bit
      spi(0x20); 
     // delay_us(1);
      spi(0x3f);
      PORTB.0=1 ; 
     


      }
      

void main(void)
{
Flag=1;
//unsigned int x;
//unsigned char a;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out 
// State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=0 
PORTB=0x00;
DDRB=0x07;            // Set MOSI and SCK and SS output, all others input
  

PORTE=0x00;
DDRE=0x38;           //Set CDSCLK1, CDSCLK2 and ADCCLK as output 


PORTF=0xff;
DDRF=0x00;


// USART1 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART1 Receiver: On
// USART1 Transmitter: On
// USART1 Mode: Asynchronous
// USART1 Baud Rate: 9600
UCSR1A=0x00;
UCSR1B=0x18;
UCSR1C=0x06;
UBRR1H=0x00;
UBRR1L=0x33;


while (Flag==1)
      {  
   
     for (i=0; i<100; i++)
     {

         CDSCLK2 =0;
         ADCCLK=1;
        
         DELAY_NS(10); 
           ADCCLK=0;   
         Enable(); 
         
          DELAY_NS(8);
          CDSCLK2 =1;
         DELAY_NS(2); 
       ADCCLK=1;   
        a[i]=PINF; 
        DELAY_NS(2);  
       CDSCLK2 =0;
       DELAY_NS(8);   
      ADCCLK=0;  
      a[i+1]=PINF; 
       Desiable();     
   
     
     }  
     
      for(k=0; k<100;k++)
              {
               putchar1(a[k]);
               delay_ms(1);                     
              }   
             
     Flag=0; 
      
         }
}
 

I don't understand the code. Why are you calling the initialization repeatedly?

Generally it's hard to understand what you are trying to achieve. AD80066 is designed to work with MHz clocks, I'm not sure if it gives meaningful output with slow bit-banging clocks. Even if it would, what is it good for?
 

My code is composed of some routines. first of them is initializing Usart and introducing getchar1 and putchar1, the rest of my code is for driving AD80066..I used the disable and enable functions in main code to set ot reset configuration register...Did you work with AD80066? Would you please to take the code here maybe it can help...

- - - Updated - - -

I think the problem is here: I want to send 16 bit to AD80066 by SPI interface.The first 8 bit is address and the second is data. I used
Code:
      PORTB.0=0 ;               //Congiguration Bit
      spi(0x00); 
      //delay_us(1);
      spi(0x0F);
      PORTB.0=1 ;
but it seems it doesn't work. now, the question is how to send 16 bits to AD80066 by SPI?
 
Last edited by a moderator:

For sending 16 bit via spi communication, It is incorrect?

Code:
       PORTB.0=0 ; 
      Conf=0x000E;
      spi((Conf & 0xFF) >> 8);       // Output the MSB first
      spi(Conf & 0xFF);            // Followed by the LSB
      PORTB.0=1 ;    
 
      
       PORTB.0=0 ;                //Mux bit
       Mux=0x1008;                   
       spi( (Mux & 0xFF) >> 8 ); 
       spi(Mux & 0xFF);
       PORTB.0=1 ;   

       
       PORTB.0=0 ;                    //Gain A bit
      spi(0x20); 
      spi(0x3f);
      PORTB.0=1 ;
 

Your code sends always 0 for the first byte, should be like this
Code:
PORTB.0=0 ; 
Conf=0x000E;
spi(Conf >> 8);       // Output the MSB first
spi(Conf & 0xFF);            // Followed by the LSB
PORTB.0=1 ;

Correct operation depends on the behaviour of the spi() library function. Should work correctly if spi() waits for completion of the serial output, I guess it does.
 
Thanks, Now it is better, Output changes. for input 0 and 0.7 output is 197 and 165, respectively.
I have another question?
How I can be sure that registers are fitted as I send the amount by spi?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top