0

DataSheet:(Atmega 324A) http://www.atmel.com/images/Atmel-8272-8-bit-AVR-microcontroller-ATmega164A_PA-324A_PA-644A_PA-1284_P_datasheet.pdf

DataSheet:(DAC) http://www.ti.com/lit/ds/symlink/dac101s101.pdf

Hi there!!

i'm learning Embedded programming in c, so please bear with me.
I am trying to generate a wave using a DAC (DAC101S101) which is connected to ATmega324A via SPI. The Dac is uni-Directional. right now i'am just trying to get a output off the dac. I have made a lut which i will use to get the required sine wave. Also, how do I modulate the frequency of the wave ? (like lets say 4000Hz)(Also I have connected a external oscillator to the ATmega chip.)

 i Have connected:  
 PB5 -- MOSI -------> DIN (DAC)  
 PB7 -- SCK  -------> SCK (DAC)  
 PA1 --------------->#Sync(DAC) 

void init_SPI_Master(void) {
/*
 *  Set MOSI and SCK output, all others input
 *  DDR_SPI = (1<<DD_MOSI)| (1<<DD_SCK);    
 *  
 *  (for ATmega 324A
 *  
 *  DDRB = (1<<DDB5) | (1<<DDB7)
 *
 */

DDRB = (1<<5) | (1<<7);

/*
 *Enable SPI, Master, set clock rate fck/16;
 *
 */

SPCR0 = (1<<SPE0) | (1<< MSTR0) | (1<<SPR00) | (1<<CPOL0);

}

void Tx_SPI_Master (unsigned char data) {
/*
 *  Start transmition 
 *
 */

SPDR0 = data;

/*
 *  is Tx complete ?
 *
 */


}


int main(void)
{   
unsigned char data1 = 0x04;
unsigned char data2 = 0xFC; 
DDRA    = 1 << 1;
PORTA   = 1 << 1;   
init_SPI_Master();  
while(1)
{
    //TODO:: Please write your application code
    //sync: i'm not sure as how to provide sync to the dac 
    // according to the datasheet as soon as the sync bit goes low the  
    //    register starts accepting data into Din.   
    //    so right now i am trying to input 0000001111111100 into
    //    the dac.
    PORTA = 1 << PINA1;
    PORTA = 0 << PINA1;


    Tx_SPI_Master(data1);
    Tx_SPI_Master(data2);
}


}

Thank you!!!!

1 Answers1

0

That's a bit of an odd DAC, to be honest. SPI isn't a 'normal' interface for ADCs/DACs. It's usually I2S, or something else with a monotonic frame clock so frequency response is guaranteed.

Regardless, the DAC update rate is governed by SYNC/. The DAC will update 16 cycles after SYNC/ goes low.

Looking at the data sheet, the data is sent to the DAC MSb first. It must be 2 don't care bits, two 'mode bits', then 10 bits of data, followed by two don't care bits. Once you've sent 16 bits, set SYNC/ high(at least 20ns), then you can repeat the cycle. If you send less than 16 bits before raising SYNC/, the 'command' will be ignored.

I don't know what an AVR does when you write to the SPI register. It might lower SS//SYNC/ for 8 bits, then raise it again. This will not work with this part. You may have to bit bang data over to it.

Russ Schultz
  • 2,545
  • 20
  • 22
  • Most microcontrollers have the option to turn off automatic /SS in SPI, in which case the pin resorts to being a GPIO. So the only "bit bang" needed should be the /SS pin itself. – Lundin Oct 08 '15 at 06:31