STM32学习笔记——DAC
Posted qw1234567
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32学习笔记——DAC相关的知识,希望对你有一定的参考价值。
1.概述STM32DAC
2.STM32F407库函数总结
3.输出模拟电压配置过程
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------
1.概述STM32DAC
-12位数字输入电压输出(8/12对齐方式可编程)
-支持DMA
-数据是由DAC_DHRX寄存器经过一个或三个APB1时钟周期后传入DAC_DORX,不可以对DAC_DORX寄存器操作,再经过T(和电源电压,模拟输出负载有关。典型3u,最大6u)后输出有效,1/T可知最大的转换速度为333KHZ左右
-DACx_OUT=Vref*DORx/4095.
-触发方式可选(软件或者硬件触发,其中硬件触发又包括定时器和外部中断俩大类)
-有噪声生成和三角波生成功能(需要使能触发)
-双DAC通道转换功能
2.STM32F407库函数总结
/* Function used to set the DAC configuration to the default reset state *****/
void DAC_DeInit(void);
/* DAC channels configuration: trigger, output buffer, data format functions */
void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);软件出发使能函数
void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);设置多通道数据
uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
/* DMA management functions ***************************************************/
void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
/* Interrupts and flags management functions **********************************/
void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
3.输出模拟电压配置过程
(1)开启PA时钟设置PA4为模拟输入,GPIO时钟线AHB1,STM32中复用DAC_OUT1/2分别复用为PA4/5
(2)使能DAC时钟,时钟线为APB1
(3)初始化DAC,DAC_Init();包含以下参数
.DAC_LFSRUnmask_TriangleAmplitude=设置屏蔽和幅值选择器(做波形发生器时使用)
.DAC_OutputBuffer=输出缓存一般不用
.DAC_Trigger=是否使用触发功能
.DAC_WaveGeneration=是否使用波形发生(三角和噪声波)
(4)使能DAC,DAC_CMD();
(5)设置DACx输出值:DAC_Setchannle1Data()
(6)读取DAC:DAC_GetDataoutputValue();
以上是关于STM32学习笔记——DAC的主要内容,如果未能解决你的问题,请参考以下文章