cancel
Showing results for 
Search instead for 
Did you mean: 

DAC Outputs Not Equal

AE104
Senior

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);
  }
 

6 REPLIES 6
KnarfB
Principal III

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

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
Senior

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

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
Senior

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

eava.1
Associate

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.