DSP

F28335 ADC多通道连续采样 代码+注释

2019-07-13 19:44发布

 程序功能: 1 CONV00  CONV01 CONV02  三个通道采样 2 连续采样 和单通道只是配置和数据提取不同  #include "DSP2833x_Device.h" // DSP2833x Headerfile Include File #include "DSP2833x_Examples.h" // DSP2833x Examples Include File #define POST_SHIFT 0 // Shift results after the entire sample table is full #define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter #define NO_SHIFT 0 // Do not shift the results #if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT #define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz #endif #if (CPU_FRQ_100MHZ) #define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz #endif #define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz #define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle #define AVG 1000 // Average sample limit #define ZOFFSET 0x00 // Average Zero offset #define BUF_SIZE 6 // Sample buffer size // Global variable for this example volatile Uint16 SampleTable[BUF_SIZE]; volatile float adc0=0; volatile float adc1=0; volatile float adc2=0; main() { Uint16 i; Uint16 array_index; InitSysCtrl(); EALLOW; SysCtrlRegs.HISPCP.all = ADC_MODCLK; // 系统外设时钟6分频,一般ADC就用6分频 // 这是因为ADC最高只能配置25MHz的频率 // 所以最快转换一次的时间使80ns EDIS; DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); InitAdc(); //这个初始化程序,必须添加DSP2833x_Adc.C文件 AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; //ADC采样时间选择 AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; //ADC内核分频 AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联工作方式 AdcRegs.ADCTRL3.bit.SMODE_SEL= 0; // 顺序采样 AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续采样 AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1 ; //完成排序后,排序器指针回到最初状态 AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x2; AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1 ; AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2 ; AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 0x1; //允许向CPU发出中断请求 // Clear SampleTable for (i=0; iBUF_SIZE) array_index = 0; while(AdcRegs.ADCST.bit.INT_SEQ1 == 0); //等待ADC的中断位为1 AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //清楚排序器中断位 SampleTable[array_index++]= ( (AdcRegs.ADCRESULT0)>>4); SampleTable[array_index++]= ( (AdcRegs.ADCRESULT1)>>4); SampleTable[array_index++]= ( (AdcRegs.ADCRESULT2)>>4); adc0=(float)SampleTable[0] * 3.0 /4096.0; // 转换为我们读取的数据类型 adc1=(float)SampleTable[1] * 3.0 /4096.0; // 数据类型转换另外一篇有说明 adc2=(float)SampleTable[2] * 3.0 /4096.0; DELAY_US(100); } } //=========================================================================== // No more. //===========================================================================