📄 focpmsm.asm
字号:
sub #Tonmax
bcnd t1_ok,GEQ ;if t1>Tonmax then t1_ok
lacl #Tonmax
sacl t1
t1_ok
lacc t2
sub #Tonmax
bcnd t2_ok,GEQ ;if t2>Tonmax then t2_ok
lacl #Tonmax
sacl t2
t2_ok
*** END t1 and t2 calculation
lacc t1 ;if t1+t2>2*Tonmax we have to saturate t1 and t2
add t2 ;
sacl tmp ;
sub #MAXDUTY ;
bcnd nosaturation,LT,EQ
*** t1 and t2 saturation
lacc #MAXDUTY,15 ;divide MAXDUTY by (t1+t2)
rpt #15 ;
subc tmp ;
sacl tmp ;
lt tmp ;calculate saturate values of t1 and t2
mpy t1 ;t1 (saturated)=t1*(MAXDUTY/(t1+t2))
pac ;
sach t1,1 ;
mpy t2 ;t2 (saturated)=t2*(MAXDUTY/(t1+t2))
pac ;
sach t2,1 ;
*** END t1 and t2 saturation
nosaturation
*** taon,tbon and tcon calculation
lacc #PWMPRD ;calculate the commutation instants taon,
;tbon and tcon
sub t1 ;of the 3 PWM channels
sub t2 ;taon=(PWMPRD-t1-t2)/2
sfr ;
sacl taon ;
add t1 ;tbon=taon+t1
sacl tbon ;
add t2 ;tcon=tbon+t2
sacl tcon ;
*** END taon,tbon and tcon calculation
*** sector switching
lacl sector ;depending on the sector number we have
sub #1 ;to switch the calculated taon, tbon and tcon
bcnd nosect1,NEQ ;to the correct PWM channel
;(see SPACE VECTOR Modulation references for
; details)
bldd tbon,#CMPR1 ;sector 1
bldd taon,#CMPR2
bldd tcon,#CMPR3
b dacout
nosect1
lacl sector
sub #2
bcnd nosect2,NEQ
bldd taon,#CMPR1 ;sector 2
bldd tcon,#CMPR2 ;
bldd tbon,#CMPR3 ;
b dacout
nosect2
lacl sector
sub #3
bcnd nosect3,NEQ
bldd taon,#CMPR1 ;sector 3
bldd tbon,#CMPR2 ;
bldd tcon,#CMPR3 ;
b dacout
nosect3
lacl sector
sub #4
bcnd nosect4,NEQ
bldd tcon,#CMPR1 ;sector 4
bldd tbon,#CMPR2 ;
bldd taon,#CMPR3 ;
b dacout
nosect4
lacl sector
sub #5
bcnd nosect5,NEQ
bldd tcon,#CMPR1 ;sector 5
bldd taon,#CMPR2 ;
bldd tbon,#CMPR3 ;
b dacout
nosect5
bldd tbon,#CMPR1 ;sector 6
bldd tcon,#CMPR2 ;
bldd taon,#CMPR3 ;
*** END sector switching
*** END * SPACE VECTOR Pulse Width Modulation
.endif
dacout
****************************************************************
* DAC output of channels 'da1', 'da2', 'da3' and 'da4' *
* Output on 12 bit Digital analog Converter *
* 5V equivalent to FFFh *
****************************************************************
ldp #sector
lacc sector,7 ;scale sector by 2^7 to have good displaying
sacl sectordisp ;only for display purposes
*** DAC out channel 'da1'
lacc #ia ;get the address of the first elements
add da1 ;add the selected output variable offset
; 'da1' sent by the terminal
sacl daout ;now daout contains the address of the
; variable to send to DAC1
lar ar5,daout ;store it in AR5
lacc * ;indirect addressing, load the value to send out
;the following 3 instructions are required to
;adapt the numeric format to the DAC resolution
sfr ;on a 12 bit DAC, +/- 2000h = [0,5] Volt
sfr ;-2000h is 0 Volt
add #800h ;0 is 2.5 Volt.
sacl daouttmp ;to prepare the triggering of DAC1 buffer
out daouttmp,DAC0_VAL
*** DAC out channel 'da2'
lacc #ia ;get the address of the first elements
add da2 ;add the selected output variable offset
;'da1' sent by the terminal
sacl daout ;now daout contains the address of the
; variable to send to DAC1
lar ar5,daout ;store it in AR5
lacc * ;indirect addressing, load the value to send out
;the following 3 instructions are required to
;adapt the numeric format to the DAC resolution
sfr ;we have 10 bit DAC, we want to have the
;number 2000h = 5 Volt
sfr
add #800h ;
sacl daouttmp ;to prepare the triggering of DAC1 buffer
out daouttmp,DAC1_VAL
*** DAC out channel 'da3'
lacc #ia ;get the address of the first elements
add da3 ;add the selected output variable offset 'da1'
;sent by the terminal
sacl daout ;now daout contains the address of the variable
;to send to DAC1
lar ar5,daout ;store it in AR5
lacc * ;indirect addressing, load the value to send out
;the following 3 instructions are required to
;adapt the numeric format to the DAC resolution
sfr ;we have 10 bit DAC, we want to have the number
;2000h = 5 Volt
sfr
add #800h
sacl daouttmp ;to prepare the triggering of DAC1 buffer
out daouttmp,DAC2_VAL
*** DAC out channel 'da4'
lacc #ia ;get the address of the first elements
add da4 ;add the selected output variable offset 'da1'
;sent by the terminal
sacl daout ;now daout contains the address of the
;variable to send to DAC1
lar ar5,daout ;store it in AR5
lacc * ;indirect addressing, load the value to send out
;the following 3 instructions are required
;to adapt the numeric format to the DAC resolution
sfr ;we have 10 bit DAC, we want to have the
;number 2000h = 5 Volt
sfr
add #800h
sacl daouttmp ;to prepare the triggering of DAC1 buffer
out daouttmp,DAC3_VAL
*** END DAC out
OUT tmp,DAC_VAL ;start D to A convertion
*** END: PWM enable
b ContextRestoreReturn
*END ControlRoutine
.endif
ContextRestoreReturn
**************************************
* Context restore and Return
**************************************
larp ar4
mar *+
lacl *+ ;Accu. restored for context restore
add *+,16
lst #0,*+
lst #1,*+
clrc INTM
ret
* END Context Restore and Return *
***************
* Virtual Menu
***************
menu
.if virtual_menu ;如果virtual_menu为真(virtual_menuzai在前面已经设置为1),就汇编下面代码。
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available ?
bcnd menu,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0ffh ;only 8 bits !!!
ldp #option ;if yes, get it and store it in option
sacl option ;now in option we have the option number
;of the virtual menu
sub #031h ;is it option 1 ?
bcnd notone,neq ;if not branch to notone
*****************************
* Option 1): Speed reference
*****************************
navail11
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail11,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail12
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail12,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl n_ref ;store it ;通过串口给定参考速度值
b menu ;return to the main polling cycle
*** END Option 1): speed reference
notone
lacc option
sub #032h ;is it option 2 ?
bcnd nottwo,neq ;if not branch to nottwo
*****************************
* Option 2): DAC update
*****************************
navail21
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail21,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #da1
sacl da1 ;if yes, get it and store it in da1
navail22
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail22,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #da1
sacl da2 ;if yes, get it and store it in da2
navail23
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail23,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #da1
sacl da3 ;if yes, get it and store it in da3
navail24
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail24,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #da1
sacl da4 ;if yes, get it and store it in da4
b menu ;return to the main polling cycle
*** END Option 2): DAC update
nottwo
lacc option
sub #033h ;is it option 3 ?
bcnd notthree,neq ;if not branch to notthree
*****************************
* Option 3): initphase
*****************************
navail31
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail31,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail32
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail32,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl initphase ;store it
b menu ;return to the main polling cycle
*** END Option 3): initphase
notthree
lacc option
sub #034h ;is it option 4 ?
bcnd notfour,neq ;if not branch to notfour
*****************************
* Option 4): vDCinvTc
*****************************
navail41
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail41,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail42
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail42,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl VDCinvT ;store it
b menu ;return to the main polling cycle
*** END Option 4): vDCinvTc
notfour
lacc option
sub #035h ;is it option 5 ?
bcnd notfive,neq ;if not branch to notfive
*****************************
* Option 5): Kpi, Ki, Kcor
*****************************
navail51
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail51,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail52
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail52,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Kpi ;store it
navail53
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail53,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail54
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail54,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Ki ;store it
navail55
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail55,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail56
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail56,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Kcor ;store it
b menu ;return to the main polling cycle
*** END Option
notfive
lacc option
sub #036h ;is it option 6 ?
bcnd notsix,neq ;if not branch to notsix
*****************************
* Option 6): Kpispeed , Kispeed , Kcorspeed
*****************************
navail61
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail61,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail62
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail62,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Kpispeed ;store it
navail63
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail63,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail64
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail64,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Kispeed ;store it
navail65
ldp #DP_PF1
bit SCIRXST,BIT6 ;is there any character available (8 LSB)?
bcnd navail65,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF
and #0FFh ;take the 8 LSB
ldp #serialtmp
sacl serialtmp ;if yes, get it and store it in serialtmp
navail66
ldp #DP_PF1
bit SCIRXST,BIT6 ;8 MSB available ?
bcnd navail66,ntc ;if not repeat the cycle (polling)
lacc SCIRXBUF,8 ;load ACC the upper byte
ldp #serialtmp
add serialtmp ;add ACC with lower byte
sacl Kcorspeed ;store it
b menu ;return to the main polling cycle
*** END Option
notsix
b menu
.else ;如果virtual_menu为假(也就是0),则不汇编.if后的代码,改为汇编.else后的代码。
ldp #n_ref
splk #1000h,n_ref ;直接给定速度参考值,不能通过串口给定了
lacc stall_timer1 ;cascaded timers to ensure correct stall
;at start
sub #1 ;when no Graphic User's Interface is available
sacl stall_timer1
bcnd norun,GT
lacc stall_timer2
sub #1
sacl stall_timer2
bcnd norun,GT
splk #01000h,initphase
splk #0,stall_timer1
splk #0,stall_timer2
b menu
norun
splk #0,initphase
b menu
.endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -