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

📄 mod6_cnt.asm

📁 TI的digital motor control lib的源代码。了解TI的编程规范
💻 ASM
字号:
;=====================================================================================
; File name:        MOD6_CNT.asm                     
;                    
; Originator:	Digital Control Systems Group
;			Texas Instruments
;
; Description:                                 
; This file contains source for the Modulo 6 counter  routine.
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000	Release	Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx.  (Peripheral Independant).
;
;
;================================================================================
; Routine Name: MOD6_CNT           Routine Type: C Callable
;
; Description:
;  
; C prototype : void  mod6cnt_calc(MOD6CNT *p)
;================================================================================
; History     Created  July 26,2000
;
; Definition of MOD6CNT:
;
; typedef struct MOD6CNT{                          
;                      int trig_in;     
;                      int cntr;        
;                      (int (*) (int))mod6cnt_calc
;                      };
;================================================================================

ON         .set 1
OFF        .set 0  
;--------------------------------------------------------------------------
RETURN_ADDRESS_SAVE .set ON     ; If this function calls no other functions 
                                ; set RETURN_ADDRESS_SAVE to OFF for
                                ; optimization                                
;--------------------------------------------------------------------------
MAX_STATES .set 5
CLEAR      .set 0 
;--------------------------------------------------------------------------
            .def _mod6cnt_calc
;================================================================================
_mod6cnt_calc:   

__mod6cnt_calc_framesize .set 0001h
;--------------------------------------------------------------------------
    .if ( RETURN_ADDRESS_SAVE = ON)  
                                ; AR1 is the  stack pointer (SP)
                                ; AR0 is the  frame pointer (FP)
                                
    POPD *+                     ; Save the return address from hardware
                                ; stack onto the software stack. ARP = AR1
    
    .endif

    SAR  AR0, *+                ; push AR0 (FP). ARP = AR1
    SAR  AR1, *                 ; *SP = SP. ARP = AR1
    LAR  AR0, #__mod6cnt_calc_framesize 
                                ; FP = size of frame. ARP = AR1
    
    LAR  AR0, *0+, AR2          ; Allocate frame. AR0 = *AR1
                                ; AR1 = AR1 + AR0. ARP = AR2
;================================================================================
                .if (RETURN_ADDRESS_SAVE = ON) 
                LAR AR2,  #-3 
                .endif                     
                
                .if (RETURN_ADDRESS_SAVE = OFF) 
                LAR AR2,  #-2 
                .endif          
;--------------------------------------------------------------------------
                MAR *0+         ; AR2 = AR2 + AR0
                                ; AR2 -> passed parameter
                                ; (i.e. pointer to the structure).
                                ; ARP = AR2.
;--------------------------------------------------------------------------
                LAR     AR2, *,AR2 
                                ; AR2 points to the first member of the
                                ; structure (i.e. AR2 -> trig_in) 
                                ; ARP = AR2.  
;--------------------------------------------------------------------------
                LACC    *+      ; Load Accumulator with trig_in 
                                ; and increment AR2
                                ; ARP = AR2. AR2-> cntr. 
;--------------------------------------------------------------------------
                BCND    __mod6cnt_calc_exit , EQ 
                                ; If trig_in is equal to zero goto
                                ; __mod6cnt_calc_exit
                                ; ARP = AR2. AR2-> cntr 
;--------------------------------------------------------------------------
                LACC    *       ; Load Accumulator with counter 
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                        
                SUB     #MAX_STATES
                                ; To check if counter is 5
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                        
                BCND    __MOD6CNT_Inc_Cntr, LT 
                                ; If counter is less than 5 goto
                                ; __MOD6CNT_Inc_Cntr
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                                
__MOD6CNT_Clear_Cntr:
                                     
                SPLK    #CLEAR, *
                                ; If yes, load 0 to clear the counter 
                                ; i.e Reset state pointer to 0
                                ; ARP = AR2.  AR2-> cntr  
;--------------------------------------------------------------------------                                                        
                B       __mod6cnt_calc_exit 
                                ; If counter is equal to zero goto
                                ; __mod6cnt_calc_exit 
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                        
__MOD6CNT_Inc_Cntr:

                LACC    *       ; Get the counter
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                        
                ADD     #1      ; To increment the counter
                                ; ARP = AR2.  AR2-> cntr 
;--------------------------------------------------------------------------                                                        
                SACL    *       ; Update counter 
                                ; i.e Increment commutation_ptr
                                ; ARP = AR2. AR2-> cntr 
;================================================================================
    ; Retrieve FP and SP of parent function
    
__mod6cnt_calc_exit:  
    MAR     *, AR1              ; set ARP = SP before you exit.
    SBRK    #(__mod6cnt_calc_framesize+1) 
                                ; Deallocate frame, point to saved FP
        
    .if (RETURN_ADDRESS_SAVE = ON)
    LAR     AR0, *-             ; Restore frame pointer
    PSHD    *                   ; Push return address on hardware stack
    .endif
        
    .if (RETURN_ADDRESS_SAVE = OFF)
    LAR     AR0, *              ; Restore frame pointer
    .endif
    
    RET
   
    .end

⌨️ 快捷键说明

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