1895 views|0 replies

2015

Posts

0

Resources
The OP
 

DAC7311 library function source code available for msp430 microcontroller [Copy link]


16-bit DAC backward compatible with 7311/8411/7811

3 IO ports can be driven

Originally used in msp430g2553, macro definition fast transplantation

The microcontroller source program is as follows:
/*
* DAC7311.c
*
* Created on: 2018
* Author: Thinkpad
*/

/************DAC8411.c******************/

#include "global.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"

#define SAMPLENUM 400 //Number of sampling points, only 200 before deleting link cmd

unsigned int data[12]={32768,49151,61145,65535,61145,49151,32768,16384,4390,1,4390,16384};
const unsigned int Data[SAMPLENUM]={32768,33282,33797,34311, 34825,35338,35851,36363,36874,37384,37893,38401,38907,39412,39915,40417,
40916,41414,41909,42402,42893,43381,43867,44350,44830,45307,45781,46252,46719,47183,47643,48100,
48553,49002,49447,49888,5 0325,50757,51185,51609,52027, 52441,52851,53255,53654,54048,54437,54820,
55198,55570,55937,56298,56654,57003,57346,57684,58015,58340,58659,58971,59277,59576,59868,60154,
60434,60706,60971,61230,6 1481,61726,61963,62193,62416, 62631,62840,63040,63233,63419,63597,63768,
63931,64086,64233,64373,64505,64629,64745,64854,64954,65047,65131,65208,65276,65337,65389,65433,
65470,65498,65518,65530,6 5535,65530,65518,65498,65470, 65433,65389,65337,65276,65208,65131,65047,
64954,64854,64745,64629,64505,64373,64233,64086,63931,63768,63597,63419,63233,63040,62840,62631,
62416,62193,61963,61726,6 1481,61230,60971,60706,60434, 60154,59868,59576,59277,58971,58659,58340,
58015,57684,57346,57003,56654,56298,55937,55570,55198,54820,54437,54048,53654,53255,52851,52441,
52027,51609,51185,50757,5 0325,49888,49447,49002,48553, 48100,47643,47183,46719,46252,45781,45307,
44830,44350,43867,43381,42893,42402,41909,41414,40916,40417,39915,39412,38907,38401,37893,37384,
36874,36363,35851,35338,3 4825,34311,33797,33282,32768, 32253,31738,31224,30710,30197,29684,29172,
28661,28151,27642,27134,26628,26123,25620,25118,24619,24121,23626,23133,22642,22154,21668,21185,
20705,20228,19754,19283,1 8816,18352,17892,17435,16982, 16533,16088,15647,15210,14778,14350,13926,
13508,13094,12684,12280,11881,11487,11098,10715,10337,9965,9598,9237,8881,8532,8189,7851,
7520,7195,6876,6564,6258,5959,56 67,5381,5101, 4829,4564,4305,4054,3809,3572,3342,
3119,2904,2695,2495,2302,2116,1938,1767,1604,1449,1302,1162,1030,906,790,681,
581,488,404,327,259,198,146,102,65,37,17,5,1 , 5,17,37,
65,102,146,198,259,327,404,488,581,681,790,906,1030, 1162,1302,1449,
1604,1767,1938,2116,2302,2495,2695,2904,3119,3342,3572,3809,4054,4305,4564,4829,
5101,5381,5667,5959,6258,6564,6876,7195,7 520, 7851,8189,8532,8881,9237,9598,9965,
10337,10715,11098,11487,11881,12280,12684,13094,13508,13926,14350,14778,15210,15647,16088,16533,
16982,17435,17892,18352,1 8816,19283,19754,20228,20705, 21185,21668,22154,22642,23133,23626,24121,
24619,25118,25620,26123,26628,27134,27642,28151,28661,29172,29684,30197,30710,31224,31738,32253};

/****************************************************** *************
* STANDARD BITS
************************************ ************************/


#define BITA (0x0400)
#define BITB (0x0800)
#define BITC (0x1000)
#define BITD (0x2000)
#define BITE (0x4000)
#define BITF (0x8000)

//--------IO macro definition----------
#define SYNC_HIGH GPIO_setHigh(myGpio, GPIO_Number_0)//P1OUT |=BIT0
#define SYNC_LOW GPIO_setLow(myGpio, GPIO_Number_0)//P1OUT &=~BIT0
#define SCLK_HIGH GPIO_setHigh(myGpio, GPIO_Number_1)//P2OUT |=BIT2
#define SCLK_LOW GPIO_setLow(myGpio, GPIO_Number_1)//P2OUT &=~BIT2
#define DIN_HIGH GPIO_setHigh(myGpio, GPIO_Number_2)//P1OUT |=BIT3
#define DIN_LOW GPIO_setLow(myGpio, GPIO_Number_2)//P1OUT &=~BIT3
int send_1=0;
int dacisr_in=0;
/****************************** ************************************************** **********************
* Name: DAC8411_Init()
* Function: Initialize DAC8411
* Input parameter: None
* Output parameter: None
* Description: Initialize related IO Status
* Example: None
******************************************** ************************************************** ********/
void DAC_Init()
{
//-----Set IO to output-----
//P1DIR |= BIT0+BIT3;
//P2DIR |= BIT2;
GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output);
GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output);
GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);

GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose);
GPIO_setMode(myGpio, GPIO_Number_1, GPIO_0_Mode_GeneralPurpose);
GPIO_setMode(myGpio, GPIO_Number_2, GPIO_0_Mode_GeneralPurpose);
//-----Set the initial state of IO to high-----
SCLK_HIGH;
HIGH;

//Do not turn on DAC first to prevent affecting GPIO0-2 of 1602
PIE_disableInt(myPie,PIE_GroupNumber_1,PIE_InterruptSource_TIMER_0);
}
/**********************************************************************************************
* Name: write2DAC8411(unsigned int Data)
* Function: write 16-bit data to DAC8411
* Input parameter: None
* Output parameter: None
* Description: A total of 18 bits need to be sent, the first two bits are 0, and the last 16 bits are DAC quantized data
* Example: None
****************************************************************************************************/
void write2DAC(unsigned int Data)
{
unsigned int Temp;
unsigned char i;
Temp=Data;
SYNC_LOW; //Pull the synchronization line low to start transmission

//-----Send 00, which means non-power saving mode (power saving stops working). -----
SCLK_HIGH;
DIN_LOW; //Data 0
SCLK_LOW;

SCLK_HIGH;
DIN_LOW; //Data 0
SCLK_LOW;


//-----Send 14 bits in sequence----- The last two bits are invalid, and the data bits only intercept the first 12 bits. Equivalent to /8. The larger the number of bits, the more cycles and the slower the loop.
for(i=0;i<14;i++)
{
SCLK_HIGH;

//-----Through bitwise AND, determine whether the highest bit is 1 or 0, and decide what data to send-----
if(Temp & BITF)
{
DIN_HIGH;
send_1++;
}
else DIN_LOW;

SCLK_LOW;
Temp=Temp<<1; //Shift left by one bit, always send the highest bit

}


SYNC_HIGH; //The valid data sequence is the 16th high data line, stop conversion
}

/******************************************************************************************************
* Name: TA0_OnTime()
* Function: TA0 timing event processing function
* Input parameter: None
* Output parameter: None
* Description: None
* Example: None
********************************************************************************************************/
void DAC_Output()
{
static unsigned int i=0;
static unsigned int MUL=0;
write2DAC(Data[i]); //Write the i-th bit data of the sine table

dacisr_in++;
// if(freq>600)
// i=i+freq/100; // Take a point every freq/10, which is equivalent to frequency doubling
// else
i+=add;//It takes a long time

if(i>SAMPLENUM-1)
i=0; //out of range


}


This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list