📄 example_dps2812m_adda.c
字号:
/* =================================================================================
File name: AD&DA.C
Originator: NA
Description:
DPS2812M Device Digital to Analog test program.
=====================================================================================
History:
-------------------------------------------------------------------------------------
4-1-2008 Release Rev 1.0 pan
------------------------------------------------------------------------------*/
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "Example_DPS2812M_AD.H"
#include "Example_DPS2812M_DA.H"
DAC_DRV DAC=DAC_DRV_DEFAULTS;
ADC_DRV AD=ADC_DRV_DEFAULTS;
Uint16 EVAInterruptCount;
Uint16 temp[128],x=0,temp2[128];
unsigned int ADflag=1;
unsigned int channal=5;
interrupt void ADC_T1TOADC_isr(void);
interrupt void ADC_SampleINT(void);
// ADC start parameters
//#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25MHz
// Global variable for this example
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
IER=0x0000;
IFR=0x0000;
// 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 DSP281x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
//IER = 0x0000;
//IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
// 初始化EVA定时器1
ADREG=0;
EvaRegs.GPTCONA.all=0;
//设置通用目的定时器1的周期为0x200;
EvaRegs.T1PR=0x0005; //周期
EvaRegs.T1CMPR=0x0000; //比较寄存器
//使能通用目的定时器1的周期中断
//向上计数、预定标x128、内部时钟、使能比较、使用自己的周期值
EvaRegs.EVAIMRA.bit.T1PINT=1;
EvaRegs.EVAIFRA.bit.T1PINT=1;
//清除通用目的定时器1的计数器值
EvaRegs.T1CNT=0x0000;
EvaRegs.T1CON.all=0x1742;
//当通用目的定时器1产生中断时启动ADC变换
EvaRegs.GPTCONA.bit.T1TOADC=2;
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.T1PINT = &ADC_T1TOADC_isr;
PieVectTable.XINT1 = &ADC_SampleINT;
EDIS; // This is needed to disable write to EALLOW protected registers
XIntruptRegs.XINT1CR.all=0x0001;
XIntruptRegs.XINT2CR.all=0x0001;
PieCtrlRegs.PIEIER1.bit.INTx3=1;
PieCtrlRegs.PIEIER1.bit.INTx4=1;
PieCtrlRegs.PIEIER2.all=M_INT4;
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals();
DAC.DACChannelSel=0x00;
DAC.DACDataCycle=128;
DAC.DACDataOffset=0;
DAC.DataSel=0;
// Step 5. User specific code, enable interrupts:
// Step 5. User specific code, enable interrupts:
IER |=(M_INT2|0x0001);
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
x = 0;
for(;;)
{
if(AD.ADCFlag.bit.ADCSampleFlag==1)
{
if(AD.LoopVar>=128) AD.LoopVar=0;
//AD.ADChannelSel=0;
if(ADflag==0)
ADCSmplePro(&AD);
//AD.LoopVar++;
AD.ADCFlag.bit.ADCSampleFlag=0;
}
}
}
interrupt void ADC_T1TOADC_isr(void)
{
if(ADflag==1)
{
DAC.DACPro(&DAC);
ADflag=0;
*AD_CONVST=0;
EvaRegs.EVAIMRA.bit.T1PINT=1;
EvaRegs.EVAIFRA .all =BIT7;
}
PieCtrlRegs.PIEACK .all =PIEACK_GROUP2;
return;
}
interrupt void ADC_SampleINT(void)
{
XIntruptRegs.XINT1CR .all =0x0000;
AD.ADCFlag.bit.ADCSampleFlag=1;
XIntruptRegs.XINT1CR .all =0x0001;
PieCtrlRegs.PIEACK .all =PIEACK_GROUP1;
return;
}
void ADCSmplePro(ADC_DRV *v)
{
unsigned int Temp1;
ADflag=1;
}
void DAC_Core(DAC_DRV *v)
{
long OutData1[320];
long OutData2;
/*********************************************************/
/*data processing */
/*********************************************************/
/*********************************************************/
/*DATA OUT */
/*********************************************************/
*DA_CHANNEL0=32768;
// *DA_CHANNEL1=*AD_CHIPSEL0;
// *DA_CHANNEL2=*AD_CHIPSEL1;
OutData1[x] =*AD_CHIPSEL1;
if (OutData1[x] >= 32768 && OutData1[x] <= 65535)
OutData2 = OutData1[x] - 32768;
else if (OutData1[x] < 32768 && OutData1[x] >= 0.0)
OutData2 = OutData1[x] + 32768;
else
OutData2 = 32768;
*DA_CHANNEL3=OutData2;
x++;
if (x == 320)
x = 0;
*DA_OUT=0;
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -