|
// // 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.
#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 = 0x3C00; // 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.ACTRA.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. //===========================================================================
|