erwindenboer
erwindenboer

Reputation: 181

STM32 TIM DAC and DMA

I want to offload the CPU of my STM32G491 by using the DMA function. I want to use the Timer 2 (TIM2) to generate four moments where a DMA transfer is needed. While doing so I can create two pulses in one period. The period, duty cycle, and the delay are adjustable by using the Timer Output Compare functions.

  int amplitude = 0xFFF;

  uint16_t current[] = {0, amplitude, 0, amplitude};

  HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*) &current[0], sizeof(uint16_t), DAC_ALIGN_12B_R);
  HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*) &current[1], sizeof(uint16_t), DAC_ALIGN_12B_R);
  HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*) &current[2], sizeof(uint16_t), DAC_ALIGN_12B_R);
  HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*) &current[3], sizeof(uint16_t), DAC_ALIGN_12B_R);

  HAL_TIM_Base_Start_IT(&htim2);
  HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_1);
  HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_2);
  HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_3);

I don't know how I can connect my timers to initiate the transfer of data from memory to the DAC. I hope you can help me give me a direction in the right way.

I have set up my timers so that they give a DMA request when the timer has expired. I have set up all my timers this way

While doing so I can create a kind-of biphasic pulse but only for the positive side. The parameters which are adjustable are the two pulse widths, the interphase interval and the period of this pulse. Note that the negative phase will be positive, so it will output two positive pulses.

enter image description here

Upvotes: 3

Views: 2181

Answers (1)

0___________
0___________

Reputation: 67820

You are configuring it wrong way.

  1. Configure DAC trigger (this trigger will force DAC to request data transfer) enter image description here

  2. Configure DAC DMA enter image description here

  3. Configure timer to generate apripiate trigger

Upvotes: 1

Related Questions