你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

安臣学习stm32f072系列 +今天又重新啃了一下adc的那段pdf

[复制链接]
安臣 发布时间:2015-12-9 17:01
本帖最后由 安臣 于 2015-12-10 08:57 编辑

The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 19 multiplexed channels allowing it to measure signals from 16 external and 3 internal sources. A/D conversion of the various channels can be performed in single, continuous, scan or discontinuous mode. The result of the ADC is stored in a left-aligned or right-aligned 16-bit data register.

12位逐次逼近adc  19个通道 (包涵16个外部 和3个内部) 转换可以是 单次,连续,扫描 和断续模式  。结果可以左对齐或者右对齐存放。


关于校准Calibration (ADCAL)  

Calibration software procedure:
1.Ensure that ADEN=0   确认 aden 等于0
2. Set ADCAL=1   
3. Wait until ADCAL=0   等待校准完成
4. The calibration factor can be read from bits 6:0 of ADC_DR.  校准结果存放的位置。


库函数
  1. /**
  2.   * @brief  Perform an ADC automatic self-calibration
  3.   *         Calibration prerequisite: ADC must be disabled (execute this
  4.   *         function before HAL_ADC_Start() or after HAL_ADC_Stop() ).
  5.   * @note   Calibration factor can be read after calibration, using function
  6.   *         HAL_ADC_GetValue() (value on 7 bits: from DR[6;0]).
  7.   * @param  hadc: ADC handle
  8.   * @retval HAL status
  9.   */
  10. HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
  11. {
复制代码
Channel selection (CHSEL, SCANDIR)  关于通道配置
  1. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig)
复制代码


通道的宏定义

  1. /**
  2.   * @brief Configure the channel number into channel selection register
  3.   * @param _CHANNEL_: ADC Channel
  4.   * @retval None
  5.   */
  6. /* This function converts ADC channels from numbers (see defgroup ADC_channels)
  7.    to bitfields, to get the equivalence of CMSIS channels:
  8.         ADC_CHANNEL_0           ((uint32_t) ADC_CHSELR_CHSEL0)
  9.         ADC_CHANNEL_1           ((uint32_t) ADC_CHSELR_CHSEL1)
  10.         ADC_CHANNEL_2           ((uint32_t) ADC_CHSELR_CHSEL2)
  11.         ADC_CHANNEL_3           ((uint32_t) ADC_CHSELR_CHSEL3)
  12.         ADC_CHANNEL_4           ((uint32_t) ADC_CHSELR_CHSEL4)
  13.         ADC_CHANNEL_5           ((uint32_t) ADC_CHSELR_CHSEL5)
  14.         ADC_CHANNEL_6           ((uint32_t) ADC_CHSELR_CHSEL6)
  15.         ADC_CHANNEL_7           ((uint32_t) ADC_CHSELR_CHSEL7)
  16.         ADC_CHANNEL_8           ((uint32_t) ADC_CHSELR_CHSEL8)
  17.         ADC_CHANNEL_9           ((uint32_t) ADC_CHSELR_CHSEL9)
  18.         ADC_CHANNEL_10          ((uint32_t) ADC_CHSELR_CHSEL10)
  19.         ADC_CHANNEL_11          ((uint32_t) ADC_CHSELR_CHSEL11)
  20.         ADC_CHANNEL_12          ((uint32_t) ADC_CHSELR_CHSEL12)
  21.         ADC_CHANNEL_13          ((uint32_t) ADC_CHSELR_CHSEL13)
  22.         ADC_CHANNEL_14          ((uint32_t) ADC_CHSELR_CHSEL14)
  23.         ADC_CHANNEL_15          ((uint32_t) ADC_CHSELR_CHSEL15)
  24.         ADC_CHANNEL_16          ((uint32_t) ADC_CHSELR_CHSEL16)
  25.         ADC_CHANNEL_17          ((uint32_t) ADC_CHSELR_CHSEL17)
  26.         ADC_CHANNEL_18          ((uint32_t) ADC_CHSELR_CHSEL18)
  27. */
  28. #define ADC_CHSELR_CHANNEL(_CHANNEL_)                                          \
  29.   ( 1U << (_CHANNEL_))     
复制代码



关于转换模式

Single conversion mode (CONT=0)  单次转换
Conversion is started by either: 启动方式有两种
• Setting the ADSTART bit in the ADC_CR register   置位ADSTART 启动
• Hardware trigger event                                       硬件启动
Inside the sequence, after each conversion is complete:  结束每次转换
• The converted data are stored in the 16-bit ADC_DR register       数据在ADC_DR  寄存器
• The EOC (end of conversion) flag is set                                     EOC 中断 读取寄存器数据
• An interrupt is generated if the EOCIE bit is set            
After the sequence of conversions is complete:         序列转换完成
• The EOSEQ (end of sequence) flag is set               eos中断  准备开始接受下一次数据的状态。
• An interrupt is generated if the EOSEQIE bit is set



1.png


Continuous conversion mode (CONT=1) 连续转换
automatically re-starts and continuously performs the same sequence of conversions. This mode is selected when CONT=1 in the ADC_CFGR1 register. Conversion is started by either:
• Setting the ADSTART bit in the ADC_CR register   
• Hardware trigger event
Inside the sequence, after each conversion is complete:
• The converted data are stored in the 16-bit ADC_DR register
• The EOC (end of conversion) flag is set
• An interrupt is generated if the EOCIE bit is set
After the sequence of conversions is complete:
• The EOSEQ (end of sequence) flag is set
• An interrupt is generated if the EOSEQIE bit is set

一次序列转换结束后,ADC 立即重新转换相同的序列通道。


2.png
Discontinuous mode (DISCEN)

在这个模式(DISCEN=1) 下,需要硬件或软件的触发事件去启动定义在一个序列中的每次转换。
相反,DISCEN=0 时, 一个硬件或软件的触发事件就可以启动定义在一个序列中的所有转换。
例如:
● DISCEN=1, 需要转换的通道为: 0, 3, 7, 10
- 1st 触发:通道 0 被转换且一个 EOC事件产生
- 2nd 触发:通道 3 被转换且一个 EOC事件产生
- 3rd 触发:通道 7 被转换且一个 EOC事件产生
- 4th 触发:通道 10 被转换且产生EOC和 EOS事件
- 5th 触发:通道 0 被转换且一个 EOC事件产生
- 6th 触发:通道 3 被转换且一个 EOC事件产生
- ...
● DISCEN=0, 需要转换的通道为: 0, 3, 7, 10
- 1st 触发:整个完整的序列转换:依次为通道 0, 3, 7和 10。
每次转换产生一个EOC 事件,到最后一通道还产生一个EOS 事件。
- 任何触发事件都会重新开始完整的序列转换。


The EXTSEL[2:0] control bits are used to select which of 8 possible events can trigger conversions. (关于外部触发)
3.png

  1. void MX_ADC_Init(void)
  2. {

  3.   ADC_ChannelConfTypeDef sConfig;

  4.     /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  5.     */
  6.   hadc.Instance = ADC1;
  7.   hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC;
  8.   hadc.Init.Resolution = ADC_RESOLUTION12b;
  9.   hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  10.   hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  11.   hadc.Init.EOCSelection = EOC_SINGLE_CONV;
  12.   hadc.Init.LowPowerAutoWait = DISABLE;
  13.   hadc.Init.LowPowerAutoPowerOff = DISABLE;
  14.   hadc.Init.ContinuousConvMode = DISABLE;
  15.   hadc.Init.DiscontinuousConvMode = ENABLE;
  16.   hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
  17.   hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
  18.   hadc.Init.DMAContinuousRequests = DISABLE;
  19.   hadc.Init.Overrun = OVR_DATA_PRESERVED;
  20.   HAL_ADC_Init(&hadc);

  21.     /**Configure for the selected ADC regular channel to be converted.
  22.     */
  23.   sConfig.Channel = ADC_CHANNEL_0;
  24.   sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  25.   sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  26.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  27.     /**Configure for the selected ADC regular channel to be converted.
  28.     */
  29.   sConfig.Channel = ADC_CHANNEL_1;
  30.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  31.     /**Configure for the selected ADC regular channel to be converted.
  32.     */
  33.   sConfig.Channel = ADC_CHANNEL_2;
  34.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  35.     /**Configure for the selected ADC regular channel to be converted.
  36.     */
  37.   sConfig.Channel = ADC_CHANNEL_3;
  38.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  39.     /**Configure for the selected ADC regular channel to be converted.
  40.     */
  41.   sConfig.Channel = ADC_CHANNEL_4;
  42.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  43.     /**Configure for the selected ADC regular channel to be converted.
  44.     */
  45.   sConfig.Channel = ADC_CHANNEL_5;
  46.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  47.     /**Configure for the selected ADC regular channel to be converted.
  48.     */
  49.   sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
  50.   HAL_ADC_ConfigChannel(&hadc, &sConfig);

  51. }
复制代码



评分

参与人数 1 ST金币 +20 收起 理由
沐紫 + 20

查看全部评分

收藏 5 评论23 发布时间:2015-12-9 17:01

举报

23个回答
安臣 回答时间:2015-12-11 08:40:47
anger0925 发表于 2015-12-10 18:00
支持                 谢谢分享

也来这边逛逛啊?
zhangdaijin 回答时间:2015-12-11 08:54:39
                     
anger0925 回答时间:2015-12-10 18:00:30
支持                 谢谢分享
creep 回答时间:2015-12-9 17:13:48
很好的总结,收藏学习!!
悄然林静 回答时间:2015-12-9 18:02:15
撸主头像是黄土,羞羞羞~
Adrain_shine_30 回答时间:2015-12-9 18:08:47

很好的总结,收藏学习!!
埃斯提爱慕 回答时间:2015-12-9 20:47:20
提示: 作者被禁止或删除 内容自动屏蔽
风子 回答时间:2015-12-9 21:25:05
安臣大哥一直给我们带来好东西
安臣 回答时间:2015-12-10 08:58:17
creep 发表于 2015-12-9 17:13
很好的总结,收藏学习!!

最近的书进度慢了  也没有笔记
安臣 回答时间:2015-12-10 08:58:40
悄然林静 发表于 2015-12-9 18:02
撸主头像是黄土,羞羞羞~

  是吗?  这个是艺术品哦!
安臣 回答时间:2015-12-10 08:58:56
Adrain_shine_30 发表于 2015-12-9 18:08
很好的总结,收藏学习!!

感谢支持,共同进步
安臣 回答时间:2015-12-10 08:59:16
dsjsjf 发表于 2015-12-9 20:47
顶一下,谢谢分享

大神驾到,感谢支持
安臣 回答时间:2015-12-10 08:59:40
风子 发表于 2015-12-9 21:25
安臣大哥一直给我们带来好东西

哈哈。 有机会我会努力的
disheng4688 回答时间:2015-12-10 09:44:11
谢谢分享
JackieLaura 回答时间:2015-12-10 09:59:39
谢谢分享
stmcu.org.png
wamcncn 回答时间:2015-12-10 10:00:56
谢谢分享   
安臣 回答时间:2015-12-10 11:28:08

又见大神
12下一页

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版