Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sinusoidal Control of BLDC motor

Not open for further replies.
I am really looking for some support on this application note AN1017A by microchip for sinusoidal control of BLDC motors. I have attached the application note i have progressed little bit but need more support. There are two source codes provided for two micros one for dspic30f4011 and another for dspic33E family. If i compare the implementations of both they are differing in some critical sections. Can someone please tell me why is it so?
There is a PhaseInc value which has to be changed in one project it is something like this
if (Current_Direction == CW)
           Phase-= PhaseInc;
In another it is
       if (Current_Direction == CW)
           Phase += PhaseInc;

I have some other doubts but i want to first get over this.


  • sinusoidal_bldc.pdf
    313.9 KB · Views: 169
    77.5 KB · Views: 148
    675.1 KB · Views: 138
I honestly wouldn't worry about that difference. CW and CCW are just arbitrary labels indicating direction. They could have just as easily named them "forward" and "reverse".

But if I had to guess, I believe it is a typo in the 30F version that was later caught and corrected in the 33F version. Notice that the comments are the same in both the 30F and 33F version, but in the code is doing the opposite of what the comment says in the 30F version, while in the 33F version the comment and code line up.

Both projects also use different dev boards so the wiring to the motor could be different. It only takes swapping any two of the three wires on a BLDC to reverse it's direction. So it could be that.
Last edited:
Thank you very much for the reply. My other major doubt is
// In the sinewave generation algorithm we need an offset to be added to the
// pointer when energizing the motor in CCW. This is done to compensate an
// asymetry of the sinewave
int PhaseOffset = 4100;  /* 22.5 degrees */

I don't understand the Phaseoffset it is different in CW rotation and CCW. What exactly is this? As per the code it is done to compensate asymmetry of sine wave. What is asymmetry? In my project which value shall i choose? Please help. If any detailed explanation is there it will be really useful.
It's because of a flaw in the the sine-wave lookup table, or whatever math function they use to calculate their sine wave:
  Note 2:          For Phase adjustment in CCW, an offset is added to
                   compensate non-symetries in the sine table used.

Because the sine-wave is being approximated with lookup table, there is a discrete number of values. Those values must not be spaced evenly around the max peaks, zeroes, and min peaks of the sine wave. To see what it really is, you are going to have to dog into "sinetable" to see how they calculate their sinewave and graph it out. But if you do, it should be very obvious. You could modify the code and get it to calculate the sine wave in the same way they are doing it and spit it out over a USB-UART serial connection to your PC if you are really curious. Or just have it generate the sine-wave open loop without the offsets and view it on the oscilloscope.

If you were able to use a symmetrical sine-wave lookup table, you would not need to do this. And to be honest, you could probably get rid of that offset and it would still run. It would just not run equally well in both directions. I would ignore this little detail if you're starting out and just trying to get everything to work. This is more of an optimization.
Last edited:
This is the lookup table they build their entire sine-wave on:
// This sinewave lookup table has 171 entries.  (1024 points per
// electrical cycle -- 1024*(60/360) = 171)
// The table covers 60 degrees of the sine function.

int __attribute__((near)) sinetable[172] =

Graph it out. I bet you the graph will look a little bit distorted because some of the the maximums, minimums, and zeroes aren't missing because they don't fall perfectly onto one of the the 172 points on the x-axis.)

A little extra work may be required since the lookup table only covers 60 degrees, and they use some extra trig to get 60-90 degrees and the rest of the sine-wave. The distortion might also come from that approximation they are doing to get the full-sine wave out of just 60 degrees worth of lookup values.
Last edited:
Thank you very much for the support. Give me some time i will share the source code i have developed and the results i got. I can see the motor running but finding some issues. I will share all those details. Request your support.
This is the source code i have developed. The code settings are as follows i tried to follow the sample code
Number of poles: 16
Open loop speed control i have set the control output at 30000.
I have set phase_zero to 45000
#define PHASE_OFFSET_CW 10000. I am not sure about this.
The hall Sensors are analog and given to comparator which is converted to digital internally. Can you please review the code. Motor runs but does not produce any torque.


    193.3 KB · Views: 133
Are you referring to phase advance. Currently i am not doing that. But normally sinusoidal control i thought will produce maximum torque as rotor field is at 90 degrees to stator field. Only for speed improvement we need phase advance. Please correct me.
This is one of the results.


  • IMG-20180505-WA0014.jpg
    109.8 KB · Views: 143
I'm afraid at this point you've done more practical work on this than I have so I can only brainstorm rather than offering any definitive answers:

1. I'm assuming you have run the motor with a normal controller so you know how much torque is possible, and the motor just doesn't have "no torque" because it is weaker than you guessed it would be.

2. I remember the example project mentioned about dealing with the latency involved in the hall sensors. Did you do anything like that?

3. What is the blue and red waveform in your scope photo?
The blue and red photos are the filtered line voltages. I expected them to be sinusoidal.
Is there a the filtering circuit between the driver and motor? What is the frequency of the "sinusoid" and what frequency is the PWM? Could you post a scope of your PWM waveform (the gate drive voltage) on top of the line voltage?

Did you build the entire circuit yourself or are you using a development board?
I have my own board. The filtering circuit was just added to see on the scope. The pwm frequency is 20khz. I did not measure the sine wave frequency. Do you think sine wave should be of particular frequency?


  • 1525533458175_IMG-20180505-WA0008.jpg
    135.1 KB · Views: 142
I have my own board. The filtering circuit was just added to see on the scope. The pwm frequency is 20khz. I did not measure the sine wave frequency. Do you think sine wave should be of particular frequency?

The sine-wave frequency will be decided by the rotation speed of the motor from the hall sensors. You don't get to pick the sine frequency without also changing the RPM. You need the PWM frequency to be higher than the rotational frequency by enough so that you can filter out all the square harmonics to get an approximate sine-wave (although I think the motor inductance can do that on its own in some cases as well).

Is blue your PWM gate drive signal? Zoom it on and it and look the duty cycle closely. From a distance, to me, it looks like your line voltages are doing what is expected of your gate drive voltage. But your gate drive voltage doesn't look like the duty cycle is varying sinusoidally which would explain the strange waveform. It should kind of look like this:

**broken link removed**

If you built your own board, make sure your gate drive is sufficient to turn your MOSFETs on and off fast enough.
Last edited:
Yes i am also concerned about the duty cycle not varying sinusoidally. But in the application note fig 15. If you see the duty cycle it does not vary sinusoidally. Can you please confirm it. It is space vector modulation as per the paper.
Oh, I see what you're trying to do. Unfortunately, I never knew such a method existed until now so I can't really help you on it!

But with regards to figure 15, that's not showing the duty cycle of the gate-voltage. It's showing the line voltage produced by each PWM signal. Maybe you mean figure 14?
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips