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

📄 back main.txt.txt

📁 利用ccs环境、MATLAB环境、DSP(TMS320F2812)、被测对象和Agilient网络分析仪E5071B
💻 TXT
字号:










//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE:	DSP28_EvPwm.c
//
// TITLE:	DSP28 Event Manager PWM Generation.
//
// ASSUMPTIONS:
//
//          This program requires the DSP28 header files.  To compile the
//          program as is, it should reside in the DSP28/examples/ev_pwm 
//          sub-directory.
//
//          As supplied, this project is configured for "boot to H0" operation.  
//
// DESCRIPTION:
//
//          This program sets up the EV timers (TIMER1, TIMER2, TIMER3 and TIMER4) 
//          to generate T1PWM, T2PWM, T3PWM, T4PWM and PWM1-12 waveforms.  
//          The user can then observe the waveforms using an scope.  
//          
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.58| 19 Jul 2002 | L.H. | First Release
//###########################################################################

// Step 0.  Include required header files
         // DSP28_Device.h: device specific definitions #include statements for
         // all of the peripheral .h definition files.
         // DSP28_Example.h is specific for the given example.  

//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE:	Example_28xGpio.c
//
// TITLE:	DSP28 Device GPIO test porgram. 
//		All the GPIO PORT pins IOs will toggle forever in an indefinite
//		loop
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.56| 06 May 2002 | S.S. | EzDSP Alpha Release
//  0.57| 27 May 2002 | L.H. | No change
//###########################################################################
#include "DSP28_Device.h"

void main(void)
{
	int i;
	unsigned int temp;
   EALLOW;
   
// On TMX samples, to get the best performance of on chip RAM blocks M0/M1/L0/L1/H0 internal
// control registers bit have to be enabled. The bits are in Device emulation registers.
   DevEmuRegs.M0RAMDFT = 0x0300;
   DevEmuRegs.M1RAMDFT = 0x0300;
   DevEmuRegs.L0RAMDFT = 0x0300;
   DevEmuRegs.L1RAMDFT = 0x0300;
   DevEmuRegs.H0RAMDFT = 0x0300;
   
           
// Disable watchdog module
   SysCtrlRegs.WDCR= 0x0068;

// Initalize PLL
   SysCtrlRegs.PLLCR = 0xA;
   // Wait for PLL to lock
   for(i= 0; i< 5000; i++){}
       
// HISPCP/LOSPCP prescale register settings, normally it will be set to default values
   SysCtrlRegs.HISPCP.all = 0x0001;
   SysCtrlRegs.LOSPCP.all = 0x0002;	
// Peripheral clock enables set for the selected peripherals.   
   SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
   SysCtrlRegs.PCLKCR.bit.EVBENCLK=1;
   SysCtrlRegs.PCLKCR.bit.SCIENCLKA=1;
   SysCtrlRegs.PCLKCR.bit.SCIENCLKB=1;
   SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=1;
   SysCtrlRegs.PCLKCR.bit.SPIENCLK=1;
   SysCtrlRegs.PCLKCR.bit.ECANENCLK=1;
   SysCtrlRegs.PCLKCR.bit.ADCENCLK=1;				
   

// 初始化 GPIO
	GpioMuxRegs.GPAMUX.all=0xffff; // 配置端口A,作为PWM clock和GPIO
	GpioMuxRegs.GPADIR.all=0xffff;
	GpioMuxRegs.GPAQUAL.all=0x0000;
	GpioMuxRegs.GPEMUX.all=0x0003; // 配置端口E为外部中断XINT1,XINT2
	GpioMuxRegs.GPEDIR.all=0x0003;
	GpioMuxRegs.GPEQUAL.all=0x0000;
	GpioMuxRegs.GPFMUX.all=0x0000; 
	GpioMuxRegs.GPFDIR.all=0x0005;
	EDIS;

// GPIO CONFIGURE OK


//	GpioDataRegs.GPFCLEAR.all=0x0001;
//	asm("RPT #200||NOP");
//	GpioDataRegs.GPFSET.all=0x0001;

	DINT;
	IER=0x0000;
	IFR=0x0000;
 
	InitPieCtrl();
	InitPieVectTable();
// 允许外设中断,触发方式为负边沿
 	XIntruptRegs.XINT1CR.all=0x0001;
	XIntruptRegs.XINT2CR.all=0x0001;

	PieCtrl.PIEIER1.bit.INTx3=1;
	PieCtrl.PIEIER1.bit.INTx4=1;
	IER|=0x0001;

	EINT;

// GENERATE SQUARE SIGNAL
	//step1, 初始化定时器,初始化EVA Timer1
	EvaRegs.T1PR=0x000e;	 // Timer1 period
	EvaRegs.T1CMPR=0x0008;	 // Timer1 compare
	EvaRegs.T1CNT=0x0000;	//Timer1 counter
	EvaRegs.T1CON.all=0x9042; 

	//step2,建立T1PWM 和 T2PWM 有比较逻辑驱动T1/T2 PWM
	EvaRegs.GPTCONA.all=0x0000;
	EvaRegs.GPTCONA.bit.T2PIN=2;

	//step3 使能PWM1-PWM6 的比较器
	EvaRegs.CMPR1=0x0008;
	EvaRegs.ACTR.all=0x000a;
	EvaRegs.DBTCONA.all=0x0000;  // 禁止死区设置

	EvaRegs.COMCONA.bit.FCOMPOE=1;
	EvaRegs.COMCONA.bit.CENABLE=1;
	EvbRegs.ACTRB.all=0x0006;
	EvbRegs.DBTCONB.all=0x0000;
	EvbRegs.COMCONB.all=0xA600;

	for(;;)
	{



	};
	
}


/*
#include "DSP28_Device.h"


// Prototype statements for functions found within this file.

// Global counts used in this example


void main(void)
{

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
    // This function is found in the DSP28_SysCtrl.c file.
	InitSysCtrl();

// Step 2. Select GPIO for the device or for the specific application:
    // This function is found in the DSP28_Gpio.c file.
	// InitGpio();  // Skip for this test
	// Initalize GPIO for this test here
	EALLOW;
	// Enable PWM pins
    GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6  pins
    GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
    EDIS;
    
// Step 3. Initialize PIE vector table:
	// The PIE vector table is initialized with pointers to shell Interrupt 
    // Service Routines (ISR).  The shell routines are found in DSP28_DefaultIsr.c.
	// Insert user specific ISR code in the appropriate shell ISR routine in 
    // the DSP28_DefaultIsr.c file.

	// Disable and clear all CPU interrupts:
	DINT;
	IER = 0x0000;
	IFR = 0x0000;

	// Initialize Pie Control Registers To Default State:
        // This function is found in the DSP28_PieCtrl.c file.
	InitPieCtrl();

	// Initialize the PIE Vector Table To a Known State:
        // This function is found in DSP28_PieVect.c.
	// This function populates the PIE vector table with pointers
        // to the shell ISR functions found in DSP28_DefaultIsr.c.
	InitPieVectTable();	
	
// Step 4. Initialize all the Device Peripherals to a known state:
	// This function is found in DSP28_InitPeripherals.c
    // InitPeripherals();
   
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

// EVA Configure T1PWM, T2PWM, PWM1-PWM6 
// Step 1  Initalize the timers
	// Initalize EVA Timer1 
	EvaRegs.T1PR = 0xffff;       // Timer1 period
	EvaRegs.T1CMPR = 0x0000;     // Timer1 compare
	EvaRegs.T1CNT = 0x0000;      // Timer1 counter
    // TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvaRegs.T1CON.all = 0x1042;   


	// Initalize EVA Timer2 
	EvaRegs.T2PR = 0x0FFF;       // Timer2 period
	EvaRegs.T2CMPR = 0x03C0;     // Timer2 compare
	EvaRegs.T2CNT = 0x0000;      // Timer2 counter
    // TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvaRegs.T2CON.all = 0x1042;   


// Step 2  Setup T1PWM and T2PWM
	// Drive T1/T2 PWM by compare logic
	EvaRegs.GPTCONA.bit.TCOMPOE = 1;
	// Polarity of GP Timer 1 Compare = Active low
	EvaRegs.GPTCONA.bit.T1PIN = 1;
	// Polarity of GP Timer 2 Compare = Active high
	EvaRegs.GPTCONA.bit.T2PIN = 2;

// Step 3 Enable compare for PWM1-PWM6
	EvaRegs.CMPR1 = 0x0C00;
	EvaRegs.CMPR2 = 0x3C00;
	EvaRegs.CMPR3 = 0xFC00;
    
    // Compare action control.  Action that takes place
    // on a cmpare event
    // output pin 1 CMPR1 - active high
    // output pin 2 CMPR1 - active low
    // output pin 3 CMPR2 - active high
    // output pin 4 CMPR2 - active low
    // output pin 5 CMPR3 - active high
    // output pin 6 CMPR3 - active low
    EvaRegs.ACTR.all = 0x0666;
	EvaRegs.DBTCONA.all = 0x0000; // Disable deadband
    EvaRegs.COMCONA.all = 0xA600;
	


// EVB Configure T3PWM, T4PWM and PWM7-PWM12
// Step 1 - Initalize the Timers

    // Initalize EVB Timer3 
	// Timer3 controls T3PWM and PWM7-12
	EvbRegs.T3PR = 0xFFFF;       // Timer3 period
	EvbRegs.T3CMPR = 0x3C00;     // Timer3 compare
	EvbRegs.T3CNT = 0x0000;      // Timer3 counter
    // TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvbRegs.T3CON.all = 0x1042;   

    // Initalize EVB Timer4 
    // Timer4 controls T4PWM
	EvbRegs.T4PR = 0x00FF;       // Timer4 period
	EvbRegs.T4CMPR = 0x0030;     // Timer4 compare
	EvbRegs.T4CNT = 0x0000;      // Timer4 counter
    // TMODE = continuous up/down
	// Timer enable
	// Timer compare enable
	EvbRegs.T4CON.all = 0x1042;   


// Step 2  Setup T3PWM and T4PWM
	// Drive T3/T4 PWM by compare logic
	EvbRegs.GPTCONB.bit.TCOMPOE = 1;
    // Polarity of GP Timer 3 Compare = Active low
	EvbRegs.GPTCONB.bit.T3PIN = 1;
	// Polarity of GP Timer 4 Compare = Active high
	EvbRegs.GPTCONB.bit.T4PIN = 2;
 	
// Step 3  Enable compare for PWM7-PWM12
	EvbRegs.CMPR4 = 0x0C00;
	EvbRegs.CMPR5 = 0x3C00;
	EvbRegs.CMPR6 = 0xFC00;
    
    // Compare action control.  Action that takes place
    // on a cmpare event
    // output pin 1 CMPR4 - active high
    // output pin 2 CMPR4 - active low
    // output pin 3 CMPR5 - active high
    // output pin 4 CMPR5 - active low
    // output pin 5 CMPR6 - active high
    // output pin 6 CMPR6 - active low
    EvbRegs.ACTRB.all = 0x0666;
	EvbRegs.DBTCONB.all = 0x0000; // Disable deadband
    EvbRegs.COMCONB.all = 0xA600;


// Step 6. IDLE loop. Just sit and loop forever:
//  PWM pins can be observed with a scope.	
	for(;;);

} 	


// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:	
	// If local ISRs are used, reassign vector addresses in vector table as
    // shown in Step 5



//===========================================================================
// No more.
//===========================================================================
*/

⌨️ 快捷键说明

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