STM32的ADC转换(普通模式)

ADC学习记录
摘要由CSDN通过智能技术生成

一、ADC,模拟数字转换器

1、定义

ADC(Analog to Digital Converter) :模数变换器;简称“模数转换器”,把模拟量转换为数字量的装置。
在计算机控制系统中,须经各种检测装置,以连续变化的电压或电流作为模拟量,随时提供被控制对象的有关参数(如速度、压力、温度等)而进行控制。计算机的输入必须是数字量,故需用模数转换器达到控制目的,过程有抽样、量化、编码(PCM编码,脉冲编码调制)。

其次简单介绍一下PCM编码:
(1)抽样:就是对模拟信号进行周期性扫描,把时间上连续的信号变成时间上离散的信号。该模拟信号经过抽样后述应当包含原信号中所有信息,也就是说能无失真的恢复原模拟信号。
(2)量化:就是把经过抽样得到的瞬时值将其幅度离散,即用一组规定的电平,把瞬时抽样值用最接近的电平值来表示,通常是用二进制表示。
(3)编码:就是用一组二进制码组来表示每一个有固定电平的量化值。然而,实际上量化是在编码过程中同时完成的,故编码过程也称为模/数变换,可记作A/D。
在这里插入图片描述

2、模拟信号

模拟信号是指用连续变化的物理量表示的信息,其信号的幅度,或频率,或相位随时间作连续变化,如目前广播的声音信号,或图像信号等。抓重点,连续的,如正弦波。

3、数字信号

数字信号指幅度的取值是离散的,幅值表示被限制在有限个数值之内。
二进制码就是一种数字信号。二进制码受噪声的影响小,易于有数字电路进行处理,所以得到了广泛的应用。抓重点,离散的,但在示波器中的方波一般指的是数字信号,把竖线去掉就是离散的了。

4、常用库函数

a.根据ADC_CommonInitTypeDef结构体,初始化ADC外设指定的参数(容易被忽略)

typedef struct 
{
   
  uint32_t ADC_Mode;                      /*!< Configures the ADC to operate in 
                                               independent or multi mode. 
                                               This parameter can be a value of @ref ADC_Common_mode */                                              
  uint32_t ADC_Prescaler;                 /*!< Select the frequency of the clock 
                                               to the ADC. The clock is common for all the ADCs.
                                               This parameter can be a value of @ref ADC_Prescaler */
  uint32_t ADC_DMAAccessMode;             /*!< Configures the Direct memory access 
                                              mode for multi ADC mode.
                                               This parameter can be a value of 
                                               @ref ADC_Direct_memory_access_mode_for_multi_mode */
  uint32_t ADC_TwoSamplingDelay;          /*!< Configures the Delay between 2 sampling phases.
                                               This parameter can be a value of 
                                               @ref ADC_delay_between_2_sampling_phases */
  
}ADC_CommonInitTypeDef;
  • @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure that contains the configuration information for All ADCs peripherals.
void ADC_CommonInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)

b.根据ADC_InitTypeDef结构体,初始化ADC外设指定的参数

typedef struct
{
   
  uint32_t ADC_Resolution;                /*!< Configures the ADC resolution dual mode. 
                                               This parameter can be a value of @ref ADC_resolution */                                   
  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_ExternalTrigConvEdge;      /*!< Select the external trigger edge and
                                               enable the trigger of a regular group. 
                                               This parameter can be a value of 
                                               @ref ADC_external_trigger_edge_for_regular_channels_conversion */
  uint32_t ADC_ExternalTrigConv;          /*!< Select the external event used to trigger 
                                               the start of conversion of a regular group.
                                               This parameter can be a value of 
                                               @ref ADC_extrenal_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_NbrOfConversion;           /*!< Specifies the number of ADC conversions
                                               that will be done using the sequencer for
                                               regular channel group.
                                               This parameter must range from 1 to 16. */
}ADC_InitTypeDef;
  • @brief Initializes the ADCx peripheral according to the specified parameters in the ADC_InitStruct.
  • @note This function is used to configure the global features of the ADC ( Resolution and Data Alignment), however, the rest of the configuration
  • parameters are specific to the regular channels group (scan mode activation, continuous mode activation, External trigger source and edge, number of conversion in the regular channels group sequencer).
  • @param  ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
    
  • @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains the configuration information for the specified ADC peripheral.
void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)

c.为选定的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~~~~~~arg ADC_Channel_18
    
  • @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_3Cycles: Sample time equal to 3 cycles
    
  •        @arg ADC_SampleTime_15Cycles: Sample time equal to 15 cycles
    
  •        @arg ADC_SampleTime_28Cycles: Sample time equal to 28 cycles
    
  •        @arg ADC_SampleTime_56Cycles: Sample time equal to 56 cycles	
    
  •        @arg ADC_SampleTime_84Cycles: Sample time equal to 84 cycles	
    
  •        @arg ADC_SampleTime_112Cycles: Sample time equal to 112 cycles	
    
  •        @arg ADC_SampleTime_144Cycles: Sample time equal to 144 cycles	
    
  •        @arg ADC_SampleTime_480Cycles: Sample time equal to 480 cycles	
    
void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)

例如是42MHZ,3cycle采集一次,那么时间

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: STM32ADC(模数转换器)有独立模式和双模式两种工作方式。 独立模式下,ADC模块可以独立地进行模数转换。它可以通过单次转换触发或定时触发进行转换操作。单次转换是指只进行一次转换即停止,适用于单通道的转换需求。定时触发是指在定时器的周期性触发下进行转换,适用于需要连续转换多个通道的情况。在独立模式中,ADC的控制寄存器和转换寄存器都是独立的。 双模式下,ADC模块可以与定时器和DMA(直接内存访问)模块进行配合。双模式主要有常规组和注入组两种模式。常规组模式指的是使用常规转换组进行普通的模数转换操作。常规转换组的转换操作可以与定时器进行配合,通过定时触发进行连续转换。注入组模式则是指使用注入转换组进行特殊的模数转换操作。注入转换组可以与DMA进行配合,通过DMA方式将转换数据传输到目标地址。在双模式下,可以同时使用常规组和注入组,以满足不同的转换需求。 总体上,独立模式适用于简单的模数转换需求,而双模式则提供了更灵活和丰富的功能。无论是独立模式还是双模式STM32ADC模块都能够提供高精度、高速度和低功耗的模数转换能力,广泛应用于各种工业和消费电子设备中。 ### 回答2: STM32ADC模块可以在独立模式和双模式下工作。 在独立模式下,ADC模块通过AD转换时钟进行采样和转换,可以设置为单次转换或连续转换。在单次转换模式下,ADC模块完成一次转换后自动停止工作,需要再次触发才能进行下一次转换。在连续转换模式下,ADC模块会不断进行转换并产生连续的转换结果。独立模式下的ADC模块可以对多个通道进行转换,并可以设置不同的采样时间和分辨率。 另外,ADC模块还支持双模式工作。在双模式下,可以设置为常规模式和注入模式。常规模式下,ADC模块与DMA控制器配合工作,可以实现高效的数据转移,适用于高速采样和转换。注入模式下,ADC模块可以在常规模式下的基础上额外进行一次或多次注入转换,适用于需要对特定事件进行高精度采样的应用场景。 总体而言,STM32ADC模块可以根据不同的应用场景选择不同的工作模式。独立模式适用于常规的采样和转换需求,而双模式则可以提供更灵活和高效的数据采集方式,满足不同的应用需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值