首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

关于PE 的豆问题~~

关于PE 的豆问题~~

我AD豆配置里设定了ANA7为采样通道,可生成的代码怎么还是读0通道的!

byte AD1_GetValue16(word *Values)
{
if (!OutFlg) /* Is output flag set? */
return ERR_NOTAVAIL; /* If no then error */
*Values = (getReg(ADCA_ADRSLT0) + 0) << 1; // ADRSLT0应该是0通道的结果寄存器,是否应该为ADCA_ADRSLT7
return ERR_OK; /* OK */
}

采样通道与结果寄存器并非一一对应的。
海纳百川  有容乃大

我用

AD1_GetValue16(pAD);
AD1_GetChanValue16(7,pAD1);

俩个函数去获得结果,竟然是一样的!

ad.h里有这一段宏 #define AD1_GetChanValue16(Ch,V) PE_AD1_GetChanValue16(V)

他把ch给消除了,然后PE_AD1_GetChanValue16()函数体里也没有处理我传过去的ch值(7),这样读出来的也同样是0通道,(事实也是这样,我在0通道上接了光敏电阻读取和亮度成正比)

byte PE_AD1_GetChanValue16(word *Value)
{
register word *pValue=(word*)Value; /* Temporary pointer to the user buffer */
if (!OutFlg) /* Is output flag set? */
return ERR_NOTAVAIL; /* If no then error */
*Value = (ADCA_ADRSLT0 + 0) << 1; /* Store value from result register of device to user buffer */
return ERR_OK; /* OK */
}

byte AD1_GetValue16(word *Values)
{
if (!OutFlg) /* Is output flag set? */
return ERR_NOTAVAIL; /* If no then error */
*Values = (getReg(ADCA_ADRSLT0) + 0) << 1; /* Store value from result register of device to user buffer */
return ERR_OK; /* OK */
}

unsigned int *pAD,*pAD1;
//float SamData;
unsigned int SamData,kk;
unsigned int ADC12Data;
void SendFloat(float Float);
void delay(int i);

void main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
pAD1=&kk;
/* Write your code here */
for(;;) {
int mm;
if(AD1_Measure(TRUE)==ERR_OK) //AD转换完成
{
AD1_GetValue16(pAD);
AD1_GetChanValue16(7,pAD1);
}
//SamData=(3.0*(*pAD))/32760;
SamData=((*pAD))/256;
PortB_PutVal(SamData);
SendFloat(SamData);
for(mm=0;mm<200;mm++)
delay(10000);

}
}

找到原因了~~还是我太菜了,豆配置里相应的sample没打开!~~

返回列表