Sie sind auf Seite 1von 3

//###########################################################################

// FILE: buffdac_enable_cpu01.c
// TITLE: Buffered DAC Enable Output Example for F2837xS.
//
//! \addtogroup cpu01_example_list
//! <h1> Buffered DAC Enable (buffdac_enable) </h1>
//!
//! This example generates a voltage on the buffered DAC output,
//! DACOUTA/ADCINA0 (HSEC Pin 9) and uses the default DAC reference setting of V
DAC.
//!
//! When the DAC reference is set to VDAC, an external reference voltage
//! must be applied to the VDAC pin. This can accomplished by connecting a
//! jumper wire from 3.3V to ADCINB0 (HSEC pin 12).
//!
//
//###########################################################################
// $TI Release: F2837xS Support Library v191 $
// $Release Date: Fri Mar 11 15:58:35 CST 2016 $
// $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
#include "F28x_Project.h" // Device Headerfile and Examples Include File
#include "math.h"
// Prototype statements for functions found within this file.
__interrupt void cpu_timer0_isr(void);
__interrupt void cpu_timer1_isr(void);
__interrupt void cpu_timer2_isr(void);

//initialize DAC pointer


volatile struct DAC_REGS* DAC_PTR[4] = {0x0,&DacaRegs,&DacbRegs,&DaccRegs};
//definitions for selecting DAC reference
#define REFERENCE_VDAC 0
#define REFERENCE_VREF 1
//definitions for DAC number
#define DACA 1
#define DACB 2
#define DACC 3
//specify configuration
#define REFERENCE REFERENCE_VDAC
#define DAC_NUM DACA
#define DAC_NUMB DACB
#define DAC_NUMC DACC
Uint16 dacval = 4095;
int k=0;
float tempa,tempb,tempc;
//local functions
void configureDAC(Uint16 dac_num);

void main(void)
{
// Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
InitSysCtrl();
// Disable CPU interrupts
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
InitPieCtrl();
// Clear all interrupts and initialize PIE vector table:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

// Configure DAC
configureDAC(DAC_NUM);
configureDAC(DAC_NUMB);
configureDAC(DAC_NUMC);
while(1)
{
// DAC_PTR[DAC_NUM]->DACVALS.all = dacval*0.0;
// DELAY_US(2);
tempa=(sin(0.062832*k)+1)*2000;
tempb=(sin(0.062832*k+2.0944)+1)*2000;
tempc=(sin(0.062832*k-2.0944)+1)*2000;
DAC_PTR[DAC_NUM]->DACVALS.all = tempa;
DAC_PTR[DAC_NUMB]->DACVALS.all = tempb;
DAC_PTR[DAC_NUMC]->DACVALS.all = tempc;
DELAY_US(0.2);
k=k+1;
if(k==100)
{k=0;}

}
}
void configureDAC(Uint16 dac_num)
{
EALLOW;
DAC_PTR[dac_num]->DACCTL.bit.DACREFSEL = REFERENCE;
DAC_PTR[dac_num]->DACOUTEN.bit.DACOUTEN = 1;
DAC_PTR[dac_num]->DACVALS.all = 0;
DELAY_US(10); // Delay for buffered DAC to power up
EDIS;
}
__interrupt void cpu_timer0_isr(void)
{

// Acknowledge this interrupt to receive more interrupts from group 1


PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}