Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sinusoidal control of BLDC Motor

Status
Not open for further replies.

electronicsman

Full Member level 5
Full Member level 5
Joined
May 4, 2012
Messages
291
Helped
11
Reputation
22
Reaction score
12
Trophy points
1,298
Activity points
3,737
One clarification would help me a lot. I am referring to the following attached document which controls the PMSM motor using sinusoidal signal. I measure the current speed using the hall sensors and read the set reference speed and adjust the amplitude of the sine signal. I calculate the frequency of the signal based on hall signal and generate the sine wave of the same frequency by switching the legs. My doubt is I can generate the sine wave using a look up table then why the document is referring to space vector PWM? What exactly is space vector pwm? I am not able to understand the timing calculations of space vector pwm. Please help.
 

Attachments

  • MotorControl.pdf
    313.9 KB · Views: 200

Please be more specific: which part you are unable to follow? It is not easy to repeat the full document here line by line...
 

Thank you for the reply. I have attached the project src i have downloaded from the micro chip website. My main questions are
1. When we will use sine wave generation using look up table and when we will use Space Vector Modulation?
2.In page number 15 there is a statement saying "UOUT is the desired resultant". What exactly is UOUT? From where it is derived? I read in several documents it is called resultant vector? How it is obtained?
3. Iam unable to understand the values specified in the code
Code:
// 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 sinetable[] __attribute__((far,section(".const,r")))= 
{0,201,401,602,803,1003,1204,1404,1605,1805,
2005,2206,2406,2606,2806,3006,3205,3405,3605,3804,4003,4202,4401,4600,
4799,4997,5195,5393,5591,5789,5986,6183,6380,6577,6773,6970,7166,7361,
7557,7752,7947,8141,8335,8529,8723,8916,9109,9302,9494,9686,9877,10068,
10259,10449,10639,10829,11018,11207,11395,11583,11771,11958,12144,
12331,12516,12701,12886,13070,13254,13437,13620,13802,13984,14165,
14346,14526,14706,14885,15063,15241,15419,15595,15772,15947,16122,
16297,16470,16643,16816,16988,17159,17330,17500,17669,17838,18006,
18173,18340,18506,18671,18835,18999,19162,19325,19487,19647,19808,
19967,20126,20284,20441,20598,20753,20908,21062,21216,21368,21520,
21671,21821,21970,22119,22266,22413,22559,22704,22848,22992,23134,
23276,23417,23557,23696,23834,23971,24107,24243,24377,24511,24644,
24776,24906,25036,25165,25293,25420,25547,25672,25796,25919,26042,
26163,26283,26403,26521,26638,26755,26870,26984,27098,27210,27321,
27431,27541,27649,27756,27862,27967,28071,28174,28276,28377};
4. The following code is there in the program
Code:
// Scale t1 to by the volts variable.
	t1 = ((long)t1*(long)volts) >> 15;
	// Scale t1 for the duty cycle range.
	t1 = ((long)t1*(long)tpwm) >> 15;
The volts is derived from the difference between measured speed and reference speed. What range of values can it have?
5. Most importantly how do i correlate Figure 14 with Figure 15 in the document.

I am sorry to ask lot of questions. But please help to clear my doubts.
 

Attachments

  • CE003_Sinusoidal_BLDC_010908.zip
    97.9 KB · Views: 135

Simple answer: about the table (Q#3)

0-360 is divided into 1024 points (these numbers are chosen because they are 2^n)

Each point is 360/1024 deg

Convert them into sin(x) values; sin(0*360/1024), sin(1*360/1024), sin(2*360/1024)... sin(170*360/1024)

Because they are all 0<sin(x)<1, we multiply them with 32768.

The first number in the list now becomes 0, the second one 32768*sin(1*360/1024)=201.06 (int representation will be 201), ... the last one will be 28311 (I do not know why there is a difference; perhaps some mistake)

You please ask one question at a time. I cannot go through so many documents in the zip file.

Why only upto 60 deg? I do not know; I thought we need a table upto 90. The program has some details...

Q4: >> is bit shift operator. 16 bit int multiplied by another 16 bit int will get you a 32 bit result; by shifting 16 bits out, you keep only the most significant value (by the way they are using signed int)

volts is an int value input to the SVM routine.
 
What exactly is space vector pwm? I am not able to understand the timing calculations of space vector pwm. Please help.

I saw the document enclosed; it should be clear. Yes, they need only look up table for sin(0) to sin(60) and that detail is explained in the document. If you have difficulty in understanding a given logic, please ask specifically.

Their look up table is having some mistake but the error is small. You can ignore that or correct it.
 
Thank you very much for the reply. I will prepare and ask clearly my questions.
 

Thank you very much for the help. I have put in lot of effort to understand what is going on and created the following excel sheet with calculations. I followed the source code provided by microchip. Please guide me if i am going in right direction, if i will be able to generate the sine signals for the phase voltages with 120 degrees apart. I am unable to attach xlsx file i have attached in zip file. I am struck up in the following calculations. Please help to understand the calculations. I don't understand the number 512000.
Code:
// PhaseInc is a value added to the Phase variable to generate the sine
    // voltages. 1 electrical degree corresponds to a PhaseInc value of 184,
    // since the pointer to the sine table is a 16bit value, where 360 Elec
    // Degrees represents 65535 in the pointer. 
    // __builtin_divud(Long Value, Int Value) is a function of the compiler
    // to do Long over Integer divisions.
	PhaseInc = __builtin_divud(512000UL, Period);	// Phase increment is used
							 					// by the PWM isr (SVM)
In the excel i have calculated the phase as per the program
Code:
#define PHASE_ZERO 	57344
#define PHASE_ONE	((PHASE_ZERO + 65536/6) % 65536)

Anything else I have to work on please suggest me.
 

Attachments

  • cal.zip
    14.4 KB · Views: 127

I don't understand the number 512000.

This is an approx value; the correct value should be 524288=2^19. (the number to be used will be 1 less; 524288-1=524287) Why 19?

int takes 16 bits and int multiplied by another int will give you a 32 bit result; the result will need a long int. I have forgotten how to multiply but one bit is used up for the sign and that has to be handled separately.

If you divide (more messy; hence int division is done by the compiler at compile time) a long int by int the result will be an int. If you divide an int by int the result will be not usable (why?)

The result of division of 19 bit int by a 16 bit int will be usable at least to 3 bits. They do not want a long value for this quantity...
 
Thank you for the reply. Have you seen my calculations am i in the right direction? I will get little confidence to proceed further. Please advise.
 

// PhaseInc is a value added to the Phase variable to generate the sine
// voltages. 1 electrical degree corresponds to a PhaseInc value of 184,
// since the pointer to the sine table is a 16bit value, where 360 Elec

again, 184 is wrong; 65535/360 is 182 and not 184. However, such small errors doe not matter much.

- - - Updated - - -

Have you seen my calculations am i in the right direction? I will get little confidence to proceed further. Please advise.

Your calculations are all constant, there are no changes? Why? All the columns have the same values for all the rows.

You also should write the formula or equation in the exel sheet so that others can understand.
 

I am sorry it may have got corrupted. I am making more changes as per your instructions. I will update it properly with the formulae and explanation. Thank you again for your support.
 

#define PHASE_ZERO 57344
#define PHASE_ONE ((PHASE_ZERO + 65536/6) % 65536)

I have no idea why phase zero is set to a random value; 65536 is 2^16 (uint max value) corresponds to 360 deg phase. 65536/6 is equal to 60 deg. That is the max value of the sine table. %65536 takes the remainder of the integer division.

All the phase values must be in the range of 0 to 65536. Phase zero therefore corresponds to 360*57344/65536=315 deg or -45 deg (must be related to the motor mount hardware)
 

I am attaching the new excel file. Following calculations i added in the excel file
Column B:
Since the pwm signal is 20khz , 0.05ms each step i am taking every 0.05. So after 20 samples it is added to 1ms. At this place i am updating some of the parameters like phaseinc. Currently i have done upto 2ms.
Column C.
Here i am considering phase i am starting with sector 1. For sector 1 the phase is
Code:
phase = PhaseValues[1];
phase = PHASE_ONE
#define PHASE_ZERO 	57344
#define PHASE_ONE	((PHASE_ZERO + 65536/6) % 65536)
Hence
phase = ((57344 + 65536/6) % 65536);
phase = 2730;
Column D:period
On power assuming maximum period or running at minimum RPM that is 60 rpm. From the program i have taken the value
Code:
#define MAXPERIOD	31250	// For 60 min rpm and 10 poles motor
Column E: PhaseInc
The phaseinc as per the formula
Code:
div(512000,period) gives me 16.

Column F:ControlOutput (Volts)
Here I am considering as the difference between the reference speed and the measured speed.
The reference speed i am assuming 300 rpm in terms of hexadecimal as per the document is 6000RPM --> 0x7FFF, 300 --> 300*0x7fff/6000 -> 1638
the measured speed is minimum rpm that is 60 which corresponds to 60 * 0x7fff / 6000 -> 327.
the controloutput is difference of these two parameters -> 1638-327 =

Column G: Measured RPM (60 rpm)
I am assuming a minimum value of 60 rpm initially. the measured speed is minimum rpm that is 60 which corresponds to 60 * 0x7fff / 6000 -> 327.

Column H: Sector1
Initially i am assuming in sector 1. The value of phase is added to phaseinc in pwm interrupt and passed to the function SVM along with controloutput in volts variable.
Column I: angle2
In the function SVM as per the condition
Code:
if(angle < VECTOR2)
angle = phase+phaseinc = 2730 + 16 = 2746 
VECTOR2 is 0x2aaa is 10922
angle < 10922
Hence
angle2 = angle - VECTOR1 = 2746 - 0;
hence angle2 is copied directly from phase Column C
Column J: angle1
From the program
Code:
angle1 = SIXTY_DEG - angle2;	// Calculate second angle referenced to 
angle1 = 10922 - 2746
angle1 = 8176
Hence angle1 = 10922 - Column I
Column K: t1
According to the program
Code:
t1 = sinetable[(unsigned char)(angle1 >> 6)];	// Look up values from
Hence shifting Column J by 6 bits.
Column L: t2
Code:
t2 = sinetable[(unsigned char)(angle2 >> 6)];
hence shifting Coloumn I by 6 bits.
Column M: t1_sinetable
Extracting from sinelookuptable[Column K]
I could not write formula but extracting manually from the code at the index in column K
Column N: t2_sinetable
Extracting from sine lookup table angle2
Column O: Refspeed
I have kept constant 300 rpm and its value is 1638.
Column P:
From the program
Code:
// Scale t1 to by the volts variable.
	t1 = ((long)t1*(long)volts) >> 15;
	// Scale t1 for the duty cycle range.
	t1 = ((long)t1*(long)tpwm) >> 15;
i have implemented the logic of sinetable * volts * dutycycle with shifting by 15.
tpwm is 1000

Column Q:
As above i have done for t2
Column R: half_t0
From the program
Code:
half_t0 = (tpwm - t1 - t2) >> 1;		// Calculate half_t0 null time from 
                                           // period and t1,t2
I have implemented the same using formula

Column S,T,U: PDC1, PDC2, PDC3
Code:
// Calculate duty cycles for Sector 1  (0 - 59 degrees)
	PDC1 = t1 + t2 + half_t0;
	PDC2 = t2 + half_t0;
	PDC3 = half_t0;

I am trying to add further calculations. I want to add data in such a way that

Test Case1: When running at constant RPM of some value of say 1000RPM when both ref speed and measured speed are equal i want to see a sine pattern of PDC registers.

Test Case2 : When running at higher RPM i want to simulate the same sine wave but with higher duty.

Please tell if my assumptions are correct and can i achieve it? And why sine look up table is only 60degrees. How does it handle the negative values i am unable to understand? Sorry for the lengthy mail if any mistakes please excuse me.
 

Attachments

  • cal_ver1.zip
    18.2 KB · Views: 133

Phase should not be const; it must increase with time. After one period, the phase must come back to the phase_zero. I shall look into the program and check that. I do not think Col C should be const.

Col D is const means that the motor is running at a const speed; if you want to change the speed, this will change.

Col E (phase_inc is const means that the motor is running at a const speed; if you want to increase the speed, this value will change.

Col F- the measured speed is obtained from the hall sensors; I need to check the routine.

you produce the sine table in the exel sheet by writing the formula in one top cell =INT(sin(row()*(360/1024)*(PI()/180))*32768)
First number will be zero, you select the cell and drag down using the corner hook till 171 rows are filled. In the present example, you can use (row()-4) because your numbers start from the fourth row. The int function rounds down; you should use round function.
 
When i was searching for errata for that application i came across the following website https://www.microchip.com/forums/m600550.aspx explaining the reason for 512000UL. And the same project modified for other micro i found which i am attaching. Luckily as you suspected the phase_zero was zero.
Code:
#define PHASE_ZERO 	0
Still going through the code. Trying to get the sine wave in excel using PDC registers. Thanks for your support.
 

Attachments

  • AN1017_Source_Code_dsPIC33EP512MU810_MCHV_MOTOR_80_optimized.zip
    563.2 KB · Views: 99

Yes, the corrected version phase values are correct; phase-zero is zero, _one is 60 deg, _two is 120 deg, _three is 180 deg and so on.

I strongly suggest when you revise this software, make it device independent (everything should be referred to the PWM frequency and the interrupts) and not to the MPU oscillator.
 

I have created new excel sheet for sector 1 and sector2 with assumptions of it starts from phase 0 with 6000 rpm or phaseinc of 312 and goes to phase2 with the same rpm. Can you please review it. Now main doubt is how the look up table covers the negative angles? I am unable to understand it. Is it not required? Please advise.
 

Attachments

  • cal_ver2.zip
    19.1 KB · Views: 119

Look up tables DO NOT use negative values; the reason is simple. PWM cannot use negative values. Negative halves are produced in the hardware by switching the high_side and low_side. This switching is always done at zero crossing. The voltages stay positive but the current direction changes (they act like a virtual voltage doubler because we get current from -I to +I using only one positive voltage).

For a normal motor, the current in the coils changes with the line frequency. Here if you do not change the current, the motor will not move. You change the current by changing the phase. Because the pulses are coming at a const rate (20 kHz), you must increase the phase faster if you want to move the motor faster. That is done by the phase_inc variable in the program.
 

Sector 1 and sector 2 are identical and are separated by 120 deg; I shall see the source code and then comment.
 

There is no point copying the software blindly; it will work only on the demo board because it has been extensively configured accordingly. You will need to go through line by line and reconfigure.

Hence my first set of questions: are you using the same demo board? Are you using the same motor specified? Did your compilation went through without any error?

In case you are using another MCU and/or a different motor, first trim the software all the fat: features you do not need or do not understand. Do not delete lines; just comment them out and watch for compiler errors. Proceed only one step at one time.

Do you really need real time display? You can remove that part.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top