📄 svpwm1.asm
字号:
; calculating ub
lacl index
and #0ffh
add #67 ; for ub lagging 120 to ua
sub 201
bcnd sin_cirB,LT
sacl indexB
sin_cirB:
add #sintab ; in sine table lag 67 word
sacl tmp
lar ar5,tmp
lacl * ;look up sine table
sacl sintetaB ;get value of sintetaA
lt sintetaB ; Q15
mpy #Umax ;ub=Umax*sintetaB,Umax(Q12)=1000h
pac ; ub(Q12), for Q15*Q12=Q27, get off
sach ub,1 ; low 16 bits,then Q11,so left-shift
; 1 bit, Q12
lacl index
and #0ffh
add #1 ; inext=index+1,indicate next
sacl index ; element of sine table
; calculating uc,in 3-phase system is unnecessery
;lacl index
;and #0ffh
;add #67 ; for uc lagging 240 to ua
;add #sintab ; in sine table lag 134 word
;sacl tmp
;lar ar5,tmp
;lacl * ;look up sine table
;sacl sintetaB ;get value of sintetaA
;lt sintetaB ; Q15
;mpy #Umax ;uc=Umax*sintetaC,Umax(Q12)=1000h
;pac ; uc(Q12), for Q15*Q12=Q27, get off
;sach ub,1 ; low 16 bits,then Q11,so left-shift
; 1 bit, Q12
;; ;
;; End ua, ub, uc calculation ;
;; We get the desired 3-phase voltages. ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Clarke transformation ;
;; (a,b)==>(alfa,beta) ;
;; usalfa=ua ;
;; usbeta=(2*ub+ua)/sqrt(3) ;
lacc ua
sacl usalfa ;usalfa 4.12
add ub
neg
sacl uc
lacc ub,1 ;usbeta=(2*ub+ua)/sqrt(3)
add ua
sacl tmp
lt tmp
mpy #sqrt3inv ;093dh, 4.12, 1/sqrt(3)=0.57735
pac
sach usbeta,4 ;usbeta(Q12), for Q12*Q12=Q24,
;get off low 16 bits,then Q8,
;so left-shift 4 bit, Q12
;; End Clarke transformation ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Park transformation
;; (alfa,beta)==>(d,q)
;; Usually in motor drive system, we put d_q axis same position
;; to alfa_beta axis at t=0, in which transformation equation
;; is given as following:
;; usd=usalfa*cosTeta_cm + usbeta*sinTeta_cm
;; usq=-usalfa*sinTeta_cm + usbeta*cosTeta_cm
;; While in PWM rictifier system, for we need put grid voltage
;; vector Us to d-axis when t=0 and assuming iq=0 and keeping
;; id same phase to Us to get unit power factor, so the d-q axis
;; is lag 90 degree to above, and the transformation equation is:
;; sin(Teta-90)=-cosTeta
;; cos(Teta-90)=sinTeta
;; usd=usalfa*sinTeta_cm - usbeta*cosTeta_cm
;; usq=usalfa*cosTeta_cm + usbeta*sinTeta_cm
;when t=0, Teta_cm=0, look up table to get sin and cos value
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SPACE VECTOR PULSE WIDTH MODULATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sector calculation
; reference voltage for sector
; Vref1=usbeta
; Vref2=(-usbeta+sqrt(3)*usalfa)/2
; Vref3=(-usbeta-sqrt(3)*usalfa)/2
lt usalfa ;Q12
mpy #sqrt32 ;sqrt32= 0ddbh sqrt(3)/2, 4.12
pac ;sqrt(3)*usalfa/2
sub usbeta,11 ;-vsbeta/2,so left-shift 11
sach Vref2,4 ;Q12
pac
neg ;-sqrt(3)*usalfa/2
sub usbeta,11 ;-vsbeta/2,so left-shift 11
sach Vref3,4 ;Q12
lacl usbeta
sacl Vref1 ;Vref1=usbeta,Q12
; End reference voltage for sector calculation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Time quality X,Y,Z Calculation
; VDCinvT=PWMPRD/Vdc=400=190h
; X=sqrt(3)*VDCinvT*usbeta
; Y=(sqrt(3)*VDCinvT*usbeta + 3*VDCinvT*usalfa)/2
; Z=(sqrt(3)*VDCinvT*usbeta - 3*VDCinvT*usalfa)/2
lt VDCinvT
mpy #sqrt32
pac
sach tmp,4 ;tmp=sqrt(3)*VDCinvT/2,Q12
lt tmp
mpy usbeta
pac
sach X,4 ;X=sqrt(3)*VDCinvT*usbeta/2,Q12
lacc X
sacl tmp1 ;tmp1=sqrt(3)*VDCinvT/2,Q12
sacl X,1 ;X=sqrt(3)*VDCinvT*usbeta,Q12
lt VDCinvT
splk #1800h,tmp ;3/2=1800h(Q12)
mpy tmp ;3*VDCinvT/2
pac
sach tmp,4 ;tmp=3*VDCinvT/2 , Q12
lt tmp
mpy usalfa ;3*VDCinvT/2*usalfa , Q12
pac
sach tmp,4 ;tmp=3/2*VDCinvT*usalfa, Q12
lacc tmp
add tmp1 ;tmp1=sqrt(3)*VDCinvT/2,Q12
sacl Y
;Y=3/2*VDCinvT*usalfa+sqrt(3)*VDCinvT/2,Q12
sub tmp,1 ;acc-tmp*2
sacl Z
;Z=3/2*VDCinvT*usalfa-sqrt(3)*VDCinvT/2,Q12
; End X,Y,Z calculation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 60 degrees sector determinnation
lacl #0
sacl sector
lacc Vref1
bcnd Vref1_neg,LEQ
;if Vref1<=0,do not set bit1 of sector
lacc sector
or #1
sacl sector
Vref1_neg:
lacc Vref2
bcnd Vref2_neg,LEQ
;if Vref2<=0,do not set bit1 of sector
lacc sector
or #2
sacl sector
Vref2_neg:
lacc Vref3
bcnd Vref3_neg,LEQ
;if Vref3<=0,do not set bit1 of sector
lacc sector
or #4
sacl sector
Vref3_neg:
;; End 60 degrees sector determinnation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; t1 and t2 calculation depending on the sector number
;sector=1 t1=Z t2=Y
lacl sector
sub #1
bcnd no2,NEQ
lacc Z
sacl t1
lacc Y
sacl t2
b t1t2out
no2: ;sector=2 t1=Y t2=-X
lacl sector
sub #2
bcnd no3,NEQ
lacc Y
sacl t1
lacc X
neg
sacl t2
b t1t2out
no3: ;sector=3 t1=-Z t2=X
lacl sector
sub #3
bcnd no4,NEQ
lacc Z
neg
sacl t1
lacc X
sacl t2
b t1t2out
no4: ;sector=4 t1=-X t2=Z
lacl sector
sub #4
bcnd no5,NEQ
lacc X
neg
sacl t1
lacc Z
sacl t2
b t1t2out
no5: ;sector=5 t1=X t2=-Y
lacl sector
sub #4
bcnd no6,NEQ
lacc X
sacl t1
lacc Y
neg
sacl t2
b t1t2out
no6: ;sector=2 t1=-Y t2=-Z
lacc Y
neg
sacl t1
lacc Z
neg
sacl t2
t1t2out:
;; End t1 and t2 calculation
;; if t1+t2>PWMPRD, we have to saturate t1 and t2
;; t1=PWMPRD*t1/(t1+t2)
;; t2=PWMPRD*t2/(t1+t2)
lacc t1
add t2
sacl tmp ;tmp=t1+t2
sub #PWMPRD
bcnd nosaturation,LT,EQ
;; t1 and t2 saturation
lacc #PWMPRD,15
rpt #15
subc tmp ;divide PWMPRD by t1+t2
sacl tmp ;tmp=PWMPRD/(t1+t2)
lt tmp
mpy t1
pac
sach t1,1 ;t1=PWMPRD*t1/(t1+t2)
mpy t2
pac
sach t2,1 ;t2=PWMPRD*t2/(t1+t2)
;; End t1 and t2 saturation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
nosaturation:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; each phase working time taon,tbon,tcon calculation
;; calculating the PWM commutation instants of 3 channels
;; taon=(PWMPRD-t1-t2)/2
;; tbon=taon+t1
;; tcon=tbon+t2
lacc #PWMPRD
sub t1
sub t2
sfr ;right shift 1 bit
sacl taon ;taon=(PWMPRD-t1-t2)/2
add t1 ;tbon=taon+t1
sacl tbon
add t2 ;tcon=tbon+t2
sacl tcon
;; End taon,tbon,tcon calculation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sector switching
;; Depending on the sector of number we have to switch
;; the calculated taon,tbon,tcon to the correct channel
;sect1 ;sector 1
lacl sector
sub #1
bcnd sect2,NEQ
bldd tbon,#CMPR1
bldd taon,#CMPR2
bldd tcon,#CMPR3
b endPWM
sect2: ;sector 2
lacl sector
sub #2
bcnd sect3,NEQ
bldd taon,#CMPR1
bldd tcon,#CMPR2
bldd tbon,#CMPR3
b endPWM
sect3: ;sector 3
lacl sector
sub #3
bcnd sect4,NEQ
bldd taon,#CMPR1
bldd tbon,#CMPR2
bldd tcon,#CMPR3
b endPWM
sect4: ;sector 4
lacl sector
sub #4
bcnd sect5,NEQ
bldd tcon,#CMPR1
bldd tbon,#CMPR2
bldd taon,#CMPR3
b endPWM
sect5: ;sector 5
lacl sector
sub #5
bcnd sect6,NEQ
bldd tcon,#CMPR1
bldd taon,#CMPR2
bldd tbon,#CMPR3
b endPWM
sect6: ;sector 6
bldd tbon,#CMPR1
bldd tcon,#CMPR2
bldd taon,#CMPR3
;; END Sector switching
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
*** END SPACE VECTOR PWM
*************************************************************
endPWM:
*************************************************************
*** clear all flags, which maybe change with only T1
*** underflow int
ldp #EVIFRA>>7
splk #200h,EVIFRA
ldp #0
lacc #0ffh
sacl IFR ;reset IFR, write into 1 to clear
*** Context restore and return
*** SEE following context saving
larp ar7 ;ar7=74h
mar *+ ;ar7=75h
lacl *+ ;Acc low restored from 75h
add *+,16 ;Acc high restored from 76h
lst #0,*+ ;ST0 restored from 77h
lst #1,*+ ;ST1 restored from 78h
; context saving
; larp ar7 ;making ar7 as current AR,ar7=79h
; mar *- ;ar7=78h
; sst #1,*- ;content of ST1 saved to 78h,then ar7=77h
; sst #0,*- ;content of ST0 saved to 77h,then ar7=76h
; sach *- ;Acc high saved to 76h,then ar7=75h
; sacl *- ;Acc low saved to 75h,then ar7=74
; end context saving
clrc INTM
ret
; b PWMSER
*** End Context restore and return
*************************************************************
;;;;;; End PWM Underflow interrupt serve program ;;;;;;;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -