cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate sinewave by using DAC in stm32h745xg ?

srikanth
Associate III

we are using stm32h745xg and I initialize DAC with timer 6 ,we enable DMA also.

we are using following code

 static TIM_HandleTypeDef htim;

 TIM_MasterConfigTypeDef sMasterConfig;

 /*##-1- Configure the TIM peripheral #######################################*/

 /* Time base configuration */

 htim.Instance = TIM6;

 htim.Init.Period      = 0x3FF;

 htim.Init.Prescaler     = 0;

 htim.Init.ClockDivision   = 0;

 htim.Init.CounterMode    = TIM_COUNTERMODE_UP;

 htim.Init.RepetitionCounter = 0;

 HAL_TIM_Base_Init(&htim);

 /* TIM6 TRGO selection */

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

 HAL_TIMEx_MasterConfigSynchronization(&htim, &sMasterConfig);

 /*##-2- Enable TIM peripheral counter ######################################*/

 HAL_TIM_Base_Start(&htim);

 HAL_DAC_DeInit(&hdac1);

if (HAL_DAC_Init(&hdac1) != HAL_OK)

 {

  /* Initialization Error */

  Error_Handler();

 }

 /*##-1- DAC channel1 Configuration #########################################*/

 sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;

 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

 if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)

 {

  /* Channel configuration Error */

  Error_Handler();

 }

 /*##-2- Enable DAC selected channel and associated DMA #############################*/

 if (HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t *)sine_wave_array, 6, DAC_ALIGN_8B_R) != HAL_OK)

 {

  /* Start DMA Error */

  Error_Handler();

 }

but we are unable to get sinewave at output .

0 REPLIES 0