程序功能比较简单:主要在于配置 功能单通道的单次采样
1,CON0口采样
2,输出7位小数采样电压
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#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
// ADC start parameters
#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 2 // Sample buffer size
// Global variable for this example
volatile Uint16 SampleTable[BUF_SIZE];
volatile float adc0=0;
main()
{
Uint16 i;
// Uint16 adc=0;
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.ADCCHSELSEQ1.bit.CONV00 = 0x1; //设置CONV0 为第一个通道
AdcRegs.ADCTRL1.bit.CONT_RUN = 0; //连续运行模式
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; //完成排序后,排序器指针回到最初状态
AdcRegs.ADCCHSELSEQ1.all = 0x0; //初始化SEQ1排序寄存器
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0; // 设置一对转换,共16通道
// Clear SampleTable
for (i=0; i<BUF_SIZE; i++)
{
SampleTable[i] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000; //软件启动转换功能
while(1)
{
if(array_index>2)
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); //将结果寄存器16位的值转换位10进制数
adc0=(float)SampleTable[0] * 3.0 /4096.0; // 转换为我们读取的数据类型
// 数据类型转
DELAY_US(100);
}
}
//===========================================================================
// No more.
//====