Skip to main content
AE104
Associate III
February 22, 2023
Question

DAC Outputs Not Equal

  • February 22, 2023
  • 6 replies
  • 1206 views

Hello,

I use the internal DAC of the processor. Even the initial value of the DACs are equal, I got 1V out from the first output of the DAC, and 2V output from the other DAC output. Why is that happen?

/* USER CODE BEGIN PV */
 
// DAC Settings
 
float DAC1_Buf = 1.0; // Output 1st of the DAC is designated;
float DAC2_Buf = 1.0; // Output 2nd of the DAC is designated
 
uint32_t DAC1_Out = 0; // Output 1st of the DAC is designated;
uint32_t DAC2_Out = 0; // Output 2nd of the DAC is designated
 
/* USER CODE END PV */
 
 /* USER CODE BEGIN 2 */
 // HAL_TIM_Base_Start(&htim1); //initializes Timer 1
 HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
 HAL_DAC_Start(&hdac, DAC_CHANNEL_2);
 
 /* USER CODE END 2 */
 
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 
	 DAC1_Out = (uint32_t)DAC1_Buf*(4096)/3.3;
	 DAC2_Out = (uint32_t)DAC2_Buf*(4096)/3.3;
 
	 HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, DAC1_Out);
	 HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R, DAC2_Out);
 }
 

This topic has been closed for replies.

6 replies

KnarfB
Super User
February 22, 2023

Check that both pins are configured correctly and identically. Check your board/schematics for conflicting external components.

Infos about chip and board are always helpful...

hth

KnarfB

S.Ma
Principal
February 22, 2023

Output for each DAC pin

Infinite loop:

DAC (1,2) = (0, 4095)

Wait(1 msec)

DAC (1.2) = (4095, 4095)

Wait( 1 msec)

(4095, 0)

Wait (1 msec)

(0,0)

Wait (1 msec)

Make sure output pin do not have pull up or down, and buffer is enabled.

Probe both pins using osciloscope.

AE104
AE104Author
Associate III
February 22, 2023

Thank you for your response @S.Ma​ and @KnarfB​ ! @S.Ma​ can you type in C language with using HAL library of your codes? I am not familiar with the your commented codes.

S.Ma
Principal
February 24, 2023

It is impossible as we even don't know which STM32 we are talking about. STM32F103, STM32U5? STM32H7? Not all DACs are same generation. You can find ST examples for the corresponding Nucleo board in the Cube SW drivers and library packages, once installed on a PC. Or try to use ChatGPT to make a skeleton code. (you need ask ChatGPT mentionning the part number or better then nucleo board closest to the desired configuration, the sysclk core frequency, that you want HAL or LL example. Let us know if this works.

AE104
AE104Author
Associate III
March 16, 2023

The microcontroller is STM32F446ZCH6. Let me check related Nucleo board.

eava.1
Visitor II
March 16, 2023

Check that both pins are configured correctly and identically. Check your board/schematics for conflicting external components.

Infos about chip and board are always helpful.