Field Oriented Control using dsPic33

Electric Motors and Controllers

Field Oriented Control using dsPic33

Postby Burtie » Tue Oct 23, 2012 5:25 pm

Field oriented control (or vector control) of brushless motors promises many advantages over the simpler 6 step trapezoidal control.
Here are a few advantages that spring to mind;

1) Because the force is always kept at 90deg to the rotor, it should be more efficient.
2) For the same reason it should also generate less audible noise.
3) The use of space vector modulation, means it should be better able to drive low inductance loads.
4) The use of fast phase current monitoring means it should be better able to protect the power stage.
5) The algorithm allows accurate +/- torque control, allowing variable regenerative braking


The disadvantages ??
1) The algorithm requires a lot of computational power
2) It takes me ages to get my head around how it works :?

FOController.jpg
Field oriented control of a Turnigy SK63-74 outrunner



There are a handful of development kits around for this sort of work, from companies like Ti, ST, NXP, Toshiba, many of them based on ARM 32bit processors.
Atmel also have a kit based on their AVR32.

Microchip offer their motor development platform based on their range of digital signal processors dsPIC30 and dsPIC33.
Although only 16 bits, these devices run fast, have a specialised instruction set and compiler for doing this kind of job, and contain hardware specialy designed to deal with motor control.


I chose the Microchip dsPIC33, since it seemed about the cheapest way for me to get up and going, there is a whole raft of application notes and example code to start you off, and captain Lebowski appears to be having great success with a similar device !



Most of the Microchip examples are aimed at reducing the parts count to a minimum when driving things like washing machines and air conditioner fans. Where starting torque and slow speed operation is not so important. The FOC examples are all sensorless and required careful tailoring of hard coded parameters to work with each different motor I tried.
The sensorless position estimating needed to know the inductance and resistance values of each motor, so the motor behaviour could be modeled (or predicted).

This is all well and good, if you are making 100,000 washing machines -all the same, but no good for the 1-off ebike here and there :(

Consequently I found some adaptation was necessary:
I removed the open-loop sensorless startup, and the sensorless position estimation , and replace it all with our familiar 3 hall sensors and a bit of code to run a timer which interpolates the rotors angle between the sensors.

It works a treat. Nice dependable high torque startup, smooth slow running, and no need to know the values of the motor phase inductance or resistance :)

http://www.youtube.com/watch?v=YFREKbPm ... e=youtu.be



Phase Waveforms.jpg
Phase voltages show nice sine waves
Phase Waveforms.jpg (98.4 KiB) Viewed 5982 times


Next step, will be to build a bigger power stage so I can run the C80-100 motor on my RC dyno.

EDIT: Now done, can be seen in this thread here:
viewtopic.php?f=30&t=44910&start=100#p694066


Burtie
Last edited by Burtie on Fri Feb 20, 2015 9:59 am, edited 4 times in total. View post history.
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using DSPIC33

Postby MattyCiii » Tue Oct 23, 2012 7:49 pm

Burtie you rock!

Thanks for the post. After years of study at the ES school of higher education, I actually understood most of that. Thank you, and all the other ES big brains out there, for sharing your thoughts on this forum.
1st build: Dahon Jetstream folding bike. Quick, reliable, capable of 32mph. Light enough to lift, folds for easy transport by car/bus/train.
2nd build: RC powered 2009 Norco A-Line. Top speed 39mph. Built like a tank, it's resistant to Boston potholes, can stop on a dime, easily goes up/down curbs when necessary.
3rd build (just started): Scratch build ultimate utility bike. Based on a common power module using a NuVinci left side freewheel.
User avatar
MattyCiii
100 kW
100 kW
 
Posts: 1477
Joined: Sat May 05, 2007 2:06 pm
Location: Boston, MA, USA

Re: Field Oriented Control using DSPIC33

Postby whereswally606 » Wed Oct 24, 2012 1:25 am

Looks very promising, I'm guessing this will work with your optical boards too?

Keep up the good work, I've a huge eMax scooter motor that this might be perfect for
Distributing "Lebowski" FOC Controller PCB (Through hole) since 2016
Moped: Emax 110s 2009
whereswally606
100 kW
100 kW
 
Posts: 1001
Joined: Sun Jun 19, 2011 2:11 pm
Location: Cheshire, UK

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Wed Oct 24, 2012 5:18 am

Do you run some sort of PLL or DLL to interpolate between the hall signals, and use this to provide
sine waves to the motor. Do you compensate for the delay due to motor inductances ?
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Burtie » Wed Oct 24, 2012 5:49 am

I am running the standard Microchip AN1078 FOC algorithm, except the rotor angle is supplied by a digital delay-locked loop synced to the hall sensors.
Any delay due to motor inductance should be compensated for by the FOC algorithm.

There is also scope for applying timing advance via the dll, to achieve field weakening, and raise the kv (all be it at the expense of some efficiency).

The motor I am using happens to have a very sinusoidal BEMF signature, so the drive voltages also look very sinusoidal.

Burtie
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Wed Oct 24, 2012 6:00 am

Burtie wrote:The motor I am using happens to have a very sinusoidal BEMF signature, so the drive voltages also look very sinusoidal.
Burtie


AFAIK there no relation between the drive waveform and the back-emf waveform ? FOC cares about the fundamentals, thats it.
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Burtie » Wed Oct 24, 2012 6:25 am

I imagined that when only pushing small phase currents at low speed (as is the case here, --unloaded motor), the drive voltage would closely match the BEMF.

As the speed and current increase, stator inductance and resistance will become more significant in the equation, and cause the drive waveform shape to change.
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Wed Oct 24, 2012 10:24 am

Burtie wrote:I imagined that when only pushing small phase currents at low speed (as is the case here, --unloaded motor), the drive voltage would closely match the BEMF.

As the speed and current increase, stator inductance and resistance will become more significant in the equation, and cause the drive waveform shape to change.


Hm, are you sure ? The way I see it the controller outputs a sine wave to matter what the back-emf waveform is. At no load, with a
back emf not equal to a sine, there will be some discrepancy resulting in the motor accellerating / decellerating at a high
rate. This causes the typical 'electric motor whine'. Since most motors make close to a sine wave back emf they are
quiet when fed with a sine. When the amplitude increases and the controller starts clipping its output sine the whine returns.
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Arlo1 » Wed Oct 24, 2012 10:31 am

Very cool burtie. Can't wait to see where you go with this.
My Leaf motor controller build. http://endless-sphere.com/forums/viewto ... 27#p963227
My YSR build http://www.youtube.com/watch?v=BRo8r5g4NBg
RC and most types of Lithium batteries you MUST know your individual cell voltages charging and discharging.
Don't keep them were you cant afford smoke or fire!
Never above 4.2v never below 2.7v EVER!!!
HI power controller design. Game Changer
User avatar
Arlo1
100 GW
100 GW
 
Posts: 8229
Joined: Sun Apr 26, 2009 10:36 pm
Location: Nanaimo BC Canada

Re: Field Oriented Control using dsPIC33

Postby Kingfish » Wed Oct 24, 2012 10:36 am

Subscribed. 8)

Many thanks, KF
* My 2WD Garden Wall
* Kinaye MotorSports
* Primary ride: 2WD Disc 9C 2806-equiv / Dual Lyen 12FET / 20S7P LiPo.
* Epics: Going to California: 2011 8)
* 50-mph, 101, 10k-Club. 12,527 miles-to-date, 7037 as 2WD.

It is by caffeine alone I set my mind in motion.
It is by the beans of Java that thoughts acquire speed.
The hands acquire shakes, the shakes become a warning.
It is by caffeine alone I set my mind in motion.
User avatar
Kingfish
10 GW
10 GW
 
Posts: 4274
Joined: Wed Feb 03, 2010 11:23 am
Location: Redmond, WA-USA, Earth, Sol, Orion–Cygnus Arm, Milky Way. Age: > yesterday < tomorrow

Re: Field Oriented Control using dsPIC33

Postby Burtie » Wed Oct 24, 2012 12:52 pm

Think I might be getting into deep water here ..... :wink:


Lebowski wrote:Hm, are you sure ? ...


I think so.

given:
R is phase resistance
L is phase inductance
I is phase current

At any given time the driving voltage, V, across 1 phase of the motor, will be:

V = Vbemf + I*R + L* dI/dt

so if I is kept small, then: V =(approx) Vbemf


Consider the more general case---
If the motor is running in steady state (i.e. velocity is constant, torque is constant) The FOC will attempt to keep Iq and Id constant.

To achieve this, Ia, Ib, Ic must be varying sinusoidally, 120 degrees apart. (These are the phase currents that are measured by the FOC system).

The system will attempt to vary the voltage applied to each phase in any way necessary to achieve this. Note this voltage is not necessarily sinusoidal, but depends on the inductance, resistance, BEMF characteristic, speed and torque of the motor, as described in the equation above.


If saturation occurs, and the ideal voltage can no longer be applied, we get torque ripple (because Iq and Id are no longer constant). And this will generate a higher level of audiable noise


Sound plausable ?
Burtie
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Wed Oct 24, 2012 2:07 pm

Ehm, looking at the system in AN1078, the waveform to the motor is determined/ calculated in the Inverse Park and inverse Clark transformation block ( figure 10 and 11). Because the inverse Park uses sine functions you'll end up with sine waves at the output, the waveform shape has nothing to do with the back emf.... me thinks :D

Also in the Clark and Park transforms the implicit assumption is made that the waveforms are sinusoidal (In the Clarke by having vectors of equal length)
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Burtie » Wed Oct 24, 2012 5:33 pm

Err um :D
Would it be fair to say...

The inverse Park transform will only output pure sinusoid signals if its inputs, Vq and Vd, are constant.

Vq and Vd are the outputs from the two PI controllers, so these quantities will be constantly changing due to any miss-match between IqRef and IqMeasured or IdRef and IdMeasured.
Result - control voltages are not necessarily pure sinusoid.


If a FOC system was unable to modify the shape of its control voltages, it would have no advantage over the much simpler pure sine wave controller as described in AN1017 "Sinusoidal Control of PMSM Motors with dsPIC30F DSC"

Edit -- FOC system will compensate for inductance by correcting timing, Simpler sinusoidal drive will not.

The Clark and Park transforms deal with transforming current vectors, most of which we are aiming to make sinusoidal.
The Inverse Clark and Inverse Park transforms are dealing with voltage vectors, which we are controlling in order to try and create the sinusoidal currents.


Burtie
Last edited by Burtie on Wed Jan 09, 2013 11:05 am, edited 1 time in total. View post history.
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby roller » Wed Oct 24, 2012 8:05 pm

Kingfish wrote:Subscribed. 8)

Many thanks, KF


ditto.
Jackalope (one of a kind): https://picasaweb.google.com/biosmell/Jackalope
ReVolt: still holds a NEDRA record http://nedra.com/100mph_club.html#revolt
ReCycle (started it all): http://www.evalbum.com/505
User avatar
roller
10 W
10 W
 
Posts: 98
Joined: Tue May 01, 2007 1:08 pm
Location: Seattle, WA

Re: Field Oriented Control using dsPIC33

Postby mauimart » Wed Oct 24, 2012 11:13 pm

Burtie,
Nice work in modding the FOC code to work in sensored mode. I have the same microchip development board and had some limited success a while back in using it to drive a modest 6-FET power stage (2kW driving a 30 inch prop). I however was implementing microchips more basic trapezoidal commutation code (can't remember the apnote numbers) in both sensored and sensorless mode. I do remember that the low rpm control in sensorless mode was much better than any of the RC ESC's could offer while driving the C80100. I shelved my development following a power board melt down. Your success with FOC has got me thinking about picking it back up again and rebuilding the power stage. Thanks. :D
Martin

https://www.youtube.com/watch?v=8TMRn5TOvIA
https://www.youtube.com/watch?v=Rj0mz2glt7c
User avatar
mauimart
100 W
100 W
 
Posts: 218
Joined: Tue Nov 10, 2009 2:08 pm
Location: maui

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Thu Oct 25, 2012 12:29 am

Burtie wrote:Vq and Vd are the outputs from the two PI controllers, so these quantities will be constantly changing due to any miss-match between IqRef and IqMeasured or IdRef and IdMeasured.
Result - control voltages are not necessarily pure sinusoid.


True, but are the bandwidths of those two PI controllers not too low for this ? I would think the
bandwidths are too low to follow the voltages as it goes through 1 e-rpm, that the PI controll loops
controll the 'long term average' (long term being a few e-rpm cycles)
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Mr.K » Thu Oct 25, 2012 2:54 am

Lebowski wrote:Ehm, looking at the system in AN1078, the waveform to the motor is determined/ calculated in the Inverse Park and inverse Clark transformation block ( figure 10 and 11). Because the inverse Park uses sine functions you'll end up with sine waves at the output, the waveform shape has nothing to do with the back emf.... me thinks :D

Also in the Clark and Park transforms the implicit assumption is made that the waveforms are sinusoidal (In the Clarke by having vectors of equal length)

Shouldn't the output wave form depend on what reference waveform that is used in the control? In the AN1078 case the code is for Space Vector Modulation (SVM) with a output waveform like this.
Phase voltage
https://dl.dropbox.com/u/53678622/665rpm-Vph.png
Line voltage
https://dl.dropbox.com/u/53678622/665rpm-Vll.png
Line voltage not sinusoidal, but rather triangular with rounded peaks.
Mr.K
1 µW
1 µW
 
Posts: 3
Joined: Thu Apr 19, 2012 3:46 pm

Re: Field Oriented Control using dsPIC33

Postby Burtie » Thu Oct 25, 2012 4:39 am

Lebowski wrote:
Burtie wrote:Vq and Vd are the outputs from the two PI controllers, so these quantities will be constantly changing due to any miss-match between IqRef and IqMeasured or IdRef and IdMeasured.
Result - control voltages are not necessarily pure sinusoid.


True, but are the bandwidths of those two PI controllers not too low for this ? I would think the
bandwidths are too low to follow the voltages as it goes through 1 e-rpm, that the PI controll loops
controll the 'long term average' (long term being a few e-rpm cycles)



Good question.
-I looked at the code, and it seems the PI loops for Vq and Vd are executed every pwm cycle (20khz), so the bandwidth is easily enough to modify the waveform within 1 electrical revolution.

The PI loop controlling the speed is the only one that runs slower than this, at 1kHz.
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Burtie » Thu Oct 25, 2012 4:47 am

Mr.K wrote:Shouldn't the output wave form depend on what reference waveform that is used in the control? In the AN1078 case the code is for Space Vector Modulation (SVM) with a output waveform like this.
Phase voltage
https://dl.dropbox.com/u/53678622/665rpm-Vph.png
Line voltage
https://dl.dropbox.com/u/53678622/665rpm-Vll.png
Line voltage not sinusoidal, but rather triangular with rounded peaks.


Yes the waveform will appear differently depending how you look at it. In the scope picture I posted earlier, the (isolated)scope probe was connected across two phase wires, and shows a trace similar to the second image you posted.

Connecting the probe between one phase wire and Ground will yield a trace similar to the first image you posted.
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Burtie » Thu Oct 25, 2012 5:02 am

mauimart wrote:Burtie,
Nice work in modding the FOC code to work in sensored mode. I have the same microchip development board and had some limited success a while back in using it to drive a modest 6-FET power stage (2kW driving a 30 inch prop). I however was implementing microchips more basic trapezoidal commutation code (can't remember the apnote numbers) in both sensored and sensorless mode. I do remember that the low rpm control in sensorless mode was much better than any of the RC ESC's could offer while driving the C80100. I shelved my development following a power board melt down. Your success with FOC has got me thinking about picking it back up again and rebuilding the power stage. Thanks. :D
Martin

https://www.youtube.com/watch?v=8TMRn5TOvIA
https://www.youtube.com/watch?v=Rj0mz2glt7c



Nice work Martin, you need to dig out that board and patch it up to get the show back on the road !
I can hep you with the code for the AN1078 sensored conversion If you like. I will PM you soon.

Burtie
User avatar
Burtie
10 kW
10 kW
 
Posts: 561
Joined: Fri Mar 27, 2009 9:45 am
Location: UK

Re: Field Oriented Control using dsPIC33

Postby Alan B » Thu Oct 25, 2012 5:51 am

Very nice work!

After having done what you have, do you feel the extra speed of the ARM is worthwhile? Would it make the job easier or not?
User avatar
Alan B
100 GW
100 GW
 
Posts: 6586
Joined: Sat Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Thu Oct 25, 2012 5:59 am

Mr.K wrote:
Lebowski wrote:Ehm, looking at the system in AN1078, the waveform to the motor is determined/ calculated in the Inverse Park and inverse Clark transformation block ( figure 10 and 11). Because the inverse Park uses sine functions you'll end up with sine waves at the output, the waveform shape has nothing to do with the back emf.... me thinks :D

Also in the Clark and Park transforms the implicit assumption is made that the waveforms are sinusoidal (In the Clarke by having vectors of equal length)

Shouldn't the output wave form depend on what reference waveform that is used in the control? In the AN1078 case the code is for Space Vector Modulation (SVM) with a output waveform like this.
Phase voltage
https://dl.dropbox.com/u/53678622/665rpm-Vph.png
Line voltage
https://dl.dropbox.com/u/53678622/665rpm-Vll.png
Line voltage not sinusoidal, but rather triangular with rounded peaks.


It seems they're using a moving midpoint to get to a bit higher amplitude...
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Thu Oct 25, 2012 6:01 am

Burtie wrote:Good question.
-I looked at the code, and it seems the PI loops for Vq and Vd are executed every pwm cycle (20khz), so the bandwidth is easily enough to modify the waveform within 1 electrical revolution.

The PI loop controlling the speed is the only one that runs slower than this, at 1kHz.


The bandwidth is not determined solely by the sample rate (20 kHz), but by samplerate and loop coefficients... pity I can't see the code here
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Lebowski » Thu Oct 25, 2012 6:03 am

Alan B wrote:Very nice work!

After having done what you have, do you feel the extra speed of the ARM is worthwhile? Would it make the job easier or not?


Looking at my controller etc, the capabilities of the ADC are most important, processor speed comes second. For me an ARM makes no
sence as I don't need the speed and it would need a separate ADC chip...
User avatar
Lebowski
100 MW
100 MW
 
Posts: 2978
Joined: Tue Jun 28, 2011 1:38 am
Location: beautiful Zurich, Switzerland

Re: Field Oriented Control using dsPIC33

Postby Alan B » Thu Oct 25, 2012 6:29 am

Lebowski wrote:
Alan B wrote:Very nice work!

After having done what you have, do you feel the extra speed of the ARM is worthwhile? Would it make the job easier or not?


Looking at my controller etc, the capabilities of the ADC are most important, processor speed comes second. For me an ARM makes no
sence as I don't need the speed and it would need a separate ADC chip...


If the ADC is the most important item then perhaps a separate ADC is indicated. ADCs in micro chips are hardly the epitome of ADC performance!
User avatar
Alan B
100 GW
100 GW
 
Posts: 6586
Joined: Sat Sep 11, 2010 7:43 am
Location: San Francisco Bay Area, USA

Next

Return to Motor Technology

Who is online

Users browsing this forum: No registered users and 7 guests