AnsweredAssumed Answered

stm32L4 : Problem generating triangular wave using DAC DMA, uneven slopes

Question asked by C S on Aug 1, 2017

Hello! I am trying to generate a triangular wave of frequency 8kHz using DAC and DMA. DAC is triggered using a timer so that the DAC speed will be 1 MSPS. I am working on stm32L476 discovery board. I am using stm32CUBEMX for code initialization. My configurations are as follows:

In stm32CUBEMX :

Clock configuration : system clock = 80MHz 

                                 APB1 and APB2 peripheral clocks = 20 MHz

                                 APB1 and APB2 timer clocks = 40 MHz

                                 PLL source mux : HSI

                                 PLLM = /1

                                 *N = x10

                                  /R = /8

                                 PLLCLK selected

Timer : Prescalar = 39

            UP counter

            Period = 1

            So that output frequency is 1 MHz to trigger the DAC.


          Output buffer : Enable

          Trigger : TIM7 Event out

          DMA(option inside DAC configuration in cubeMX): DAC channel 2(PA5), Half word, circular mode, priority = very             high, memory(ticked) in cubeMX

I am using ac6SW4stm32(system workbench) for writing code. I created an array like this for triangular wave.

const uint16_t val[]={130,260,390,520,650,780,910,1040,


In main, I added the following three statements. These statements start timer, DAC and DMA respectively.

HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_2, (uint32_t*)val, 64, DAC_ALIGN_12B_R);


At the output, I am not getting proper triangular wave. Frequency of the wave is correct but the wave is not perfectly triangular. It has different rising and falling slopes(unequal edges). Can anyone tell me what the problem is ? Or does anyone have any working code  for this?