思澈科技软件开发工具包  2.20
ADC

ADC HAL 提供用于访问 adc 外设寄存器的基本 API。 主要功能包括:

  • 最多支持 8 个 ADC 通道。
  • 10 位数据(A0), 12 位数据(PRO)。
  • DMA 支持。

使用 ADC HAL 驱动程序:

ADC 可支持 8 个通道,每一比特的变化对应电压大约在1毫伏左右,具体需要根据每颗芯片单独校准。 测试量程,A0上为 0~ 1.1V, PRO上为 0 ~ 3.3V.

在轮询模式下使用 ADC HAL 的示例:

uint32_t channel, value, timeout;
/* initial handle */
hadc.Instance = hwp_gpadc1;
#ifndef SF32LB55X
hadc.Init.data_samp_delay = 2;
hadc.Init.conv_width = 24;
hadc.Init.sample_width = 22;
#else
hadc.Init.clk_div = 31; // set frequency
#endif
hadc.Init.adc_se = 1; // single channel
hadc.Init.adc_force_on = 0;
hadc.Init.dma_en = 0; // no dma
hadc.Init.en_slot = 0; // default slot, update by enable and configure
hadc.Init.op_mode = 0; // single mode, not continous
/* initial ADC controller */
ret = HAL_ADC_Init(&hadc);
/* enable ADC */
channel = 1;
HAL_ADC_EnableSlot(&hadc, channel, 1);
/* configure ADC */
rt_memset(&ADC_ChanConf, 0, sizeof(ADC_ChanConf));
ADC_ChanConf.Channel = channel;
ADC_ChanConf.pchnl_sel = channel;
ADC_ChanConf.slot_en = 1;
HAL_ADC_ConfigChannel(&hadc, &ADC_ChanConf);
/* start ADC */
/* Wait for the ADC to convert */
timeout = 100; // 100 ms
HAL_ADC_PollForConversion(&hadc, tmieout);
/* Get ADC value */
value = (rt_uint32_t)HAL_ADC_GetValue(&hadc, channel);
...
ADC_HandleTypeDef::Instance
GPADC_TypeDef * Instance
Definition: bf0_hal_adc.h:175
HAL_ADC_Start
HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc)
Enables ADC, starts conversion of regular group. Interruptions enabled in this function: None.
ADC_ChannelConfTypeDef
Structure definition of ADC channel for regular group.
Definition: bf0_hal_adc.h:132
HAL_ADC_Init
HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc)
Initializes the ADC peripheral and regular group according to parameters specified in structure "ADC_...
ADC_HandleTypeDef
ADC handle Structure definition.
Definition: bf0_hal_adc.h:174
ADC_HandleTypeDef::Init
ADC_InitTypeDef Init
Definition: bf0_hal_adc.h:177
HAL_ADC_PollForConversion
HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout)
Wait for regular group conversion to be completed.
HAL_ADC_ConfigChannel
HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig)
Configures the the selected channel to be linked to the regular group.
HAL_ADC_EnableSlot
HAL_StatusTypeDef HAL_ADC_EnableSlot(ADC_HandleTypeDef *hadc, uint32_t slot, uint8_t en)
Enable/Disable ADC slot/channel.
HAL_ADC_GetValue
uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc, uint32_t slot)
Get ADC convert result.