历史上的今天
返回首页

历史上的今天

今天是:2024年10月27日(星期日)

正在发生

2021年10月27日 | stm32专题二十四:ADC 标准库函数分析

2021-10-27 来源:eefocus

ADC初始化结构体:


typedef struct

{

  uint32_t ADC_Mode;                      /*!< Configures the ADC to operate in independent or

                                               dual mode. 

                                               This parameter can be a value of @ref ADC_mode */

 

  FunctionalState ADC_ScanConvMode;       /*!< Specifies whether the conversion is performed in

                                               Scan (multichannels) or Single (one channel) mode.

                                               This parameter can be set to ENABLE or DISABLE */

 

  FunctionalState ADC_ContinuousConvMode; /*!< Specifies whether the conversion is performed in

                                               Continuous or Single mode.

                                               This parameter can be set to ENABLE or DISABLE. */

 

  uint32_t ADC_ExternalTrigConv;          /*!< Defines the external trigger used to start the analog

                                               to digital conversion of regular channels. This parameter

                                               can be a value of @ref ADC_external_trigger_sources_for_regular_channels_conversion */

 

  uint32_t ADC_DataAlign;                 /*!< Specifies whether the ADC data alignment is left or right.

                                               This parameter can be a value of @ref ADC_data_align */

 

  uint8_t ADC_NbrOfChannel;               /*!< Specifies the number of ADC channels that will be converted

                                               using the sequencer for regular channel group.

                                               This parameter must range from 1 to 16. */

}ADC_InitTypeDef;

(1)ADC模式: 一般选择独立模式;


/** @defgroup ADC_mode 

  * @{

  */

 

// 独立模式,最为常用

#define ADC_Mode_Independent                       ((uint32_t)0x00000000)

// 剩下的都是双ADC模式,包括同步、交叉、交替、混合等,不常用

#define ADC_Mode_RegInjecSimult                    ((uint32_t)0x00010000)

#define ADC_Mode_RegSimult_AlterTrig               ((uint32_t)0x00020000)

#define ADC_Mode_InjecSimult_FastInterl            ((uint32_t)0x00030000)

#define ADC_Mode_InjecSimult_SlowInterl            ((uint32_t)0x00040000)

#define ADC_Mode_InjecSimult                       ((uint32_t)0x00050000)

#define ADC_Mode_RegSimult                         ((uint32_t)0x00060000)

#define ADC_Mode_FastInterl                        ((uint32_t)0x00070000)

#define ADC_Mode_SlowInterl                        ((uint32_t)0x00080000)

#define ADC_Mode_AlterTrig                         ((uint32_t)0x00090000)

(2)ADC扫描模式:单通道 AD转换使用 DISABLE,多通道 AD转换使用 ENABLE;


(3)ADC连续转换:一般都会启用;


(4)外部触发选择:一般选择软件触发,也可以使用定时器触发 or 外部中断事件触发;


(5)ADC数据对齐:右对齐;


(6)ADC转换通道数量;


常用的标准固件库函数:


(1)ADC初始化函数


// 初始化ADC

void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);

(2)ADC时钟设置函数(设置分频系数),通常设置为6分频,ADCCLK = 12MHz


/**

  * @brief  Configures the ADC clock (ADCCLK).

  * @param  RCC_PCLK2: defines the ADC clock divider. This clock is derived from 

  *   the APB2 clock (PCLK2).

  *   This parameter can be one of the following values:

  *     @arg RCC_PCLK2_Div2: ADC clock = PCLK2/2

  *     @arg RCC_PCLK2_Div4: ADC clock = PCLK2/4

  *     @arg RCC_PCLK2_Div6: ADC clock = PCLK2/6

  *     @arg RCC_PCLK2_Div8: ADC clock = PCLK2/8

  * @retval None

  */

void RCC_ADCCLKConfig(uint32_t RCC_PCLK2)

{

  uint32_t tmpreg = 0;

  /* Check the parameters */

  assert_param(IS_RCC_ADCCLK(RCC_PCLK2));

  tmpreg = RCC->CFGR;

  /* Clear ADCPRE[1:0] bits */

  tmpreg &= CFGR_ADCPRE_Reset_Mask;

  /* Set ADCPRE[1:0] bits according to RCC_PCLK2 value */

  tmpreg |= RCC_PCLK2;

  /* Store the new value */

  RCC->CFGR = tmpreg;

}

(3)ADC规则通道配置函数(配置通道、转换顺序、采样周期)


/**

  * @brief  Configures for the selected ADC regular channel its corresponding

  *         rank in the sequencer and its sample time.

  * @param  ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.

  * @param  ADC_Channel: the ADC channel to configure. 

  *   This parameter can be one of the following values:

  *     @arg ADC_Channel_0: ADC Channel0 selected

  *     @arg ADC_Channel_1: ADC Channel1 selected

  *     @arg ADC_Channel_2: ADC Channel2 selected

  *     @arg ADC_Channel_3: ADC Channel3 selected

  *     @arg ADC_Channel_4: ADC Channel4 selected

  *     @arg ADC_Channel_5: ADC Channel5 selected

  *     @arg ADC_Channel_6: ADC Channel6 selected

  *     @arg ADC_Channel_7: ADC Channel7 selected

  *     @arg ADC_Channel_8: ADC Channel8 selected

  *     @arg ADC_Channel_9: ADC Channel9 selected

  *     @arg ADC_Channel_10: ADC Channel10 selected

  *     @arg ADC_Channel_11: ADC Channel11 selected

  *     @arg ADC_Channel_12: ADC Channel12 selected

  *     @arg ADC_Channel_13: ADC Channel13 selected

  *     @arg ADC_Channel_14: ADC Channel14 selected

  *     @arg ADC_Channel_15: ADC Channel15 selected

  *     @arg ADC_Channel_16: ADC Channel16 selected

  *     @arg ADC_Channel_17: ADC Channel17 selected

  * @param  Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16.

  * @param  ADC_SampleTime: The sample time value to be set for the selected channel. 

  *   This parameter can be one of the following values:

  *     @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles

  *     @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles

  *     @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles

  *     @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles

  *     @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles

  *     @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles

  *     @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles

  *     @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles

  * @retval None

  */

void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)

{

  uint32_t tmpreg1 = 0, tmpreg2 = 0;

  /* Check the parameters */

  assert_param(IS_ADC_ALL_PERIPH(ADCx));

  assert_param(IS_ADC_CHANNEL(ADC_Channel));

  assert_param(IS_ADC_REGULAR_RANK(Rank));

  assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));

  /* if ADC_Channel_10 ... ADC_Channel_17 is selected */

  if (ADC_Channel > ADC_Channel_9)

  {

    /* Get the old register value */

    tmpreg1 = ADCx->SMPR1;

    /* Calculate the mask to clear */

    tmpreg2 = SMPR1_SMP_Set << (3 * (ADC_Channel - 10));

    /* Clear the old channel sample time */

    tmpreg1 &= ~tmpreg2;

    /* Calculate the mask to set */

    tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));

    /* Set the new channel sample time */

    tmpreg1 |= tmpreg2;

    /* Store the new register value */

    ADCx->SMPR1 = tmpreg1;

  }

  else /* ADC_Channel include in ADC_Channel_[0..9] */

  {

    /* Get the old register value */

    tmpreg1 = ADCx->SMPR2;

    /* Calculate the mask to clear */

    tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel);

    /* Clear the old channel sample time */

推荐阅读

史海拾趣

Greenliant公司的发展小趣事

随着电动汽车市场的爆发式增长,GPS在2025年决定涉足电动汽车充电基础设施领域。公司推出了一系列快速、智能的电动汽车充电桩,支持多种充电标准和支付方式,满足了不同用户的需求。同时,GPS还开发了充电站管理软件,实现了充电桩的远程监控和运维管理,提高了充电服务的可靠性和便捷性。GPS的电动汽车充电基础设施解决方案在多个城市得到广泛应用,为电动汽车的普及提供了有力支持。

Chipcera Technology Co Ltd公司的发展小趣事

随着技术实力的不断增强,Chipcera开始将目光投向更广阔的市场。公司通过参加国际电子展会、与知名厂商合作等方式,积极推广自家产品。同时,公司还加大了对品牌建设的投入,通过提升产品质量、优化售后服务等措施,树立了良好的品牌形象。这些努力使得Chipcera的产品逐渐打入国际市场,成为行业内的佼佼者。

超霸(GP)公司的发展小趣事

2013年,绿索超容在南京江宁区智能电网产业园正式成立。公司自创立之初,就明确了“制造中国可靠性最高的超级电容”的目标,以及“引领超容行业,做绿色能源模范”的使命。这一清晰的发展定位,为绿索超容后续的技术创新和市场拓展奠定了坚实的基础。公司初期虽然面临资金和技术挑战,但通过不懈努力,逐步建立了自己的研发团队和生产体系。

Afero公司的发展小趣事

Afero的物联网平台在智能家居领域取得了显著的突破。他们与多家智能家居设备制造商合作,推出了一系列基于Afero平台的智能家居产品。这些产品通过统一的嵌入式、移动和云技术,实现了跨设备的安全通信和云通信,为用户提供了更加便捷、智能的家居体验。Afero平台还支持从制造到消费者使用的全过程设备连接,确保设备的安全性和可靠性。

GE Oil & Gas Digital Solutions公司的发展小趣事
检查电容和电阻元件是否有损坏或老化现象,检查电路布局是否合理以避免电磁干扰。
ESPROS [Espros Photonics corp]公司的发展小趣事

ESPROS的ToF传感器技术已成功应用于多个领域,包括无人机飞行避障及定高、人机交互和手势识别、机器人定位和智能导航、人体检测和物体探测、工业自动化以及汽车自动驾驶等。这些应用不仅展示了ESPROS技术的广泛适用性,也证明了其在光电传感器领域的强大实力。

问答坊 | AI 解惑

S2300 PCI-E开发平台

该开发实验板采用PCI-E x1接口,为方便用户进行自主开发,提供了80个可用的FPGA IO输入输出,用户可以自行设计应用接插板,如外部A/D数据采集,图象数据处理等系统应用,而不需要对PCI-E接口有过多的了解。       PCI-E接口芯 ...…

查看全部问答>

高手讲讲怎么才能作好FPGA

大虾:        小弟一直想做FPGA。书是看了不少,可是还是很迷茫。因为大部分就是一些简单的实例,也有一些稍微复杂一点的。可是我总是感觉没有长进。        比如:我看到好多设计中都用到FIFO,可是异 ...…

查看全部问答>

各类竞赛作品选编

本帖最后由 paulhyde 于 2014-9-15 09:08 编辑 很强大 各年竞赛的作品选编  …

查看全部问答>

求教 BCD BIN指令数据转换形式

各位高人 本人被这两个指令搞得头昏脑胀了 请指教 这两个指令中的数据时怎样变换的 我的理解:BIN: 例如键盘输入528400 要把这个输入数计入到数据寄存器里 用BIN指令 过程是不是把这个BCD码当作 十进制然后才成相应的二进制 0000 0000 0000 1000 0 ...…

查看全部问答>

求高人解惑!我用OP07设计的3倍输出电路运放,输出只能在1.69-4.33V之间,为什么?

第一次发图  不知道大家能看到不。 ------------------------------------ 我是用5V单电源供电,运放为OP07,便于实验,两个输入,U2接地,U1为0-4.5V的一个可调输入,参数设计为输出3倍的电压, 但是试验中,当我输入电压的3倍低于1 ...…

查看全部问答>

EVC连接出错.

我将PB下面的printer USB程序copy到一个文件夹中. 用EVC4新建一个dll工程. 并包含这些C.H文件及设置路径. 编译连接出错如下:    Creating library ARMV4IRel/apdusb.lib and object ARMV4IRel/apdusb.exp usbapd.obj : error LNK2019: ...…

查看全部问答>

一般没解压的NK.NB0比压缩的NK.BIN文件大多少呢

一般没解压的NK.NB0比压缩的NK.BIN文件大多少呢?? 例如30M的NK.BIN文件转成NK.NBO一般是多大呢…

查看全部问答>

有AXD 和MULTIICE仿真遇到的断点问题

我先有MULIICESERVER连的板子。BIOS已经烧到了板子的NORFLASH里面。 在用AXD调试。用LOAD把调试镜象.AXF文件下到板子里面.怎么只能在main函数设置断点.而且就能设置2次.设置2次以后清楚断点继续设置断点运行后.就不停止了. 这是为什么.…

查看全部问答>

怎样对nandflash分两个fat区?

我目前使用的是freescale m31+ce5.0系统,通过修改hive注册表后,512m的nandflash现在已经有fat分区,并且在系统启动后能现在nand flash的磁盘。 我现在想改成两个fat的分区,一个用与存放system.hv等注册表和系统的一些应用程序,另一个提供用户 ...…

查看全部问答>

W5100的中断方式与单片机联合编程

    w5100是自带网络协议的芯片,具体我不讲了,我就讲下中断方式应用,这个应用是采用TCP/IP网络协议,单片机是客户端跟服务器进行相连的。     这里先讲两种寄存器,W5100_IR和W5100_S0_IR,后面这个这个芯片总共 ...…

查看全部问答>