打印
[综合信息]

华大HC32F003☆ ---ADC例程分享(部分一)

[复制链接]
1266|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
LED2013|  楼主 | 2020-8-7 10:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 LED2013 于 2020-8-7 10:28 编辑

版本历史
日期 版本 负责人 IAR MDK 描述
2017-06-07 0.1 虹芯侠客 7.70 5.16A first version

====================================
功能描述

本样例主要展示ADC 单通道连续采样示例,使用中断方式获取ADC运行状态。
说明:
配置ADC并开始采样,ADC中断发生标志连续转换完成,读取累加转换结果

================================================================================
测试环境
测试用板:辅助工具:

示波器
电源

辅助软件:

====================================
使用步骤

1)打开工程编译并运行
2)查看串口输出

====================================
注意

调试串口的使用:
调试串口在系统时钟使用高速晶振时可用,PIN为P35. 波特率为19200, 8N1.

================================================================

/****************************************************************************/
/ \file main.c
**
** A detailed description is available at
*
* @link Sample Group Some description @endlink

**
** - 2017-05-28 LiuHL First Version
**
******************************************************************************/

/******************************************************************************

  • Include files
    ******************************************************************************/
    #include “adc.h”
    #include “gpio.h”

/******************************************************************************

  • Local pre-processor symbols/macros (’#define’)
    ******************************************************************************/
    #define DEBUG_PRINT

/******************************************************************************

  • Global variable definitions (declared in header file with ‘extern’)
    ******************************************************************************/

/******************************************************************************

  • Local type definitions (‘typedef’)
    ******************************************************************************/

/******************************************************************************

  • Local function prototypes (‘static’)
    ******************************************************************************/

/******************************************************************************

  • Local variable definitions (‘static’) *
    ******************************************************************************/
    static stc_adc_irq_t stcAdcIrqFlag;

/*****************************************************************************

  • Function implementation - global (‘extern’) and local (‘static’)
    ******************************************************************************/

void AdcContIrqCallback(void)
{
// Adc_DisableIrq();
// Adc_ClrContIrqState();
stcAdcIrqFlag.bAdcIrq = TRUE;
}
void AdcRegIrqCallback(void)
{
// Adc_DisableIrq();
// Adc_ClrRegIrqState();
stcAdcIrqFlag.bAdcRegCmp = TRUE;
}

void AdcHhtIrqCallback(void)
{
// Adc_DisableIrq();
// Adc_ClrHhtIrqState();
stcAdcIrqFlag.bAdcHhtCmp = TRUE;
}

void AdcLltIrqCallback(void)
{
// Adc_DisableIrq();
// Adc_ClrLltIrqState();
stcAdcIrqFlag.bAdcLltCmp = TRUE;
}

/**


** \brief Main function of project
**
** \return uint32_t return value, if needed
**
** This sample
**
******************************************************************************/
int32_t main(void)
{
stc_adc_cfg_t stcAdcCfg;
stc_adc_cont_cfg_t stcAdcContCfg;
stc_adc_irq_t stcAdcIrq;
stc_adc_irq_calbakfn_pt_t stcAdcIrqCalbaks;
uint32_t u32AdcResultAcc;

DDL_ZERO_STRUCT(stcAdcCfg);DDL_ZERO_STRUCT(stcAdcContCfg);DDL_ZERO_STRUCT(stcAdcIrq);DDL_ZERO_STRUCT(stcAdcIrqCalbaks);DDL_ZERO_STRUCT(stcAdcIrqFlag);Clk_SwitchTo(ClkXTH);Clk_SetPeripheralGate(ClkPeripheralUart0, TRUE);Clk_SetPeripheralGate(ClkPeripheralBt, TRUE);    Clk_SetPeripheralGate(ClkPeripheralGpio, TRUE);#ifdef DEBUG_PRINTDebug_UartInit();#endifif (Ok != Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE)){    return 1;}    printf("ADC continuous sampling INTR test start.\n");Gpio_SetAnalog(2, 4, TRUE);Gpio_SetAnalog(2, 6, TRUE);// Gpio_SetAnalog(3, 5, TRUE);//ADC配置Adc_Enable();M0P_BGR->CR_f.BGR_EN = 0x1u;//BGR必须使能M0P_BGR->CR_f.TS_EN = 0x1u;delay100us(1);stcAdcCfg.enAdcOpMode = AdcContMode;//连续采样模式stcAdcCfg.enAdcClkSel = AdcClkSysTDiv1;stcAdcCfg.enAdcSampTimeSel = AdcSampTime4Clk;// stcAdcCfg.enAdcRefVolSel = RefVolSelInBgr2p5;stcAdcCfg.enAdcRefVolSel = RefVolSelAVDD;// stcAdcCfg.bAdcInBufEn = TRUE;stcAdcCfg.bAdcInBufEn = FALSE;stcAdcCfg.enAdcTrig0Sel = AdcTrigDisable;stcAdcCfg.enAdcTrig1Sel = AdcTrigDisable;Adc_Init(&stcAdcCfg);    stcAdcIrq.bAdcIrq = TRUE;stcAdcIrq.bAdcRegCmp = FALSE;stcAdcIrq.bAdcHhtCmp = FALSE;stcAdcIrq.bAdcLltCmp = FALSE;stcAdcIrqCalbaks.pfnAdcContIrq = AdcContIrqCallback;stcAdcIrqCalbaks.pfnAdcRegIrq = AdcRegIrqCallback;stcAdcIrqCalbaks.pfnAdcHhtIrq = AdcHhtIrqCallback;stcAdcIrqCalbaks.pfnAdcLltIrq = AdcLltIrqCallback;Adc_ConfigIrq(&stcAdcIrq, &stcAdcIrqCalbaks);Adc_EnableIrq();Adc_CmpCfg(&stcAdcIrq);//stcAdcContCfg.enAdcContModeCh = AdcAiTsInput;stcAdcContCfg.enAdcContModeCh = AdcExInputCH0;stcAdcContCfg.u8AdcSampCnt = 0xFFu;stcAdcContCfg.bAdcResultAccEn = TRUE;Adc_ConfigContMode(&stcAdcCfg, &stcAdcContCfg);while(1){    Adc_Start();//ADC开始转换    while(FALSE == stcAdcIrqFlag.bAdcIrq);    Adc_DisableIrq();        #ifdef DEBUG_PRINT    if (FALSE != stcAdcIrqFlag.bAdcIrq)    {        printf("Cont IRQ Fired!\n");    }    #endif    Adc_GetAccResult(&u32AdcResultAcc);    Adc_ClrAccResult();    #ifdef DEBUG_PRINT    printf("CH: %d, SampCnt: 0x%X, AdcVal_acc: 0x%X, AdcVal_avg: 0x%X\n",             stcAdcContCfg.enAdcContModeCh,             stcAdcContCfg.u8AdcSampCnt,             u32AdcResultAcc,            u32AdcResultAcc/(stcAdcContCfg.u8AdcSampCnt+1));    #endif            delay1ms(1000);    Adc_Init(&stcAdcCfg);    Adc_ConfigIrq(&stcAdcIrq, &stcAdcIrqCalbaks);    Adc_EnableIrq();    Adc_ConfigContMode(&stcAdcCfg, &stcAdcContCfg);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

}

/******************************************************************************

  • EOF (not truncated)
    ******************************************************************************/

使用特权

评论回复
沙发
labasi| | 2020-9-4 13:32 | 只看该作者
感谢楼主分享资料

使用特权

评论回复
板凳
paotangsan| | 2020-9-4 13:33 | 只看该作者
支持楼主 不错!

使用特权

评论回复
地板
renzheshengui| | 2020-9-4 13:34 | 只看该作者
路过 学习下

使用特权

评论回复
5
wakayi| | 2020-9-4 13:34 | 只看该作者
长知识了 呵呵

使用特权

评论回复
6
wowu| | 2020-9-4 13:35 | 只看该作者
排版有些乱

使用特权

评论回复
7
hugewinner| | 2020-9-8 14:01 | 只看该作者
路过 学习下 谢谢楼主分享

使用特权

评论回复
8
rgbgirl| | 2021-3-5 10:53 | 只看该作者
代码比较乱,一定要看例程了

使用特权

评论回复
9
七毛钱| | 2021-3-5 15:28 | 只看该作者
代码比较乱

使用特权

评论回复
10
liangshuang95| | 2021-3-9 20:55 | 只看该作者
上传文件可能要好点

使用特权

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

本版积分规则

2167

主题

28450

帖子

24

粉丝