1

I'm using an STM32G474RE board and experimenting using a timer as an interrupt to call the DMA controller - which I think indexes into an array which holds values for my Sine wave lookup table.

I have all of this working using STMCubeMX and IDE.

At the moment it looks like (but i'm not sure):

  • the timer increments a variable to the size of the array then resets back to zero,
  • the DMA then rolls round to send the value to the DAC, this works great,

I would like to create a further 2 outputs, which I have working but I want to shift the index so the DMA retrieves data from the array x values into the array, the aim being I want to have a 120 Degree phase shift from phase A to phase B then C. e.g.

  • Phase A 0 Degree (array index starts at 0)
  • Phase B 120 Degree (array index start at 100)
  • Phase C 240 Degree (array index starts at 200)

A snippet of the main function is below.

Is it possible to pre-load the index into the array so it starts filling the DAC with values later into the array?

I really appreciate any guidance.

Thanks, Nick

I have tried this and it works using STMCubeMx to generate the project and built the project using CubeIDE.

int main(void)
{
    /* USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration--------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* USER CODE BEGIN Init */

    /* USER CODE END Init */

    /* Configure the system clock */
    SystemClock_Config();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_DAC1_Init();
    MX_TIM2_Init();
    /* USER CODE BEGIN 2 */

    // The DAC,DMA and Look up table are defined here I think ,

    HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)Wave_LUT_BIG, 2500, DAC_ALIGN_12B_R); 
    HAL_TIM_Base_Start(&htim2);
    HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_2,    (uint32_t*)Wave_LUT_COS, 128, DAC_ALIGN_12B_R);
    HAL_TIM_Base_Start(&htim2);

    /* USER CODE END 2 */
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1) {
       /* USER CODE END WHILE */
       /* USER CODE BEGIN 3 */
    }
    /* USER CODE END 3 */
}
pmacfarlane
  • 3,057
  • 1
  • 7
  • 24
om_kcin
  • 23
  • 5
  • I don't know if that is possible. But your array looks like it is probably quite small. You could just have three arrays, each with the required phase-shift. – pmacfarlane May 15 '23 at 21:52
  • Thanks for feedback Yeah that's my fallback option but I thought it more efficient if i only hold one array of 2500 values, also it would make altering the phase simpler If I could alter the index . – om_kcin May 16 '23 at 18:37

0 Answers0