📄 3_vf_main.asm
字号:
;***********************************************************************
; 软件名称: DSP控制的高性能变频调速系统(下位机源代码)
; 时间:18/04/04
; 版权所有:浙江天煌科技实业有限公司技术开发部
; 程序说明: 该程序是采用TMS320F240 DSP控制的三相异步电机变频调速.控制方式共有三种:分别为
; 正弦波脉宽调制(SPWM).马鞍波调制(VVPWM).空间矢量调制(SVPWM).
; Originator: jzming
; Description: this program use spwm & vvpwm & svpwm to contol the three-phase asm-motor.
; Control mode: v/f control ,pwm frequency:20khz
; The program include serial communications and be run in hardware.
; The system uses the key to control the speed:
; IOPB3---->"MODE";IOPB4---->"START"; IOPB5---->"STOP"; IOPB6---->"+";IOPB7---->"-".
; Int resource: sine & t1upf
;***********************************************************************
;------------------ public initialization ------------------------------
count .usect ".blk0",1 ;read the key number which pressed
count1 .usect ".blk0",1 ;temp register
count2 .usect ".blk0",1 ;temp register
yjax_flag .usect ".blk0",1 ;set the yjax flag
count_h .usect ".blk0",1 ;high num of the led (dec)
count_l .usect ".blk0",1 ;low num of the led (dec)
count_hl .usect ".blk0",1 ;V/F control register
option .usect ".blk0",1
start_key .usect ".blk0",1
comm_flag .usect ".blk0",1 ;the serial_comm control flag
add_var .usect ".blk0",1 ;the add variables(use to serial_comm)
sub_var .usect ".blk0",1 ;the substruct variables(use to serial_comm)
add_var_h .usect ".blk0",1
add_var_l .usect ".blk0",1
add_temp .usect ".blk0",1
add_cen .usect ".blk0",1
add_pn .usect ".blk0",1
dpbc_var .usect ".blk0",1
tx_count .usect ".blk0",1
tx_count1 .usect ".blk0",1
tx_count2 .usect ".blk0",1
LED0_LED1 .usect ".blk0",1
LED0 .usect ".blk0",1 ;display (lowest bits)
LED1 .usect ".blk0",1
LED2 .usect ".blk0",1
LED3 .usect ".blk0",1
TEMP .usect ".blk0",1 ;temporary register
*-----------------------------------------------------------------------
************************************************************************
;----------------- vf_spwm & vv_pwm initialization ---------------------
table .usect ".blk0",1
toptable .usect ".blk0",1
comparet1 .usect ".blk0",1
freqstep .usect ".blk0",1
vf_freq .usect ".blk0",1
ad_res_0 .usect ".blk0",1
ad_res_1 .usect ".blk0",1
p_counter .usect ".blk0",1
modreg .usect ".blk0",1
sineval .usect ".blk0",1
b_sadd .usect ".blk0",1
c_sadd .usect ".blk0",1
vf_cap .usect ".blk0",1
vf_cen .usect ".blk0",1
vf_cmp1 .usect ".blk0",1
vf_cmp2 .usect ".blk0",1
vf_cmp3 .usect ".blk0",1
vf_spwm_sel .usect ".blk0",1
vf_spwm_varl .usect ".blk0",1
vf_spwm_varh .usect ".blk0",1
vf_spwm_var .usect ".blk0",1
vf_spwm_cofi .usect ".blk0",1
vf_spwm_num .usect ".blk0",1
vf_spwm_count .usect ".blk0",1
cmpr1var .usect ".blk0",1
cmpr2var .usect ".blk0",1
cmpr3var .usect ".blk0",1
spwm_r_flag .usect ".blk0",1
t1compare .set 0
t1period .set 500
normal .set 250
b_phase .set 170
c_phase .set 85
************************************************************************
;---------------- vf_svpwm initialization -------------------------------
temp .usect ".blk0",1
set_f .usect ".blk0",1 ; set F: D0 (-1.0-1.0, 1.0-120Hz)
f_omega .usect ".blk0",1 ; set F to angular speed ratio: D10
omega .usect ".blk0",1 ; set angular speed: D10
omega_v .usect ".blk0",1 ; angular speed to voltage ratio:D-9
min_v .usect ".blk0",1
set_v .usect ".blk0",1 ; set voltage: D1
t_sample .usect ".blk0",1 ; sampling period: D-9
theta_h .usect ".blk0",1 ; phase of ref vector hi word: D3
theta_l .usect ".blk0",1 ; theta lo word
theta_r .usect ".blk0",1 ; rounded theta_h: D3
theta_m .usect ".blk0",1 ; theta mapped to 1st quadrant: D3
theta_i .usect ".blk0",1 ; theta to index for sine table: D6
SS .usect ".blk0",1 ; sin sign modification: D15
SC .usect ".blk0",1 ; cos sign modification: D15
sin_indx .usect ".blk0",1 ; index to sine table: D15
sin_entry .usect ".blk0",1 ; beginning of sin table
sin_end .usect ".blk0",1 ; end of sin table
sin_theta .usect ".blk0",1 ; sin(theta): D1
cos_theta .usect ".blk0",1 ; cos(theta): D1
Ud .usect ".blk0",1 ; voltage Ud: D2
Uq .usect ".blk0",1 ; voltage Uq: D2
theta_s .usect ".blk0",1 ; theta to sector mapping: D0
sector .usect ".blk0",1 ; sector reference U is in: D15
theta_90 .usect ".blk0",1 ; 90: D3
theta_180 .usect ".blk0",1 ; 180: D3
theta_270 .usect ".blk0",1 ; 270: D3
theta_360 .usect ".blk0",1 ; 360: D3
dec_ms .usect ".blk0",24 ; Decomposition matrices: D1
t1_periods .usect ".blk0",1 ; scaled Timer 1 period: D10
cmp_1 .usect ".blk0",1 ; decomp on 1st basic sp vector: D15
cmp_2 .usect ".blk0",1 ; decomp on 2nd basic sp vector: D15
cmp_0 .usect ".blk0",1 ; decomp on 0 basic sp vector /2: D15
first_tog .usect ".blk0",1 ; the 1st-to-toggle channel
sec_tog .usect ".blk0",1 ; the 2nd-to-toggle channel
svpat .usect ".blk0",1 ; S/V pattern for ACTR
svdpbc_var .usect ".blk0",1
svpwm_r_flag .usect ".blk0",1
first_var .usect ".blk0",1
second_var .usect ".blk0",1
svpwm_cenvarl .usect ".blk0",1
svpwm_cenvarh .usect ".blk0",1
vf_svpwm_cofi .usect ".blk0",1
vf_svpwm_num .usect ".blk0",1
vf_svpwm_sel .usect ".blk0",1
vf_svpwm_var .usect ".blk0",1
; Program parameters
;-------------------------------------------------------------------
debug_data .set 3fffh ; 60Hz-3FFF, 30Hz-1FFF, 25Hz-1AAB
; Scaled sampling period
; Ts*D-9=Ts*2**24, Ts=50uS
t_sample_ .set 0346h ; D-9
; Set frequency to radian frequency conversion ratio
; 120*2*pi/7FFFh/D0 = 754.0052472756
; 7FFFh corresponds to 120Hz=753.9822368616 rad/sec
f_omega_ .set 24128 ; D10
; Minimum radian frequency
; min_F*2*pi*D10=12*2*pi*D10=75.39822368616*D10
; min_F=12Hz is the minimum frequency input, D10=2**5
;min_omega_ .set 2413 ; D10
min_omega_ .set 0 ; D10
; Radian frequency to ref voltage conversion ratio -> V/Hz constant
; 1.0/sqrt(2)/(60*2*pi)*D24 = 0.001875658991994*D24
omega_v_ .set 31468 ; D-9
;omega_v_ .set 44496 ; D-9
; Max magnitude of reference voltage
; 1.0/sqrt(2)*D1 = 0.7071067811865*D1
max_v_ .set 11585 ; D1. 1b less res to reduce # shiftingsa
;max_v_ .set 5792
; Min magnitude of reference voltage given by
; 1.0/sqrt(2)* *D1 = 0.1414213562373*D1
;min_v_ .set 2317 ; D1
min_v_ .set 1158 ; D1
;min_v_ .set 0 ; D1
; Conversion from theta to index for sine table
; 360/(0.5pi)*D8, D8=2**(15-8)=2**7 ; 360 entry sine table
; theta_i_ .set 29335 ; D8
; 90/(0.5pi)*D6, D6=2**9 ; 90 entry sine table
theta_i_ .set 29335 ; D6
; Conversion from theta to sector
; 6/(2*pi)*D0, D0=2**(15-0)
theta_s_ .set 31291 ; D0
; No of cycles needed to qualify a button push
but_qual_ .set 60 ; 20*t_sample
t1_period_ .set 500 ; Tpwm/50nS/2=50uS/50nS/2=500
t1_periods_ .set 500*32 ; D10, scaled Timer 1 period
t2_period_ .set 1000 ;
************************************************************************
; Context
;-----------------------------------------------------------------------
ST0 .set 0
ST1 .set 1
ST0_save .set 060h ; saved status register ST0
ST1_save .set 061h ; saved status register ST1
ACCH .set 062h ; saved accumulator high
ACCL .set 063h ; saved accumulator low
AR0_save .set 064h ; saved AR0 content
AR1_save .set 065h ; saved AR1 content
P_hi .set 066h ; saved P high byte
P_lo .set 067h ; saved P low byte
T_save .set 068h ; saved T content
.bss GPR0,1 ;General purpose register.
;-----------------------------------------------------------------------
.global _c_int0,
.ref sys_int
.def int2_isr,PHANTOM
.include "x24x.h"
;=======================================================================
; M A I N _ C O D E - starts here
;=======================================================================
.text
_c_int0:
LDP #00E0h
SPLK #006Fh, WDCR ;disable watchdog w/max. overflow
KICK_DOG ;Reset watchdog counter
call sys_int
call serial_int
;----------------------------------------------------------------------
comm_ini ;decide if serial_comm control?
ldp #04h
lacl comm_flag
sub #01h
bcnd comm_loop,neq
B key_control
;----------------------------------------------------------------------
key_control1
call sys_int
key_control: ;键盘控制
LDP #0H
SPLK #0h,IMR ;Mask all Ints
SPLK #0FFh,IFR ;Clear all Int Flags
LDP #0E8H
SPLK #0H,ACTR
LDP #0E0H
BIT SCIRXST, 9 ; test RXRDY bit
BCND key_scan, NTC ; if RXRDY NEQ 1, loop back on input
LACL SCIRXBUF ; else, load ACCL with character received
AND #00FFh ; mask unsignificant bits in ACC
sub #7fh
bcnd key_scan,neq
call _co ; Send the same value to the PC
LDP #0E0H
add #7fh
and #00FFh
SACL SCITXBUF
b comm_loop
key_scan
ldp #0e1h
lacc PBDATDIR
cmpl
and #0ffh
ldp #04h
sacl tx_count
lacl tx_count
lar ar0,tx_count
bcnd key_press?,neq
b key_control
key_press? ;back wobble
call delay_time
call delay_time
ldp #0e1h
lacc PBDATDIR
cmpl
and #0ffh
ldp #04h
sacl tx_count1
lacc tx_count1
lar ar1,tx_count1
bcnd key_pressed,neq
b key_control
key_pressed
;
ldp #04h
mar *,AR1
cmpr 00
bcnd key_control,ntc
sar ar0,tx_count2
ldp #04h ;decide if "start" key?
lacl tx_count2
sub #10h
bcnd not_startkey,neq ;no?
b mode_select
not_startkey
ldp #04h
lacl tx_count2
sub #04h
bcnd key_control,neq
key_contr
call yanshi
ldp #04h
lacl LED3
sub #03h
bcnd key_next,lt
splk #01h,LED3
setc intm
call DIS
clrc intm
b key_control
key_next
ldp #04h
lacl LED3
add #1
sacl LED3
setc intm
call DIS
clrc intm
b key_control
mode_select
ldp #04h
lacl LED3
sub #01h
bcnd mode2,neq
call _co ;send #1fh to the PC
lacl #1fh
SACL SCITXBUF
b vf_spwm
mode2
lacl LED3
sub #02h
bcnd mode3,neq
call _co ;send #01h to the PC
lacl #2fh
SACL SCITXBUF
b vf_vvpwm
mode3
call _co ;send #01h to the PC
lacl #3fh
SACL SCITXBUF
b vf_svpwm
vf_spwm
call spwm_ini_pwm
call spwm_main
call spwm_start
ldp #04h
splk #stable,toptable
clrc intm
b main_loop
;----------------------------------------------------------------------------------
vf_vvpwm
call spwm_ini_pwm
call spwm_main
call spwm_start
ldp #04h
splk #vvpwm_stable,toptable
clrc intm
b main_loop
;----------------------------------------------------------------------------------
vf_svpwm
call svpwm_ini_pwm
call svpwm_varies_ini
call svpwm_start
clrc intm
b main_loop
;----------------------------------------------------------------------------------
main_loop
turn_on ;"start" key
ldp #04H
SPLK #0H,LED0
SPLK #0H,LED1
SETC INTM
CALL DIS
CLRC INTM
turn1
ldp #04h
splk #00h,yjax_flag ;clear the yjax_flag
nop
call jpan ;call the jpan sub_program
lacc yjax_flag ;decide if some key pressed
sub #01h
bcnd other_key,eq ;yes
KICK_DOG
b turn1
other_key
ldp #04h
lacc count
sub #40h ;"+" key?
bcnd up_butn,eq
lacc count
sub #20h ;"-" key
bcnd dn_butn,eq
lacc count
sub #08h ;"stop" key
bcnd cut_off,eq
b turn1
up_butn ;"+" button-->IOPB6
ldp #04h
lacc count_h ;dicide if the count_h'number equal 6
sub #6
bcnd led_max,eq ;yes,jump led_max
lacc count_l
sub #9
bcnd led_jinwei,eq
add #9
sacl count_l
LACC count_l ; count_l +1
ADD #1
SACL count_l
b xunhuan
led_jinwei ;if count_l=9,then led_jinwei
ldp #04h
splk #0,count_l
lacc count_h ;increase the count_h
add #1
sacl count_h
lacc count_h
sub #6
bcnd led_max,eq ;if=6,then led_max
add #6 ;restore
sacl count_h
b xunhuan
led_max ;the maxim desplayed(60)
ldp #04h
splk #0,count_l
splk #6,count_h
b xunhuan
dn_butn ;decrease button:IOPB7
ldp #04h
lacc count_l
bcnd dn_next1,eq ;decide if it's "00"
b dn_next2
dn_next1
lacc count_h
bcnd led_min,eq
dn_next2 ;jiewei
lacc count_l
bcnd led_jiewei,eq
sub #1
sacl count_l
b xunhuan
led_jiewei
ldp #04h
splk #9,count_l
lacc count_h
sub #1
sacl count_h
b xunhuan
led_min ;the minimum displayed
ldp #04h
splk #0,count_l
splk #0,count_h
b xunhuan
cut_off
call _co ;Send the #0FFh to PC,then return the ini configure
lacl #0ffh
SACL SCITXBUF
ldp #04h
SPLK #0FH,LED0
SPLK #0FH,LED1
SPLK #0FH,LED2
SPLK #01H,LED3
splk #0,count_h
splk #0,count_l
SETC INTM
CALL DIS
CLRC INTM
b key_control
xunhuan ;displayed based on led_table
ldp #04h
lacc count_h
and #0fh
SACL LED1
lacc count_l
and #0fh
SACL LED0
SETC INTM
CALL DIS
call _co ;Send the display value to the PC
ldp #04h
LACC LED1,4
OR LED0
LDP #0E0H
SACL SCITXBUF
CLRC INTM
sfjx
LDP #0E0H
SPLK #006FH,WDCR
KICK_DOG ;delay intervel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -