Park transformation for motor control
ManAtWork
Posts: 2,176
in Propeller 2
The Park or d/q-transformation is useful when controlling AC motors or brushless servo motors. It transforms currents or voltages from a three phase system with stator reference into a rectangular coordinate system that is referenced to the rotor. The output can be treated as if the motor was a DC machine. After calculations (PID control) are done the values are transformed back to the three phase system using the inverse Park transformation. The results can then be output to a three phase power stage.
The calculation of the matrix coefficients and the matrix multiplication normally are very complex operations. You'd need sine tables and lots of multiplications filling multiple pages with hundrets of instructions. But not on the P2 where this can be done quite elegant and efficient with the CORDIC solver.
The calculation of the matrix coefficients and the matrix multiplication normally are very complex operations. You'd need sine tables and lots of multiplications filling multiple pages with hundrets of instructions. But not on the P2 where this can be done quite elegant and efficient with the CORDIC solver.
{ Park transformation Park matrix: [+cos(T) +cos(T-120°) +cos(T+120°)] [-sin(T) -sin(T-120°) -sin(T+120°)] PM x (Iu Iv Iw) = (Id Iq) Id:= Iu*cos(T) + Iv*cos(T-120°) + Iw*cos(T+120°) Iq:= -Iu*sin(T) - Iv*sin(T-120°) - Iw*sin(T+120°) QROTATE performs x:= D*cos(S) - Q*sin(S) y:= D*sin(S) + Q*cos(S) So the matrix multiplication can be carried out with 3 QROTATE operations with Q=0, summing up the X/Y results and then scaling them by 2/3. x1,y1:= QROTATE Iu,T x2,y2:= QROTATE Iv,T-120° x3,y3:= QROTATE Iw,T+120° Id:= 2/3 * (x1 + x2 + x3) Iq:= -2/3 * (y1 + y2 + y3) } parkTrafo qrotate actU,theta ' input: actU,V,W, theta sub theta,angle120 qrotate actV,theta add theta,angle240 qrotate actW,theta sub theta,angle120 getqx actD getqy actQ getqx x getqy y add actD,x ' output: actD, actQ add actQ,y getqx x getqy y add actD,x add actQ,y scas actD,##$2AAA ' *= +2/3 mov actD,#0 scas actQ,##$D555 ' *= -2/3 mov actQ,#0 ret angle120 long $5555_5555 ' 120° as unsigned long angle240 long $AAAA_AAAA ' 240°
Comments
I forgot to say that I use 16 bit signed format for all current and voltage values. This should be sufficient for most applications. The CORDIC even could do full 32 bit resolution, only the scaling had to use 32 bit multiplication instead of the SCAS instructions. The angle (theta) has to be left adjusted.
We really need a wiki for gems like this. There are so many of these golden nuggets that get buried under the sheer volume of posts.
JRoark,
Cluso's sticky will do for the moment - https://forums.parallax.com/discussion/169542/p2-links-for-where-to-obtain-tools-sample-test-code-reference-only
I think what AJL is talking about, would be quite useful in motor research labs, where the display could graph real-time effects and measurements, and the USB/SD allow easy changes for testing.
There are also wireless power transfer projects, where that combination would be very nice to have.
Yeah, agreed. I thought about putting this into OBEX (GIT hub). But these "nuggets" are part of a bigger puzzle which still has to be put together. So I think I'll wait until all the interfaces are clear. A piece of assembler code alone is not very useful to anyone else except as example to learn from.
That and probably more.
I was hinting at all the great experimentation possibilities in one board with the P2 at the heart of it, and only really needing power drive stages to support it.
> It's far to early to promise anything but I thought of probably releasing my single axis servo controller project as open source or some sort of reference design. I'm not sure if it makes sense to put some of the code to the OBEX library. If I program for my own project I can hard code the pin numbers, buffer sizes and things like that. It is much more work to write a general purpose library where everything must be configurable and more robustness (range checking and error handling) is required.
All that extra code can make things less understandable. For learning, something simpler with maybe hard-coded values is okay because it lets the concept shine through more clearly.