dsp28335芯片 adc中断方式采样代码加注释
时间: 2023-07-09 08:45:48 浏览: 218
adc.zip_ADC采样程序_DSP2812_model68x_顺序采样程序
好的,以下是dsp28335芯片 adc中断方式采样代码,已加上注释:
```c
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define ADC_usDELAY 5000L
// 定义ADC采样结果变量
Uint16 AdcResult[16];
interrupt void adc_isr(void) // ADC中断处理函数
{
// 读取ADC采样结果
AdcResult[0] = AdcResultRegs.ADCRESULT0;
AdcResult[1] = AdcResultRegs.ADCRESULT1;
AdcResult[2] = AdcResultRegs.ADCRESULT2;
AdcResult[3] = AdcResultRegs.ADCRESULT3;
AdcResult[4] = AdcResultRegs.ADCRESULT4;
AdcResult[5] = AdcResultRegs.ADCRESULT5;
AdcResult[6] = AdcResultRegs.ADCRESULT6;
AdcResult[7] = AdcResultRegs.ADCRESULT7;
AdcResult[8] = AdcResultRegs.ADCRESULT8;
AdcResult[9] = AdcResultRegs.ADCRESULT9;
AdcResult[10] = AdcResultRegs.ADCRESULT10;
AdcResult[11] = AdcResultRegs.ADCRESULT11;
AdcResult[12] = AdcResultRegs.ADCRESULT12;
AdcResult[13] = AdcResultRegs.ADCRESULT13;
AdcResult[14] = AdcResultRegs.ADCRESULT14;
AdcResult[15] = AdcResultRegs.ADCRESULT15;
// 清除ADC采样完成标志位
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
// 重新启动ADC采样
AdcRegs.ADCSOCFRC1.all = 0xFFFF;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
// 退出中断处理函数
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
void InitAdc(void)
{
// 使能ADC模块时钟
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
EDIS;
// 初始化ADC模块
AdcRegs.ADCTRL1.bit.RESET = 1;
AdcRegs.ADCTRL1.bit.SUSMOD = 3;
AdcRegs.ADCTRL1.bit.ACQ_PS = 0x1F;
AdcRegs.ADCTRL1.bit.CPS = 0;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;
AdcRegs.ADCTRL1.bit.CONT = 1;
AdcRegs.ADCTRL1.bit.CLKDIV2EN = 1;
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 15; // 最大采样通道数
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.ADCCHSELSEQ3.bit.CONV08 = 8;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 9;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 10;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 11;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 12;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 13;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 14;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 15;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;
AdcRegs.ADCINTSEL1N2.bit.INT1SEL = 1;
AdcRegs.ADCINTSEL1N2.bit.INT1E = 1;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
// 设置ADC采样时钟
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_CLK_DIV;
EDIS;
// 延时等待ADC采样模块初始化完成
DELAY_US(ADC_usDELAY);
// 启动ADC采样
AdcRegs.ADCSOCFRC1.all = 0xFFFF;
}
void main(void)
{
// 系统初始化
InitSysCtrl();
// 初始化ADC模块
InitAdc();
// 使能CPU中断
EINT;
ERTM;
// 无限循环
while(1);
}
```
以上代码是基于dsp28335芯片的adc中断方式采样代码,其中:
- `AdcResult` 是存储ADC采样结果的数组;
- `adc_isr` 是ADC中断处理函数,当ADC采样完成后会调用该函数进行处理;
- `InitAdc` 是ADC模块初始化函数,用于初始化ADC模块并设置ADC采样参数;
- `main` 函数中先调用 `InitSysCtrl` 函数进行系统初始化,再调用 `InitAdc` 函数进行ADC模块初始化,最后启用CPU中断并进入无限循环。
注释中详细解释了各个函数的功能和变量的作用,希望能对你有所帮助。
阅读全文