打印
[MCU]

请教ADC旋转按钮中函数调用问题

[复制链接]
1436|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
59387033|  楼主 | 2015-1-20 17:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
获得Volunme的值
Volume = Get_ADC_Knob();
函数定义如下:
uint32_t Get_ADC_Knob(void)
{
    uint32_t ADC_Raw_Data;
    /* Clear the A/D ADI NT0 interrupt flag */
    EADC_CLR_INT_FLAG(EADC, 0x1);

    //Trigger sample module 0 to start A/D conversion
    EADC_START_CONV(EADC, 0x1);

    /* Wait ADC interrupt (g_u32AdcIntFlag will be set at IRQ_Handler function) */
    while(EADC_GET_INT_FLAG(EADC, 0x1) == 0);
    ADC_Raw_Data = EADC_GET_CONV_DATA(EADC, 0);

    return ADC_Raw_Data;
}

EADC_GET_CONV_DATA函数的定义如下:
/**
  * @brief Get the conversion data of the user-specified sample module.
  * @param[in] eadc Base address of EADC module.
  * @param[in] u32ModuleNum Decides the sample module number, valid value are from 0 to 18.
  * @return Return the conversion data of the user-specified sample module.
  * @details This macro is used to read RESULT bit (EADC_DATn[15:0], n=0~18) field to get conversion data.
  */
#define EADC_GET_CONV_DATA(eadc, u32ModuleNum) ((eadc)->DAT[(u32ModuleNum)] & EADC_DAT_RESULT_Msk)

我的问题是在函数Get_ADC_Knob()中EADC_GET_CONV_DATA(EADC, 0),u32ModuleNum的值不是已经被设定为0了吗,那么它又是如何根据我旋转按钮而最终改变volume的值的??
还是我的理解有错?volume的值究竟是如何根据我旋转MCU上的按钮而随之改变的?

相关帖子

沙发
59387033|  楼主 | 2015-1-20 18:53 | 只看该作者
问题已解决
EADC位于APB总线,地址空间为:0X4000_3000-0X4004_3FFF,变化范围为0-4095。
(eadc)->DAT[(u32ModuleNum)]中DAT数组定义如下:
/**
     * DATn, n=0~18
     * ===================================================================================================
     * Offset: 0x00-0x48  A/D Data Register n for Sample Module n, n=0~18
     * ---------------------------------------------------------------------------------------------------
     * |Bits    |Field     |Descriptions
     * | :----: | :----:   | :---- |
     * |[15:0]  |RESULT    |A/D Conversion Result
     * |        |          |This field contains 12 bits conversion result.
     * |        |          |When DMOF (EADC_CTL[9]) is set to 0, 12-bit ADC conversion result with unsigned format will be filled in RESULT[11:0] and zero will be filled in RESULT[15:12].
     * |        |          |When DMOF (EADC_CTL[9]) set to 1, 12-bit ADC conversion result with 2'complement format will be filled in RESULT[11:0] and signed bits to will be filled in RESULT[15:12].
     * |[16]    |OV        |Overrun Flag
     * |        |          |If converted data in RESULT[11:0] has not been read before new conversion result is loaded to this register, OV is set to 1.
     * |        |          |0 = Data in RESULT[11:0] is recent conversion result.
     * |        |          |1 = Data in RESULT[11:0] is overwrite.
     * |        |          |Note: It is cleared by hardware after EADC_DAT register is read.
     * |[17]    |VALID     |Valid Flag
     * |        |          |This bit is set to 1 when corresponding sample module channel analog input conversion is completed and cleared by hardware after EADC_DAT register is read.
     * |        |          |0 = Data in RESULT[11:0] bits is not valid.
     * |        |          |1 = Data in RESULT[11:0] bits is valid.
     */
它用于存储APB EADC_BA返回的值,并且存在其0-11位中

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

26

帖子

0

粉丝