这段程序什么意思,怎么实现AD转换。在线等
这段程序什么意思,怎么实现AD转换。在线等#include"DSP2833x_Device.h"#include"DSP2833x_Examples.h"#defineP...
这段程序什么意思,怎么实现AD转换。在线等
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#define POST_SHIFT 0
#define INLINE_SHIFT 1
#define NO_SHIFT 0
// ADC start parameters
#if (CPU_FRQ_150MHZ)
#define ADC_MODCLK 0x3
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2
#endif
#define ADC_CKPS 0x0
#define ADC_SHCLK 0x1
#define AVG 1000
#define ZOFFSET 0x00
#define BUF_SIZE 512
float SampleTable[BUF_SIZE];
float dianya[BUF_SIZE];
float sum=0;
void main()
{
Uint16 i;
Uint16 array_index;
InitSysCtrl();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;
EDIS;
DINT;//禁止中断
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags(标志):
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitAdc();
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode(顺序模式): Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; // 预分频用
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode 1 级联模式 0双排序模式
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run 连续模式
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;
AdcRegs.ADCCHSELSEQ1.all = 0x0;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;
// Clear SampleTable
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
lcdpeizhi();
while(1)
{
//WriteCmd12864(0x82);
// delay(5);
// DisplayCgrom("你好吗");
// WriteData12864('1');
for(array_index=0;array_index<512;array_index++)
{
/*if(array_index>512)
{
array_index = 0;
s=(int)(sum/512)*1000;
//WriteCmd12864(0x82);
delay(5);
ShowF(1234);
//WriteCmd12864(0x90);
//WriteData12864('2');
//WriteCmd12864(0x88);
//WriteData12864(tab1[5]);
sum=0;
}*/
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[array_index]= ( (AdcRegs.ADCRESULT0)>>4);
dianya[array_index]=(SampleTable[array_index]/4095)*2.924;
sum=sum+dianya[array_index];
DELAY_US(100);
}
sum=sum/512;
WriteCmd12864(0x90);
delay(5);
display(sum);
delay(5);
// WriteCmd12864(0x88);
// delay(5);
// display(12);
delay(5);
sum=0;
}
} 展开
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#define POST_SHIFT 0
#define INLINE_SHIFT 1
#define NO_SHIFT 0
// ADC start parameters
#if (CPU_FRQ_150MHZ)
#define ADC_MODCLK 0x3
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2
#endif
#define ADC_CKPS 0x0
#define ADC_SHCLK 0x1
#define AVG 1000
#define ZOFFSET 0x00
#define BUF_SIZE 512
float SampleTable[BUF_SIZE];
float dianya[BUF_SIZE];
float sum=0;
void main()
{
Uint16 i;
Uint16 array_index;
InitSysCtrl();
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK;
EDIS;
DINT;//禁止中断
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags(标志):
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitAdc();
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode(顺序模式): Sample rate= 1/[(2+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; // 预分频用
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode 1 级联模式 0双排序模式
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run 连续模式
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;
AdcRegs.ADCCHSELSEQ1.all = 0x0;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;
// Clear SampleTable
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
lcdpeizhi();
while(1)
{
//WriteCmd12864(0x82);
// delay(5);
// DisplayCgrom("你好吗");
// WriteData12864('1');
for(array_index=0;array_index<512;array_index++)
{
/*if(array_index>512)
{
array_index = 0;
s=(int)(sum/512)*1000;
//WriteCmd12864(0x82);
delay(5);
ShowF(1234);
//WriteCmd12864(0x90);
//WriteData12864('2');
//WriteCmd12864(0x88);
//WriteData12864(tab1[5]);
sum=0;
}*/
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[array_index]= ( (AdcRegs.ADCRESULT0)>>4);
dianya[array_index]=(SampleTable[array_index]/4095)*2.924;
sum=sum+dianya[array_index];
DELAY_US(100);
}
sum=sum/512;
WriteCmd12864(0x90);
delay(5);
display(sum);
delay(5);
// WriteCmd12864(0x88);
// delay(5);
// display(12);
delay(5);
sum=0;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询