AnsweredAssumed Answered

DAC. Arbitrary form signal generation.

Question asked by Ann Darkhanova on May 31, 2018
Latest reply on Jun 2, 2018 by Ann Darkhanova

Hello, dear Community!

I'm using DAC to generate oscillogram of a short-circuit in a power line(50Hz). To achieve this I created array of discrete samples in MathCAD with sampling frequency of 4000Hz. In order to feed my samples to DAC with the same frequency(4kHz) I'm initializing a timer.

The problem is that I see something inappropriate on my scope that hardly can be named a sinewave at all. I looked through the similar examples across the web, so here I have:


void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){

     if (htim->Instance==TIM6)
      for(int i=0; i<n; i++){
      HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1,  DAC_ALIGN_12B_R, inf[i]);



  htim6.Instance = TIM6;
  htim6.Init.Prescaler = 999;
  htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim6.Init.Period = 53;
  htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

  HCLK is 216 MHz.


Could you clarify please how it should be organized properly and make sure that DAC gives me proper signal?