码迷,mamicode.com
首页 > 其他好文 > 详细

STM32学习笔记——DAC

时间:2016-03-11 22:14:45      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/threethousandhours/p/5267128.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!