⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 com_trig.asm

📁 TI的digital motor control lib的源代码。了解TI的编程规范
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;=====================================================================================
; File name:        COM_TRIG.ASM                     
;                    
; Originator:	Digital Control Systems Group
;			Texas Instruments
;
; Description:                                 
; This file contains commutation trigger points generation routine.
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000	Release	Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx.  (Peripheral Independant).
;
;
;================================================================================
; Routine Name: Commutation trigger generator module     Routine Type: C Callable
;
; Description:
;        This module determines the Bemf zero crossing points                     
;        of a 3-phase BLDC motor and then generates the commutation                  
;        trigger points for the 3-phase power inverter switches.  
;  
;  C prototype : int cmtn_trig_calc( *p);
;================================================================================
; History     Created   July 22, 2000
;             
;
;==========================================================================
; Definition of CMTN:
;
;typedef  struct {
;  int trig;              
;  int va;                
;  int vb;                
;  int vc ;               
;  int zc_trig;           
;  int ptr_ct;            
;  int debug_Bemf;        
;  int noise_windowCntr;  
;  int d30_doneFlg;       
;  int time_stampNew;     
;  int time_stampOld;     
;  int v_timer;           
;  int delay;             
;  int dt_taskFlg ;       
;  int noise_windowMax;  
;  int delay_cntr;       
;  int cdnw_delta;       
;  int nw_dynThold;      
;  (int(*)(int))cmtn_trig_calc;
;} CMTN;
;================================================================================                 
;       Frame Usage Details:
;            |      a           
;____________|__________________________________
;       FR0  |                                  | 
;       FR1  |  1. neutral                      |
;            |  2. rev_period                   |
;            |  3. remainder                    |
;            |                                  |
;       FR2  |  GPR0_COM_TRIG.                  |
;================================================================================                       


;--------------------------------------------------------------------------------      
    .def    _cmtn_trig_calc
;--------------------------------------------------------------------------------          
CLEAR            .set 0000h    
CYCLE_LENGTH     .set 7FFFh 
GONE_THRO_ONCE   .set 0Fh


__CMTN_framesize .set 0003h

_cmtn_trig_calc:
;================================================================================  
               
                                ; AR0 is the frame pointer, AR1 is the stack 
                                ; pointer. ARP = AR1
                      
    POPD    *+                  ; Save the return address from hardware
                                ; stack onto the software stack
                                ; ARP = AR1
        
    SAR     AR0,*+              ; push AR0 (FP). ARP = AR1
        
    SAR     AR1,*               ; *SP = SP. ARP = AR1 .  
        
    LAR     AR0, #__CMTN_framesize
                                ; FP = size of frame. ARP = AR1
        
    LAR     AR0,*0+,AR2         ; Allocate frame. AR0 = *AR1
                                ; AR1 = AR1 + AR0. ARP = AR2

    LAR     AR2,#-3             ; AR2 = -3. ARP = AR2
   
    MAR     *0+                 ; AR2 -> passed parameter
                                ; (i.e. pointer to the structure).
                                ; ARP = AR2.  AR2 = AR0 - 3 
;================================================================================  
                                ; ARP = AR2.  AR2 -> structure pointer
                LAR     AR4,*   ; AR4 points to the first structure member
                                ; (i.e. AR4 -> trig). 
;--------------------------------------------------------------------------------        
                LAR     AR5,*   ; AR5 points to the first structure member
                                ; (i.e. AR5 -> trig). 
                                ; AR4-> trig.  AR2 -> structure pointer
                                ; ARP = AR2. 
;--------------------------------------------------------------------------------        
                LAR     AR3,*   ; ARP = AR2. AR2 -> structure pointer . 
                                ; AR3 points to the first structure member
                                ; (i.e. AR3 -> trig). AR4-> trig.
                                ; AR5 -> trig.  
;--------------------------------------------------------------------------------        
                LAR     AR2,#1  ; AR2 = 1. ARP = AR2. 
                                ; AR3 -> trig. AR4-> trig. AR5 -> trig. 
;--------------------------------------------------------------------------------        
                MAR     *0+,AR4 ; AR2 -> FR1
                                ; ARP = AR4. AR4 -> trig. AR3 -> trig.
                                ; AR5 -> trig.
;================================================================================  

;             Neutral  Voltage Calculation           
;--------------------------------------------------------------------------------                           
__CMTN_neu_calc:
                SETC    SXM     ; Sign extension mode ON
                                ; AR2 -> FR1. ARP = AR4. 
                                ; AR4 -> trig. AR3 -> trig.
                                ; AR5 -> trig.
;--------------------------------------------------------------------------------                           
                LACC    #CLEAR  ; Always clear flag on entry.
                                ; AR2 -> FR1. ARP = AR4. 
                                ; AR4 -> trig. AR3 -> trig.
                                ; AR5 -> trig.    
;-------------------------------------------------------------------------------- 
                SACL    *+      ; trig = 0.
                                ; ARP = AR4. AR4-> va. AR3-> trig
                                ; AR2-> FR1. AR5-> trig
;--------------------------------------------------------------------------------
                LACC    *+      ; Accumulator = va. 
                                ; ARP = AR4. AR4-> vb. AR5-> trig
                                ; AR3-> trig. AR2-> FR1.
;--------------------------------------------------------------------------------                
                ADD     *+      ; Accumulator = (va + vb).
                                ; ARP = AR4. AR4 -> vc. AR5-> trig
                                ; AR3-> trig. AR2-> FR1.
;--------------------------------------------------------------------------------                        
                ADD     *+, AR2 ; Accumulator = (va + vb + vc).
                                ; AR4 -> zc_trig.  AR3-> trig.
                                ; ARP = AR2. AR2 -> FR1 (neutral).
                                ; AR5-> trig. 
;--------------------------------------------------------------------------------                                         
                SACL    *+,AR4  ; neutral = (va + vb + vc) = 3*neutral voltage(Vn) 
                                ; AR2 -> FR2 (GPR0_COM_TRIG).
                                ; ARP = AR4. AR4 -> zc_trig. AR3-> trig.
                                ; AR5-> trig. 
;================================================================================  
               
            ; Commutation State Table Tasks

__CMTN_state_tasks:
                SPLK    #CLEAR,*+ 
                                ; zc_trig = 0 (Always clear the flag on entry).
                                ; ARP = AR4. AR4 -> ptr_ct. AR3-> trig.
                                ; AR5-> trig. AR2 -> FR2 (GPR0_COM_TRIG).
;-------------------------------------------------------------------------------- 
                LACC    *+,AR2  ; Accumulator = ptr_ct.
                                ; Points to state table
                                ; ARP = AR2. AR2 -> FR2(GPR0_COM_TRIG).
                                ; AR4 -> debug_Bemf. AR3-> trig.
                                ; AR5-> trig. 
;-------------------------------------------------------------------------------- 
                ADD  #_CMTN_STATE_TBL 
                                ; Accumulator = CMTN_STATE_TBL + ptr_ct.
                                ; ARP = AR2. AR2 -> FR2(GPR0_COM_TRIG).
                                ; AR4 -> debug_Bemf. AR3-> trig.
                                ; AR5-> trig. 
;-------------------------------------------------------------------------------- 
                TBLR    *       ; Tranfer of a word from program 
                                ; memory to data memory.
                                ; ARP = AR2. AR2 -> FR2(GPR0_COM_TRIG).
                                ; AR4 -> debug_Bemf. AR3 -> trig.
                                ; AR5-> trig. 
;-------------------------------------------------------------------------------- 
                LACC    *-,AR3  ; Accumulator = state address.
                                ; ARP = AR3. AR3 -> trig.  AR2 -> FR1(neutral).
                                ; AR5 -> trig. 
                                ; AR4 -> debug_Bemf.
;-------------------------------------------------------------------------------- 
                BACC            ; Branch to perform state task whose address
                                ; is in Accumulator.
                                ; ARP = AR3. AR3 -> trig.  AR2 -> FR1(neutral).
                                ; AR4 -> debug_Bemf. AR5-> trig.
;-------------------------------------------------------------------------------- 
            ; state 0 - ZC for phase C
            ; ARP = AR3. AR3 -> trig.  AR2 -> FR1(neutral). AR4 -> debug_Bemf.
            ; AR5-> trig. 

__CMTN_state_anb:
                
                ADRK    #3      ; AR3 -> vc. ARP = AR3. AR2 -> FR1(neutral). 
                                ; AR4 -> debug_Bemf. AR5-> trig. 
;-------------------------------------------------------------------------------- 
                LACC    *,1     ; Accumulator = (2 * vc).
                                ; ARP = AR3. AR3-> vc. AR2 -> FR1(neutral).
                                ; AR4 -> debug_Bemf. AR5-> trig. 
;-------------------------------------------------------------------------------- 
                ADD     *,AR2   ; Accumulator = (3 * vc)
                                ; neutral = 3 * neutral voltage (Vn)
                                ; ARP = AR2. AR2 -> FR1(neutral).
                                ; AR3 -> vc. AR4 -> debug_Bemf. AR5 -> trig. 
;-------------------------------------------------------------------------------- 
                SUB     * ,AR4  ; Accumulator = (3 * vc) - neutral = 3*Vc - 3*Vn.
                                ; ARP = AR4, AR4 -> debug_Bemf.
                                ; AR2 -> FR1(neutral). AR3 -> vc. AR5 -> trig.
                                ; AR0 -> FP. AR1 -> SP.
;-------------------------------------------------------------------------------- 
                SACL    *+      ; debug_Bemf = (3 * vc) - neutral = 3*Vc - 3*Vn.
                                ; ARP = AR4. AR4 -> noise_windowCntr. AR3-> vc.
                                ; AR5 -> trig. 
                                ; AR2 -> FR1(neutral).
;-------------------------------------------------------------------------------- 
                BCND     __CMTN_clr_nw_s0,GT
                                ; ARP = AR4. AR4 -> noise_windowCntr.
                                ; AR3 -> vc. AR5 -> trig. AR2 -> FR1(neutral).
;-------------------------------------------------------------------------------- 
                CALL    _Noise_Wind  
                                ; ARP = AR4. AR4 -> noise_windowCntr.
                                ; AR5 -> trig. AR3 -> vc. AR2 -> FR1(neutral).
;-------------------------------------------------------------------------------- 
                B       __CMTN_st_end;
                                ; ARP = AR4. AR4 -> noise_windowCntr.
                                ; AR5 -> trig. AR3 -> vc. AR2 -> FR1(neutral).
;-------------------------------------------------------------------------------- 
            ; ARP = AR4. AR4 -> noise_windowCntr.
            ; AR3 -> vc. AR5 -> trig. AR2 -> FR1(neutral).
                 
__CMTN_clr_nw_s0:
                
                SPLK    #CLEAR, *  
                                ; noise_windowCntr = 0.  
                                ; ARP =  AR4. AR4 ->  noise_windowCntr.
                                ; AR3 -> vc. AR5 -> trig. AR2 -> FR1(neutral).
;-------------------------------------------------------------------------------- 
                B     __CMTN_st_end
                                ; ARP =  AR4. AR4 ->  noise_windowCntr.
                                ; AR3 -> vc. AR5 -> trig. AR2 -> FR1(neutral).
;================================================================================
            
            ; state 1 - ZC for phase B
            ; ARP = AR3. AR3 -> trig.  AR2 -> FR1(neutral).                                
            ;  AR4 -> debug_Bemf. AR5-> trig.

__CMTN_state_anc:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -