2

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

erwindenboer
  • 111
  • 1
  • 10
  • It seems like you're trying to generate some kind of square wave, am I right? What are the requirements of this signal? What parameters do you want to be adjustable? – Tagli May 29 '21 at 19:17

1 Answers1

0

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

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Thank you for the answer. As I can see from the drop-down menu you can only select a timer out event. There is no way to use output compare functions to initiate a DMA transfer? In my image four output compare functions are used to request a DMA transfer – erwindenboer May 30 '21 at 10:15
  • @erwindenboer this question shows that you did not read the uC documentation (Reference Manual). You write different things. Read the timer section of the documentation. Using a "magical" HAL library does not replace knowledge. – 0___________ May 30 '21 at 10:24
  • I have read the uC documentation. But perhaps I have misinterpreted the information in the documentation wrong. In the documentation I have read that the output compare channels can generate DMA requests (as well as interrupts). But in the STM32CubeMX I see that I can't connect the output compare channels to the DAC to initiate a transfer. I don't know if what I want is feasible in the microcontroller. Hence my question. – erwindenboer May 30 '21 at 10:36