导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    采用GPADC的查询模式总是不能获得电压

    V Series
    1
    1
    921
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Z
      zealsoft LV 3 最后由 编辑

      在裸机环境按照手册的说明设置GPADC0为查询模式,但总是得不到电压值。
      在设置连续转换模式之后和使能ADC之后读取GP_CTRL,发现总是默认值0x800000,和设置啥无关。
      哪些帮忙看看,谢谢。
      程序大致如下:
      unsigned int ra;
      unsigned int x, d;

      /* init GPADC */
      /* 1. Write 0x1 to the bit[16] of GPADC_BGR_REG (Offset: 0x09EC) to dessert reset. */
      PUT32(GPADC_BGR, 1 << 16);
      /* 2. Write 0x1 to the bit[0] of GPADC_BGR_REG (Offset: 0x09EC) to enable the GPADC clock. */
      PUT32(GPADC_BGR, 1);
      /* 3. Write 0x2F to the bit[15:0] of GP_SR_CON (Offset: 0x0000) to set the acquiring time of ADC.
         4. Write 0x1DF to the bit[31:16] of GP_SR_CON (Offset: 0x0000) to set the ADC sample frequency divider. */
      PUT32(GP_SR_CON, 0x1df002f);
      /* 5. Write 0x2 to the bit[19:18] of GP_CTRL (Offset: 0x0004 ) to set the continuous conversion mode.*/
      ra = GET32(GP_CTRL) & ~(0x03 << 18);
      PUT32(GP_CTRL, ra | (0x02 << 18));
      /* 6. Write 0x1 to the bit[0] of GP_CS_EN (Offset: 0x0008) to enable the analog input channel. */
      ra = GET32(GP_CS_EN);
      PUT32(GP_CS_EN, ra | 1);
      /* 7. Write 0x1 to the bit[16] of GP_CTRL (Offset: 0x0004) to enable the ADC function.*/
      ra = GET32(GP_CTRL);
      ra = GET32(GP_CTRL) & ~(0x09 << 16);
      PUT32(GP_CTRL, ra | (0x09 << 16));
      
      /* queue the key states */
      while(1)
      {
          /* 8. Read the bit[0] of GP_DATA_INTS (Offset: 0x0038), if the bit is 1, then data conversion is complete.*/
          x = GET32(GP_DATA_INTS);
      if(x & 1)
      {
         d = GET32(GP_CH0_DATA) & 0xfff;
         hexstring(d);
      }
          DELAY(0x1000000);
      }
      
      1 条回复 最后回复 回复 引用 分享 0
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策