dsp28335芯片 adc中断方式采样代码
时间: 2023-07-09 21:45:40 浏览: 118
关于28335的有效值采样代码
以下是基于DSP28335芯片的ADC中断方式采样代码示例:
```c
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "DSP2833x_GlobalPrototypes.h"
Uint16 AdcBuf[8];
volatile Uint16 SampleFlag;
interrupt void AdcIsr(void)
{
AdcBuf[0] = AdcResult.ADCRESULT0;
AdcBuf[1] = AdcResult.ADCRESULT1;
AdcBuf[2] = AdcResult.ADCRESULT2;
AdcBuf[3] = AdcResult.ADCRESULT3;
AdcBuf[4] = AdcResult.ADCRESULT4;
AdcBuf[5] = AdcResult.ADCRESULT5;
AdcBuf[6] = AdcResult.ADCRESULT6;
AdcBuf[7] = AdcResult.ADCRESULT7;
SampleFlag = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
void AdcInit(void)
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
AdcRegs.ADCTRL1.bit.RESET = 1;
AdcRegs.ADCTRL1.bit.SUSMOD = 3;
AdcRegs.ADCTRL1.bit.ACQ_PS = 9;
AdcRegs.ADCTRL1.bit.CPS = 1;
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0;
AdcRegs.ADCTRL3.bit.ADCPWDN = 1;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 7;
AdcRegs.ADCTRL3.bit.SMODE_SEL = 1;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 7;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 3;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 4;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 5;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 6;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 7;
AdcRegs.ADCTRL1.bit.INTPULSEPOS = 1;
PieVectTable.ADCINT1 = &AdcIsr;
IER |= M_INT1;
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
AdcRegs.ADCTRL1.bit.ADCENABLE = 1;
EDIS;
}
void main(void)
{
InitSysCtrl();
EINT;
InitPieCtrl();
InitPieVectTable();
AdcInit();
for (;;) {
while (SampleFlag == 0)
;
SampleFlag = 0;
// 此处可进行数据处理
}
}
```
在这个例子中,我们使用了ADC中断来采样8个通道的数据,并将其存储在AdcBuf数组中。每次ADC中断被触发,SampleFlag标志会被设置为1,然后在主循环中进行数据处理。注意,在AdcInit函数中需要配置ADC的各项参数,使其符合实际需求。
阅读全文