Quantcast
Channel: Processors forum - Recent Threads
Viewing all articles
Browse latest Browse all 17527

CCS/TMS320C6745: DAC MCP4921 with TMS320C6745

$
0
0

Part Number:TMS320C6745

Tool/software: Code Composer Studio

Hello,

I used a board of TMS320C6745 processor which used MCP4921 DAC through SPI. I get the following code to generate the sine wave. in this i dont understand why it use sampling frequency 11000.. 

when i changed the sampling frequency, sine wave frequency has changed.

I did not get this point.

please help me asap.

 

#include <stdio.h>
#include<math.h>

#include "c6745.h"
#include "spidac.h"

#define PI 3.14

#define DAC_CS_LOW(); SPI_SPIPC3 = 0x0; //(CS=Low:Enable)
#define DAC_CS_HIGH(); SPI_SPIPC3 = 0x1; //(CS=High:Disable)

void SPI_Write(unsigned short Data);
void Sent_to_SPI(unsigned short Value);

unsigned short i,j=0,High,Value=0;
const float sampf = 11000.0; // Sampling frequency is fixed
const int inpf = 1000; // change the input frquency from 1khz to 8khz(1000 to 8000)
float sampt;
double teta;
signed short value;
int count,nsamp;

void main()
{
spidac_init();
DAC_CS_HIGH();

sampt = 1/sampf;
nsamp = sampf/inpf;

while(1)
{
for(count=0;count<nsamp;count++)
{
teta = (2 * PI * inpf * sampt * count);
value = sin(teta)*2048;
Sent_to_SPI(value);
}
}
}

void Sent_to_SPI(unsigned short Value)
{
DAC_CS_LOW();
Value = (0x0FFF & Value);
Value = (0x0800 ^ Value);
SPI_Write(Value);
for(j=0;j<10;j++);
DAC_CS_HIGH();
}

/****************************/
/* SPI 16 bit Data to Dac */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;

Data = ( 0x3000 | Data );

/* Clear any old data */
receive = SPI_SPIBUF;

// Wait for transmit ready
while( SPI_SPIBUF & 0x10000000 );(Please visit the site to view this file)
/* Write 1 byte */
SPI_SPIDAT1 = Data;
while((SPI_SPIBUF & 0x20000000)==1);

receive = SPI_SPIBUF;
}


Viewing all articles
Browse latest Browse all 17527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>