2
\$\begingroup\$

Here is a snippet of code from /src/motorBLDC_6step.c in the Microchip appnote "AN1175 - bldc1619 Source Code - Sensorless Brushless DC Motor Control with PIC16" linked below, that implements a digital filter used in commutation of a BLDC motor:

... #define FILTER_DELAY 6 ... static void PhaseDelayFilter(void) { phase_delay_filter += comm_time; phase_delay = phase_delay_filter >> FILTER_DELAY; phase_delay_filter -= phase_delay; phase_delay_counter = phase_delay >> 3; } 

The source of the code is found in a project provided by Microchip linked below, to use a PIC16F1619 to control a BLDC motor using six-step commutation method:

My questions are:

  1. What kind of a filter is implemented here (what is its differential equation)?
  2. How the factors 6 and 3 are chosen ?
\$\endgroup\$
6
  • \$\begingroup\$ learn design - Thanks for adding that link. You said it was for the PIC16F1619 so I looked in ww1.microchip.com/downloads/en/AppNotes/bldc1619.zip - I found almost identical, code in /src/motorBLDC_6step.c - is that where you copied that code from, and then changed it from phase_delay = phase_delay_filter >> FILTER_DELAY; to phase_delay = phase_delay_filter >> 6;? Or did you copy the code in the question from a different file? In short: Where exactly did the code in the question come from, please? Was it changed? TY \$\endgroup\$ Commented Jan 4 at 18:24
  • \$\begingroup\$ I have just changed FILTER_DELAY to 6, for clarity and help the reader to focus on the value of the factor, rather then looking for it elsewere! \$\endgroup\$ Commented Jan 4 at 18:28
  • 4
    \$\begingroup\$ learn design - Re: "I have just changed FILTER_DELAY to 6, for clarity" OK, that explains why I couldn't find the exact line you showed :( FYI there are better ways to show that. For the future, please don't imply that code has been copied from somewhere, if you have also changed it. Otherwise people will waste time looking for the exact code you showed, and never find it :( I edited the question to show the original code, as well as where the number 6 comes from. Please check to confirm that is what you meant. TY \$\endgroup\$ Commented Jan 4 at 18:45
  • 1
    \$\begingroup\$ @SamGibson I comfirm it, thank you \$\endgroup\$ Commented Jan 4 at 18:50
  • \$\begingroup\$ Check the prescaler, compare register, and interrupt service routine to ensure comm_time is updated as expected and check for rounding /truncation errors. I think commutation error is a tradeoff between skew and negative torque or positive torque at the boundary. For examples Hall sensor based fans will fail over time if the sensor thermally or age shifts the skew negative and it won't start and just dither back and forth. I had 1% of Nidec fans in production integration fail because of this and had to screen for start/stop report failure and send my tester to them to screen their product. \$\endgroup\$ Commented Jan 4 at 20:26

1 Answer 1

2
\$\begingroup\$

This can be found in the application note available at link you added:

enter image description here

The filter looks like an IIR approximation of a FIR moving average filter. Check the timer 2 usage to see how frequently the input comm_time is being incremented. Maybe, for numerical reasons, the factors in the code (from the bit shifts) are actually 64 and 8 (respectively).

\$\endgroup\$
4
  • \$\begingroup\$ What do you mean by IIR approximation of a FIR ? is there a technique or a method to design such filters ? \$\endgroup\$ Commented Jan 4 at 19:38
  • 2
    \$\begingroup\$ a simplified recursive implementation is used to achieve the effect of an FIR moving average without requiring as much memory or computational overhead. \$\endgroup\$ Commented Jan 4 at 20:17
  • 2
    \$\begingroup\$ "What do you mean by IIR approximation of a FIR " For example, instead of storing the 10 most recent samples of the value to calculate an exact moving average, you add 1/10 of the newest value to 9/10 of the previous average. Digitally, it is more precise to do these multiplied by factor of 2. You will find dozens of references for digital filter design. Check this reference from AD: analog.com/media/en/training-seminars/design-handbooks/… \$\endgroup\$ Commented Jan 4 at 21:00
  • 1
    \$\begingroup\$ "What do you mean by IIR approximation of a FIR?" -- more like it's a bog standard first-order IIR lowpass filter. You could also say that a FIR moving average is an approximation of this -- either way, things should work. \$\endgroup\$ Commented Jan 5 at 0:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.