问题1. 在下面提到的代码中、当我在监视变量窗口中使用"sampleTable"时 、表达式"sampleTable"的值不会给出最大值、即4096。所以这个故障的原因是什么 ?
问题2.该计划如何运作?
//监视变量:
// SampleTable -转换值的日志。
// GPIO34 -切换每个 ADC 序列发生器标志
//
//######################################################################################################################
//
//原始来源:S.S.
//
//$TI 发行版:DSP2833x/DSP2823x C/C++头文件 v1.31 $
//$Release Date:2009年8月4日$
//######################################################################################################################
#include "DSP28x_Project.h"//器件头文件和示例 include 文件
//确定何时发生向右转移数据对齐的情况
//其中只有一个应该被定义为1。
//其他两个应定义为0。
#define post_shift 0 //在整个采样表满后移位结果
#define inline_shift 1 //从结果寄存器获取数据时移位结果
#define NO_SHIFT 0 //不移动结果
// ADC 开始参数
#IF (CPU_FRQ_150MHz)//默认- 150MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3)= 25.0MHz
#endif
#IF (CPU_FRQ_100MHz)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2)= 25.0MHz
#endif
#define ADC_CKPS 0x0 // ADC 模块时钟= HSPCLK/1 = 25.5MHz/(1)= 25.0MHz
#define ADC_SHCLK 0x1 //在 ADC 模块周期中的 S/H 宽度= 2个 ADC 周期
#define AVG 1000 //平均采样限制
define zOffset 0x00 //平均零偏移
#define BUF_SIZE 1024 //采样缓冲区大小
//此示例的全局变量
uint16 SampleTable[BUF_SIZE];
MAIN ()
{
uint16 i;
uint16 array_index;
//步骤1. 初始化系统控制:
// PLL、安全装置、启用外设时钟
//此示例函数位于 DSP2833x_SYSCTRL.c 文件中。
InitSysCtrl();
//此示例的特定时钟设置:
EALLOW;
SysCtrlRegs.HISPCP。all = ADC_MODCLK;// HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
//步骤2. 初始化 GPIO:
//此示例函数位于 DSP2833x_GPIO.c 文件和中
//说明了如何将 GPIO 设置为其默认状态。
// InitGpio();//针对此示例跳过
//启用引脚 GPIO34作为输出
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;// GPIO 引脚
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;//输出引脚
EDIS;
//步骤3. 清除所有中断并初始化 PIE 矢量表:
//禁用 CPU 中断
Dint;
//将 PIE 控制寄存器初始化为默认状态。
//默认状态为禁用所有 PIE 中断和标志
//被清除。
//此函数位于 DSP2833x_PIECTRL.c 文件中。
InitPieCtrl();
//禁用 CPU 中断并清除所有 CPU 中断标志:
IER = 0x0000;
IFR = 0x0000;
//使用指向 shell 中断的指针初始化 PIE 矢量表
//服务例程(ISR)。
//这将填充整个表,即使是中断也是如此
//在本例中未使用。 这对于调试很有用。
//可以在 DSP2833x_DefaultIsr.c 中找到 shell ISR 例程
//此函数可在 DSP2833x_PieVect.c 中找到
InitPieVectTable();
//步骤4. 初始化所有器件外设:
//此函数位于 DSP2833x_InitPeripherals.c 中
// InitPeripherals ();//此示例不需要
InitAdc ();//对于此示例,初始化 ADC
//本示例的特定 ADC 设置:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;//顺序模式:采样率= 1/[(2+ACQ_PS)*以 ns 为单位的 ADC 时钟]
//= 1/(3*40ns)=8.3MHz (对于150MHz SYSCLKOUT)
//= 1/(3*80ns)=4.17MHz (对于100MHz SYSCLKOUT)
//如果启用同步模式:采样率= 1/[(3+ACQ_PS)*以 ns 为单位的 ADC 时钟]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;// 1级联模式
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1;//设置连续运行
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;//启用序列发生器覆盖功能
AdcRegs.ADCCHSELSEQ1.ALL = 0x0;//初始化所有 ADC 通道选择为 A0
AdcRegs.ADCCHSELSEQ2.ALL = 0x0;
AdcRegs.ADCCHSELSEQ3.ALL = 0x0;
AdcRegs.ADCCHSELSEQ4.ALL = 0x0;
AdcRegs.ADCMAXCONV.BIT.MAX_CONV1 = 0x7;//转换并存储在8个结果寄存器中
//步骤5. 特定于用户的代码、启用中断:
//清除 SampleTable
(i=0;<BUF_SIZE; i++)
{
SampleTable[i]= 0;
}
//启动 SEQ1
AdcRegs.ADCTRL2.all = 0x1999;
for (;;)
{//获取 ADC 数据并将其记录到 SampleTable 数组中
//初始化数组索引。 这指向电流
// SampleTable 中的位置
array_index = 0;
对于(i=0;i<(BUF_SIZE /16);i++)
{
//等待 INT1
while (AdcRegs.ADCST.bit.INT_SEQ1=0){}
GpioDataRegs.GPBSET.BIO34 = 1;//将 GPIO34设置为监控-可选
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
#if inline_shift
SampleTable[array_index+]=(AdcRegs.ADCRESULT0)>>4);
SampleTable[array_index++]=((AdcRegs.ADCRESULT1)>>4);
SampleTable[array_index++]=((AdcRegs.ADCRESULT2)>>4);
SampleTable[array_index+]=(AdcRegs.ADCRESULT3)>>4);
SampleTable[array_index+]=(AdcRegs.ADCRESULT4)>>4);
SampleTable[array_index++]=((AdcRegs.ADCRESULT5)>>4);
SampleTable[array_index+]=(AdcRegs.ADCRESULT6)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT7)>>4);
#endif //-- inline_shift
#if no_shift || post_shift
SampleTable[array_index++]=((AdcRegs.ADCRESULT0));
SampleTable[array_index++]=((AdcRegs.ADCRESULT1));
SampleTable[array_index++]=((AdcRegs.ADCRESULT2);
SampleTable[array_index++]=((AdcRegs.ADCRESULT3);
SampleTable[array_index++]=((AdcRegs.ADCRESULT4));
SampleTable[array_index++]=((AdcRegs.ADCRESULT5);
SampleTable[array_index++]=((AdcRegs.ADCRESULT6));
SampleTable[array_index++]=((AdcRegs.ADCRESULT7));
#endif //-- no_shift || post_shift
while (AdcRegs.ADCST.bit.INT_SEQ1=0){}
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;//清除 GPIO34以进行监控-可选
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
#if inline_shift
SampleTable[array_index+]=(AdcRegs.ADCRESULT8)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT9)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT10)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT11)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT12)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT13)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT14)>>4);
SampleTable[array_index++]=(AdcRegs.ADCRESULT15)>>4);
#endif //-- inline_shift
#if no_shift || post_shift
SampleTable[array_index++]=((AdcRegs.ADCRESULT8));
SampleTable[array_index++]=((AdcRegs.ADCRESULT9));
SampleTable[array_index++]=((AdcRegs.ADCRESULT10));
SampleTable[array_index++]=((AdcRegs.ADCRESULT11));
SampleTable[array_index++]=((AdcRegs.ADCRESULT12));
SampleTable[array_index++]=((AdcRegs.ADCRESULT13));
SampleTable[array_index++]=((AdcRegs.ADCRESULT14));
SampleTable[array_index++]=((AdcRegs.ADCRESULT15));
#endif //-- no_shift || post_shift
}
#if post_shift
//对于后移,移动 ADC 结果
//在 SampleTable 缓冲区中,缓冲区已满。
(i=0;<BUF_SIZE; i++)
{
SampleTable[i]=((SampleTable[i])>>4);
}
#endif //-- post_shift
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;//清除 GPIO34以进行监控-可选
}
}
//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
//不再需要。
//============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================