Control Software Architecture

Overview

Before starting to implement subcomponents for the FOC control algorithm, let us first look at the software architecture. Following is a simple example:

Control software architecture.

There are 3 tasks in this example:

  • 10uS interrupt task. The triggering of the task will be explained in next section. The execution rate of the task can be the same as PWM frequency, which will be the control bandwidth as well. Since PWM duty command can only be updated once every PWM cycle, it doesn’t make sense to have control bandwidth higher than the PWM frequency. In this example, it is assumed that PWM switching frequency is 100kHz. This interrupt will mainly perform following tasks:
    • Sample 3-phase current feedback, DC voltage, rotor position.
    • Perform dq transfomration.
    • Compare current feedback and command values, generate voltage commands in dq domain.
    • Perform inverse dq transformation for voltage commands, then generate PWM duty commands for output voltage.
  • Slow control loop. This loop is usually triggered by system timer at a fixed rate, such as every 2mS. This loop will mainly perform tasks that can be executed slowly such as following tasks:
    • State machine
    • Diagnostics
    • Current command selection
  • The data buffer between fast loop and slow loop. This buffer is needed to make sure the data synchronization.

Fast Loop

As mentioned in last chapter, slow control loop can be triggered simply be a system timer with a fixed rate. But fast control loop is more complicated. When doing the dq transformation, it needs to be sure that 3-phase current and also the position are all sampled at exactly the same time point. Otherwise, the transformation result will be off. In order to achieve that, fast loop is usually triggered as following:

Current and position alignments.

Notice that:

  • In order to sample 3-phase current and DC voltage at the same time, microcontroller needs to have at least 4 independent ADC converters, and these ADC converters shall be configured so they can be triggered at beginning of each PWM cycle. Some microcontroller may not have 4 converters. That could introduce errors on feedback values.
  • DMA is not mandatory, and some microcontroller may not even have DMA peripheral. If that is the case, the fast loop task can be triggered by ADC once the sampling is done.
  • Since the fast loop task can only be triggered by one DMA or ADC channel, it is important to check the status for rest of DMA or ADC channels when entering the task, to make sure ADC data is ready before executing the control algorithm in this task.
  • DC voltage sampling is optional, if your control algorithm doesn’t require DC voltage in the fast loop.
  • It is not explained here that how to synchronize the position sampling with 3-phase current and DC voltage. Depending the position sampling approach, there will be different ways. For instance, if sensor less algorithm is implemented, the position shall be estimated based on factors such as ADC sampling timing, estimated speed, estimated position, etc.
  • By running in fast rate, this task will consume a lot CPU throughput, so try to avoid put too many functions here. The task shall be finished within 100uS so it can update PWM duty before starting next cycle, and to avoid task overrun.

Before closing the topic, there is one more thing that we need to pay attention to, as shown in following:

PWM angle prediction.

As mentioned above, position and current will be sampled at beginning of the PWM cycle. In this case, we will have ฮธn for PWM cycle n. This angle will be used for dq transformation to get the dq current feedback. However, when trying to do the inverse dq transformation, to convert voltage command from dq frame to abc frame, ฮธn cannot be used. This is because the new duty cycle command won’t be applied till next PWM cycle n+1. So ฮธn1 is the angle that shall be used for inverse dq transformation during PWM cycle n. Assuming center aligned PWM is used, means the PWM duty is aligned with the center of PWM cycle, ฮธn1 can be calculated as following:

PWM prediction angle calculation.

where T is the PWM period, ฯ‰e is the electric rotor speed.