DSP

TMS320C54XDSP与直流伺服电机定速控制实验代码

2019-07-13 17:13发布

TMS320C54XDSP与直流伺服电机定速控制实验代码 这是用CCS编写的DSP汇编程序,可以实现TMS320C54XXDSP与直流伺服电机定速控制实验

************************************************
* FileName: ex9.asm            *
* Description:
直流伺服电机定速控制实验    *
* Copyright(C) SanZhi Electronic, Author Zpin *
************************************************


.title "ex9"
.global _c_int00
.mmregs

DJ_ADDR .set 0b007h

VOL_POS .SET 0100H
VOL_NEG .SET 0200H
VOL_Z .SET 0000H


DIRECT .set 61h
RATIO_Z .set 62h
RATIO_K .set 63h

DJ_VOL .set 64h
DJ_STATUS .set 65h

.sect ".vectors"
reset: B _c_int00
NOP
NOP
.space 4*127


.text
_c_int00:
LD #0h,DP
STM #3000h,SP
SSBX INTM
RSBX SXM
STM #07FFFh,SWWSR
stm #0001h,2Bh

ST #0h,CLKMD
tst BITF CLKMD,#1h
BC tst,TC
ST #1087h,CLKMD  ;
工作在20MHz
RPT #0FFh
NOP

ST #3h,DJ_STATUS  ;
状态4

read  LD #fo_s0,B
    ADD DJ_STATUS,3,B,B  ;
判断状态
BACC B

fo_s0 ST #1h,DIRECT  ;
状态0:低速正转
ST #07h,RATIO_Z
ST #73h,RATIO_K
B dj_ctrl

fo_s1 ST #1h,DIRECT  ;
状态1:中速正转
ST #10h,RATIO_Z
ST #70h,RATIO_K
B dj_ctrl

fo_s2 ST #1h,DIRECT  ;
状态2:高速正转
ST #20h,RATIO_Z
ST #60h,RATIO_K
B dj_ctrl

fo_s3 ST #1h,DIRECT  ;
状态3:全速正转
ST #80h,RATIO_Z
ST #0h,RATIO_K
B dj_ctrl

bk_s0 ST #2h,DIRECT  ;
状态4:低速反转
ST #73h,RATIO_Z
ST #07h,RATIO_K
B dj_ctrl

bk_s1 ST #2h,DIRECT  ;
状态5:中速反转
ST #70h,RATIO_Z
ST #10h,RATIO_K
B dj_ctrl

bk_s2 ST #2h,DIRECT  ;
状态6:高速反转
ST #60h,RATIO_Z
ST #20h,RATIO_K
B dj_ctrl

bk_s3 ST #2h,DIRECT  ;
状态7:全速反转
ST #0h,RATIO_Z
ST #80h,RATIO_K


dj_ctrl BITF DIRECT,#1h  ;
判断方向
BC pos,TC

ST #VOL_Z,DJ_VOL  ;(
反转)输出零电平
PORTW DJ_VOL,DJ_ADDR
B de1

pos ST #VOL_POS,DJ_VOL  ;(
正转)输出正电平
PORTW DJ_VOL,DJ_ADDR

de1 LD RATIO_Z,A        ;
延时
STLM A,AR6
CALL delay

BITF DIRECT,#2h  ;
判断方向
BC neg,TC

ST #VOL_Z,DJ_VOL  ;(
正转)输出零电平
PORTW DJ_VOL,DJ_ADDR
B de2

neg ST #VOL_NEG,DJ_VOL  ;(
反转)输出负电平
PORTW DJ_VOL,DJ_ADDR

de2 LD RATIO_K,A  ;
延时
STLM A,AR6
CALL delay

B read   ;
继续读取状态


delay nop
nop
ST #01A0h,AR7  ;
延时子程序
nop
nop
BANZ $,*AR7-
nop
nop
BANZ delay,*AR6-  ;AR6
决定延时长短
nop
nop
nop
RET