4.4 Zero-Cross Filtering

In some cases, the zero-cross point might be detected earlier or later than the ideal case due to noise or other factors such as motor particularities.

A filtering method will be used to avoid an unwanted behavior that can get the motor out of lock.

The basic constraints of this filter need to follow a few simple rules:
  • The value of the filter must not be too aggressive in a way that would affect the reaction time of the motor in the case of a moderately fast speed change and not too soft, as it defeats its intended purpose
  • The filter must not be computationally intensive, as it may take a long time to obtain the desired result and delay the commutation point
  • A minimum pass-through delay is required to obtain the best results

Based on the above requirements, a first-order IIR filter is chosen under the form of a moving average low-pass filter using the formula y ( n ) = y ( n 1 ) × ( a 1 ) a + x ( n ) a , where y is the output of the filter, x is the input, and a is the filter coefficient.

timerValue = (uint32_t)(((uint32_t)previous_zero_cross_time * (MOTOR_DIVISION_FACTOR - 1) +
 (uint32_t)current_zero_cross_time)) / MOTOR_DIVISION_FACTOR;

Ideally, for faster computation, the filter coefficient (MOTOR_DIVISION_FACTOR) must be a power of two, as it can be implemented using bit shifting with specific core instructions.

The input and output values are unsigned 16-bit values, thus, to prevent an overflow during the multiplication of y(n-1), as well as the total sum, the operations are done using casting to 32-bit unsigned values.

For the scope of this application, a value of 4 for the filter coefficient was considered the best fit.