[技术问答] N76E003的ADC采集问题

[复制链接]
 楼主| ltwsq 发表于 2017-2-21 13:51 | 显示全部楼层 |阅读模式
使用开发板,运行官方例程,进行ADC采集,但在转换的过程当中,运行到
while(ADCF==0);时,一直死循环在这里,也就是说无法完成ADC采集,这是为什么啊?
zhuomuniao110 发表于 2017-2-21 18:57 | 显示全部楼层
应该没有启动成功那个ADC模块。
zhuomuniao110 发表于 2017-2-21 19:00 | 显示全部楼层
zhuomuniao110 发表于 2017-2-21 19:01 | 显示全部楼层
zhuomuniao110 发表于 2017-2-21 19:02 | 显示全部楼层
注意这个跟其他的N76系列的ADC是不同的,这个是12BIT。
zhuomuniao110 发表于 2017-2-21 19:06 | 显示全部楼层
目前可恶的是,官方给了其他几个系列的例程序,没有给这个的,而且只有一个英文的手册,坑。
zhuomuniao110 发表于 2017-2-21 19:35 | 显示全部楼层
楼主对照那个图看看吧,哪个寄存器还没有配置呢。
玛尼玛尼哄 发表于 2017-2-21 21:53 | 显示全部楼层
没例程,没有板子,不好验证,你板子哪儿来的,问卖给你板子的人有没有例程,可能是官方有,没有上传嗯。
wuhuikai 发表于 2017-2-22 08:34 | 显示全部楼层
这个已经调通

void AdcInit(void){  //ADC初始化
  ADCCON0 &=0XF0;
  ADCCON0|=8;//1.通道
  ADCCON1|=BV(0);
  ADCF=0;
}

uint16_t AdValue(uint8_t ch){//通道CH电压值 10次和
  uint16_t AdTemp1=0,AdTemp2=0;
  uint8_t i=0;
  ADCCON0 &=0XF0;
  ADCCON0 |= ch;
  ADCS=1;
  while(ADCF==0);//除出上一次的结果
  ADCF=0;
  for(i=0;i<10;i++){
    ADCS = 1;           //使能adc
    while(ADCF==0);
    ADCF=0;
    AdTemp1=ADCRL;
    AdTemp1 += ADCRH<<4;
    AdTemp2 += AdTemp1;
  }
  return AdTemp2;
}

uint16_t VbatValue(uint8_t ch){  //通道ch电压
  return  ((uint32_t)1220*(uint32_t)AdValue(ch)/(uint32_t)AdValue(8));
}
rwbycc 发表于 2017-2-22 13:34 | 显示全部楼层
用ADC中断比较好
郑州海源 发表于 2017-5-5 11:59 | 显示全部楼层
遇到多通道切换采集的,才头疼。官方也没个例子参考,只能自己摸索了。
Harvard 发表于 2017-5-5 13:46 | 显示全部楼层
本身不难 .在查询完成标记的时候 关注一下 看门狗的情况
sun420410089 发表于 2017-5-5 17:14 | 显示全部楼层
mark,说不定哪天需要用这芯片的ADC功能了
wahahaheihei 发表于 2017-5-7 15:22 | 显示全部楼层
搞定了没,之前什么缘故?
xixi2017 发表于 2017-5-8 10:57 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2016 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E885 ADC demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include "N76E003.h"
  17. #include "Common.h"
  18. #include "Delay.h"
  19. #include "SFR_Macro.h"
  20. #include "Function_Define.h"



  21. //*****************  The Following is in define in Fucntion_define.h  ***************************
  22. //****** Always include Function_define.h call the define you want, detail see main(void) *******
  23. //***********************************************************************************************
  24. #if 0
  25. //#define Enable_ADC_AIN0                        ADCCON0&=0xF0;P17_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT0;ADCCON1|=SET_BIT0                                                                        //P17
  26. //#define Enable_ADC_AIN1                        ADCCON0&=0xF0;ADCCON0|=0x01;P30_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT1;ADCCON1|=SET_BIT0                //P30
  27. //#define Enable_ADC_AIN2                        ADCCON0&=0xF0;ADCCON0|=0x02;P07_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT2;ADCCON1|=SET_BIT0                //P07
  28. //#define Enable_ADC_AIN3                        ADCCON0&=0xF0;ADCCON0|=0x03;P06_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT3;ADCCON1|=SET_BIT0                //P06
  29. //#define Enable_ADC_AIN4                        ADCCON0&=0xF0;ADCCON0|=0x04;P05_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT4;ADCCON1|=SET_BIT0                //P05
  30. //#define Enable_ADC_AIN5                        ADCCON0&=0xF0;ADCCON0|=0x05;P04_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT5;ADCCON1|=SET_BIT0                //P04
  31. //#define Enable_ADC_AIN6                        ADCCON0&=0xF0;ADCCON0|=0x06;P03_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT6;ADCCON1|=SET_BIT0                //P03
  32. //#define Enable_ADC_AIN7                        ADCCON0&=0xF0;ADCCON0|=0x07;P11_Input_Mode;AINDIDS=0x00;AINDIDS|=SET_BIT7;ADCCON1|=SET_BIT0                //P11
  33. //#define Enable_ADC_BandGap        ADCCON0|=SET_BIT3;ADCCON0&=0xF8;                                                                                                                                                                                                                                                        //Band-gap 1.22V

  34. //#define PWM0_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  35. //#define PWM2_FALLINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  36. //#define PWM4_FALLINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1&=~SET_BIT2;ADCCON1|=SET_BIT1
  37. //#define PWM0_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
  38. //#define PWM2_RISINGEDGE_TRIG_ADC                ADCCON0&=~SET_BIT5;ADCCON0|=SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1
  39. //#define PWM4_RISINGEDGE_TRIG_ADC                ADCCON0|=SET_BIT5;ADCCON0&=~SET_BIT4;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1

  40. //#define P04_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
  41. //#define P13_FALLINGEDGE_TRIG_ADC                ADCCON0|=0x30;ADCCON1&=0xF3;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
  42. //#define P04_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1&=~SET_BIT6
  43. //#define P13_RISINGEDGE_TRIG_ADC                        ADCCON0|=0x30;ADCCON1&=~SET_BIT3;ADCCON1|=SET_BIT2;ADCCON1|=SET_BIT1;ADCCON1|=SET_BIT6
  44. #endif

  45. /******************************************************************************
  46. The main C function.  Program execution starts
  47. here after stack initialization.
  48. ******************************************************************************/
  49. void main (void)
  50. {
  51.     Set_All_GPIO_Quasi_Mode;
  52.                 InitialUART0_Timer1(115200);
  53.           
  54. /*-------------------------------------------
  55.         ADC simply initial setting
  56. --------------------------------------------*/
  57. //                Enable_ADC_AIN3;                                                                                                                // Enable AIN0 P1.7 as ADC input
  58.                 Enable_ADC_BandGap;

  59.                 while(1)
  60.     {
  61.                         clr_ADCF;
  62.                         set_ADCS;                                                                                                                                        // Each time ADC start trig signal
  63.       while(ADCF == 0);
  64.                         printf ("\n Value = 0x%bx",ADCRH);
  65.                                 printf ("\n Value = 0x%bx",ADCRL);
  66.                         Timer0_Delay1ms(100);
  67.     }
  68. }

xixi2017 发表于 2017-5-8 10:57 | 显示全部楼层
上面的这个例程跑起来有问题?你用的是官方的那个开发板 吗?应该没问题啊
chen472015439 发表于 2017-8-4 11:45 | 显示全部楼层
mark一下,碰GPIO不够用又需要多个按键的时候,估计要用ADC做按键
smilefenfen 发表于 2018-4-28 11:20 | 显示全部楼层
wuhuikai 发表于 2017-2-22 08:34
这个已经调通

void AdcInit(void){  //ADC初始化

有点晕
jack5288 发表于 2018-7-23 11:07 | 显示全部楼层
我在调试时也发现这个问题,运行到while(ADCF==0);时,一直死循环在这里,现在找到原因了吗,是什么原因分享下你经验。
g562225639 发表于 2019-9-16 16:12 | 显示全部楼层
void ADC_Init(void)
{
        Enable_ADC_AIN5; //选择P0.4
        ADCMgr.AdcValue = 0;
}

/**
  * @brief  获取ADC
  * @param  NONE
  * @retval ADC Value
  */
void Get_ADCResult(void)
{
        u8 i;
        for(i=0; i<4; i++)
        {
                clr_ADCF;
                set_ADCS;         //启动ACD转换
                while(ADCF == 0)
                        ADCMgr.AdcValue += ((ADCRH<<4)|(ADCRL&0x0F));
        }
        ADCMgr.AdcValue  = ADCMgr.AdcValue>>2;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

14

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

8

主题

14

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部