📄 ad.c
字号:
/******************************************************************************/
/* Copyright 2004 by SEED Electronic Technology LTD. */
/* All rights reserved. SEED Electronic Technology LTD. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* MODULE NAME... DARAM on board */
/* FILENAME...... DEC5416_SRAM.c */
/* PROJECT....... Read and write on-board daram memory of TMS320VC5502 */
/* 作者: gao */
/* 版本:1.0 */
/* 日期:06.11.10 */
/******************************************************************************/
#include <math.h>
#include "DSP28_Device.h"
#include "comm.h"
///////////////////////////////////////////////////////////////////
#define SAMPLERATE 2
unsigned int SampleRate;
unsigned int SampleLong=1024;
///////////////////
unsigned int i,j;
unsigned int Ad_data[1536]={0};
//////////////////
unsigned int convcount = 0;
volatile unsigned int adconvover =0;
// Prototype statements for functions found within this file.
interrupt void ISRTimer2(void);
interrupt void ad(void);
/*****************************************************************************/
void main(void){
/*初始化系统*/
InitSysCtrl();
#if SAMPLERATE==1
SampleRate =ADSAMPL8K;
#endif
#if SAMPLERATE==2
SampleRate =ADSAMPL44K;
#endif
#if SAMPLERATE==3
SampleRate =ADSAMPL96K;
#endif
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
//初始化cputimer
InitCpuTimers();
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT2 = &ISRTimer2;
PieVectTable.ADCINT = &ad;
EDIS; // This is needed to disable write to EALLOW protected registers
/*开中断*/
IER |= M_INT1;//ADC中断
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
/*启动AD采样*/
/*AD采样率*/
adconvover=0;
switch( SampleRate){
case ADSAMPL8K: //采样率为8k
DINT;
/*设置CPU*/
ConfigCpuTimer(&CpuTimer2, 150, 125);
StartCpuTimer2();
/*开中断*/
IER |= M_INT14;
EINT;
InitAdc();
SampleRate = 0;
break;
case ADSAMPL44K: //采样率为44k
DINT;
/*设置CPU*/
ConfigCpuTimer(&CpuTimer2, 150, 22);
StartCpuTimer2();
/*开中断*/
IER |= M_INT14;
EINT;
InitAdc();
SampleRate = 0;
break;
case ADSAMPL96K: //采样率为96k
DINT;
/*设置CPU*/
ConfigCpuTimer(&CpuTimer2, 150, 10);
StartCpuTimer2();
/*开中断*/
IER |= M_INT14;
EINT;
InitAdc96k();
SampleRate = 0;
break;
default:
break;
}
for(;;){
if (adconvover==1){
adconvover=0;
}
}
}
interrupt void ad(void)
{
IFR=0x0000;
PieCtrl.PIEACK.all=0xffff;
if(adconvover==0){
Ad_data[convcount] = AdcRegs.RESULT0;
convcount++;
}
if (convcount==(SampleLong+SampleLong/2))
{
convcount=0;
adconvover=1;//接满标志
}
}
interrupt void ISRTimer2(void)
{
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -