Workbench Software Architecture

Preface

Here, there are many online resources available for reference, such as the video tutorials on FOC control principles and motor application development based on STM32. This discussion focuses on the code generated by ST’s Workbench after setting up the parameters, mainly on the program architecture and important code explanations. After understanding the architecture, users can adjust and add the necessary applications on their own. Subsequently, API applications and modifications for different controls will be introduced step by step

Software Architecture

The main structure of the entire program can be seen in the following figure. There are two interrupts (Systick interrupt and ADC interrupt) that can be seen from the diagram as the main core of the program. The Systick interrupt performs safety tasks and intermediate frequency tasks (speed loop), while the ADC interrupt performs high frequency tasks.

Systick interrupt

The system timer is a 24-bit down-counting counter, and the time for each counting is 1/SYSCLK. When the value in the memory value register decreases to 0, the system timer generates an interrupt. Here is an example of the default 1ms timing interrupt for reference code.

__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
  /* Configure the SysTick to have interrupt in 1ms time basis*/
  if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
  {
    return HAL_ERROR;
  }

  /* Configure the SysTick IRQ priority */
  if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  {
    HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
    uwTickPrio = TickPriority;
  }
  else
  {
    return HAL_ERROR;
  }

  /* Return function status */
  return HAL_OK;
}

interrupt Function

void SysTick_Handler(void)
{
    MC_RunMotorControlTasks();
}

MC_RunMotorControlTasks function

__weak void MC_RunMotorControlTasks(void)
{
  if ( bMCBootCompleted ) {
    /* ** Medium Frequency Tasks ** */ 
    MC_Scheduler(); //中頻任務

    /* Safety task is run after Medium Frequency task so that
     * it can overcome actions they initiated if needed. */
    TSK_SafetyTask(); //安全任務

    /* ** User Interface Task ** */
    UI_Scheduler();  //用户界面任務
  }
}

ADC interrupt

The ADC interrupt mainly performs FOC coordinate transformation, SVPWM execution, voltage/current/temperature sampling, and PWM adjustment ratio output after Timer trigger (refer to the diagram below). The ADC initialization part can refer to the document “Motor Development Application Based on NUCLEO-F746ZG” section 7 “Program Framework-Two Important Interrupts”, which is generally similar to the normal initialization, so we will not elaborate on it. Only the library is added in the interrupt section.

ADC interrupt

void ADC_IRQHandler(void)
{
  /* USER CODE BEGIN ADC_IRQn 0 */

  /* USER CODE END ADC_IRQn 0 */
  if ( LL_ADC_IsActiveFlag_JEOS( ADC1 ) )//檢查ADC轉換flag
  {
    LL_ADC_ClearFlag_JEOS( ADC1 );//清除Flag
  }

  // Highfrequency task Single or M1
 UI_DACUpdate(TSK_HighFrequencyTask()); //高頻任務
  /* USER CODE BEGIN ADC_IRQn 1 */

  /* USER CODE END ADC_IRQn 1 */
}

1 thought on “MCSDK Software Architecture”

  1. Pingback: Motor Profiler and MotorControl Workbench - AMS and STM32

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart