STM32 F1 系列 DAC 示例详
前言
基于学习的目的,详细讲解关于 Cube 库中 DAC 的功能。本次介绍 DAC
一、示例详解
基于硬件平台:STM32F10C-EVALMCU 的型号是 STM32F107VCT6
软件则是其 Cube 库,路径:
STM32Cube\Repository\STM32Cube_FW_F1_V1.3.0\Projects\STM3210C_EVAL\Examples\DAC\DAC_SignalsGeneration
1
主程序
软件配置,运行程序可以发现,系统时钟设置为 72MHz,定时器使用到的是 TIM6;
int main(void)
{
HAL_Init();
/* Configure the system clock to 72 MHz */
SystemClock_Config();
/* Configure LED3 */
BSP_LED_Init(LED3);
/* Configures Key push-button */
BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
/*##-1- Configure the DAC peripheral #######################################*/
DacHandle.Instance = DACx;
/*##-2- Configure the TIM peripheral #######################################*/
TIM6_Config();
/* Infinite loop */
while (1)
{
/* If the Key is pressed */
if (ubKeyPressed != RESET)
{
HAL_DAC_DeInit(&DacHandle);
/* select waves forms according to the Key push-button status */
if (ubSelectedWavesForm == 1)
{
/* The triangle wave has been selected */
/* Triangle Wave generator -------------------------------------------*/
DAC_Ch1_TriangleConfig();
}
else
{
/* The escalator wave has been selected */
/* Escalator Wave generator -------------------------------------------*/
DAC_Ch1_EscalatorConfig();
}
ubKeyPressed = RESET;
}
}
}
根据时钟树的图谱及其程序, 该示例选择的是内部时钟源作为定时器的时钟源;TIM6 的时钟源来自 APB1 的分频。