【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压

时间:2021-01-17 07:29:57

实验原理:

  STM32内部集成12位DAC,可以配置成12位或8位,DAC具有两个独立转换通道,

在双DAC模式下,DA转换可被配置成独立模式或工作模式,iCore1S中DAC参考电压为

2.5V。本实验输出2.0V电压

核心代码:

int main(void)
{ /* USER CODE BEGIN 1 */
/* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */
SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DAC_Init(); /* USER CODE BEGIN 2 */
HAL_DAC_Start(&hdac, DAC_CHANNEL_1); dac.set_voltage(2.0); /* USER CODE END 2 */ /* Infinite loop */
/* USER CODE BEGIN WHILE */
while ()
{
/* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ LED_RED_ON;
LED_GREEN_OFF;
LED_BLUE_OFF;
HAL_Delay();
LED_RED_OFF;
LED_GREEN_ON;
LED_BLUE_OFF;
HAL_Delay();
LED_RED_OFF;
LED_GREEN_OFF;
LED_BLUE_ON;
HAL_Delay();
}
/* USER CODE END 3 */ }

源代码下载链接:

链接:http://pan.baidu.com/s/1i5b0kRV 密码:p2h5

【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压