二、DAC,数字模拟转换
1、定义
STM32F4 的 DAC 模块(数字/模拟转换模块)是 12 位数字输入,电压输出型的 DAC。DAC可以配置为 8 位或 12位模式,也可以与 DMA 控制器配合使用。 DAC 工作在 12 位模式时,数据可以设置成左对齐或右对齐,一般设置右对齐,从第零位开始。 DAC 模块有 2个输出通道,每个通道都有单独的转换器。在双 DAC 模式下, 2 个通道可以独立地进行转换,也可以同时进行转换并同步地更新 2个通道的输出。 DAC 可以通过引脚输入参考电压 Vref+(通 ADC 共用) 以获得更精确的转换结果。
#主要应用在
输出自定义电压、音频播放、视频播放
2、库函数
a.根据DAC_InitTypeDef初始化DAC
- @param DAC_Channel: the selected DAC channel.
- This parameter can be one of the following values:
-
@arg DAC_Channel_1: DAC Channel1 selected
-
@arg DAC_Channel_2: DAC Channel2 selected
- @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that contains the configuration information for the specified DAC channel.
void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
typedef struct
{
uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
This parameter can be a value of @ref DAC_trigger_selection */
uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
are generated, or whether no wave is generated.
This parameter can be a value of @ref DAC_wave_generation */
uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
the maximum amplitude triangle generation for the DAC channel.
This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.