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

📄 example1.dsp

📁 pwm out demo
💻 DSP
字号:
.MODULE/RAM/SEG=USER_PM1/ABS=0x30      example1;

{    
   Revision History:

   Rev 1.0 : (i)  Now write 0x000 to ICNTL to enable level
		  sensitive interrupts to ensure no lost
		  interrupts.
	     (ii) Remove reading of IRQFLAG and PIOFLAG
		  registers at end of interrupt service
		  routine - not needed with level interrupts.
   Rev 2.0 : (i)  Ported to ADMCF32X, change to include F32X .h files
             (ii) Must now write to PWMTM, PWMCHA, PWMCHB, and PWMCHC
                  during initialization to start PWMSYNC.
}

{   Demo program for the ADMCF32X Evaluation Board.
   
   This demo initializes the PWM and interrupts
   of the ADMCF32X. Both the PWMSYNC and PWMTRIP
   interrupts are enabled in software.

   This example file sets up the interrupt vector
   table with calls to the interrupt service 
   routines (ISR) for these two interrupts.  
   
   In this example the ISR for PWMSYNC simply
   writes constant duty cycle values to the
   three PWM registers.

   The ISR for the PWMTRIP does nothing.

}

{ Include file with ADMCF32X specific constant definitions }

#include <admcf32X.h>;

{      Subroutines defined in other modules           }

.EXTERNAL PUT_VECTOR;

{ Program constant definitions                            }

.CONST  period     = 0x3e8;    {10 kHz switching frequency      } 
.CONST  deadtime   = 0x00a;    {Dead time of 1 us               }   
.CONST  pulsedel   = 0x00f;    {Pulse deletion time of 1.5 us   }
.CONST  seg_value  = 0x000;    {Enable all PWM outputs          }
.CONST  gate_value = 0x204;    {Enable low-side chopping at 1MHz}
.CONST  pwmA_init  = 0x0104;   {25% duty cycle}
.CONST  pwmB_init  = 0x01fe;   {50% duty cycle}
.CONST  pwmC_init  = 0x02f8;   {75% duty cycle}
 
{ Program variable defintions                            }

.VAR/DM/RAM/SEG=USER_DM  pwmA_value;
.VAR/DM/RAM/SEG=USER_DM  pwmB_value;
.VAR/DM/RAM/SEG=USER_DM  pwmC_value;

{ MACRO definitions                                     }
{ MACRO used to initialize locations in data memory     }

.MACRO init_dm_scalar(%0,%1);
    ax0=%1; dm(%0)=ax0;
.ENDMACRO;

{ Initialization Code }

STARTUP:
      
        CALL INIT_PWM;   {Initialize PWM registers and ISRs }

                         {Enable only IRQ2 (Peripheral) int }
	IFC = 0x80;      {Clear any pending IRQ2 interrupt  }
	ICNTL = 0x00;    {Configure interrupt format        }
	AY0 = 0x200;     {Enable IRQ2. interrupt}    
	AR = IMASK;
	AR = AR OR AY0;
	IMASK = AR;        
	
MAINLOOP:		 {Dummy main loop - simply waits   }
         nop;            {for interrupts to occur          }
         nop;
         jump MAINLOOP;
        	
INIT_PWM:      
	init_dm_scalar(PWMTM,   period);
    init_dm_scalar(PWMDT,   deadtime);
    init_dm_scalar(PWMPD,   pulsedel);
    init_dm_scalar(PWMSEG,  seg_value);
    init_dm_scalar(PWMGATE, gate_value);
    init_dm_scalar(PWMCHA,  pwmA_init);
    init_dm_scalar(PWMCHB,  pwmB_init);
    init_dm_scalar(PWMCHC,  pwmC_init);
		
	init_dm_scalar(pwmA_value, pwmA_init);
	init_dm_scalar(pwmB_value, pwmB_init);
	init_dm_scalar(pwmC_value, pwmC_init);

	I4 = PWMSYNC_INT_ADDR;       {Initialize jump to PWMSYNC ISR}
	MR0 = ^PWMSYNC_ISR;          {Vector address in I4          }
	CALL PUT_VECTOR;	     {Start address of ISR in MR0   }
   
        I4 = PWMTRIP_INT_ADDR;       {Initialize jump to PWMTRIP ISR}
        MR0 = ^PWMTRIP_ISR;          {Vector address in I4          }
        CALL PUT_VECTOR;             {Start address of ISR in MR0   }

	AY0 = 0x000C;                {Enable PWMSYNC & PWMTRIP      }
	AR = DM(MODECTRL);           {interrupts from MODECTRL      }
	AR = AR OR AY0;       	     {of ADMC330. Preserve other    }
	DM(MODECTRL) = AR;           {bits of MODECTRL by ORing     }

	RTS;

PWMSYNC_ISR:

{ On occurance of PWMSYNC interrupt write to three PWM registers   }

         nop;
         nop;
  
	 ax0 = dm(pwmA_value);
         dm(PWMCHA) = ax0;
	 ax0 = dm(pwmB_value);
         dm(PWMCHB) = ax0;
	 ax0 = dm(pwmC_value);
         dm(PWMCHC) = ax0;

	 
         RTI;

PWMTRIP_ISR:   
 
{ On occurance of PWMTRIP interrupt do nothing                     }
       
        nop;
        nop;
	RTI;

.ENDMOD;

⌨️ 快捷键说明

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