void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2803x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initialize GPIO: // This example function is found in the DSP2803x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // For this case just init GPIO pins for ePWM1, ePWM2, and TZ pins InitEPwm1Gpio(); InitEPwm2Gpio(); InitEPwm3Gpio(); InitTzGpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2803x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2803x_DefaultIsr.c. // This function is found in DSP2803x_PieVect.c. InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.EPWM1_TZINT = &epwm1_tzint_isr; PieVectTable.EPWM2_TZINT = &epwm2_tzint_isr; PieVectTable.EPWM3_TZINT = &epwm3_tzint_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // Not required for this example EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; InitEPwm1Example(); InitEPwm2Example(); InitEPwm3Example(); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; // Step 5. User specific code, enable interrupts // Initialize counters: EPwm1TZIntCount = 0; EPwm2TZIntCount = 0; EPwm3TZIntCount = 0; // Enable CPU INT3 which is connected to EPWM1-3 INT: IER |= M_INT2; // Enable EPWM INTn in the PIE: Group 2 interrupt 1-3 PieCtrlRegs.PIEIER2.bit.INTx1 = 1; PieCtrlRegs.PIEIER2.bit.INTx2 = 1; PieCtrlRegs.PIEIER2.bit.INTx3 = 1; // Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Step 6. IDLE loop. Just sit and loop forever (optional): for(;;) { __asm(" NOP"); } }
// // Main // void main(void) { // // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the F2837xS_SysCtrl.c file. // InitSysCtrl(); // // Step 2. Initialize GPIO: // This example function is found in the F2837xS_Gpio.c file and // illustrates how to set the GPIO to it's default state. // // InitGpio(); // // enable PWM2, PWM6, PWM7 and PWM8 // CpuSysRegs.PCLKCR2.bit.EPWM2=1; CpuSysRegs.PCLKCR2.bit.EPWM6=1; CpuSysRegs.PCLKCR2.bit.EPWM7=1; CpuSysRegs.PCLKCR2.bit.EPWM8=1; // // For this case just init GPIO pins for PWM2, PWM6, PWM7 and PWM8 // These functions are in the F2837xS_EPwm.c file // InitEPwm2Gpio(); // InitEPwm6Gpio(); InitEPwm7Gpio(); InitEPwm8Gpio(); // // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts // DINT; // // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the F2837xS_PieCtrl.c file. // InitPieCtrl(); // // Disable CPU interrupts and clear all CPU interrupt flags: // IER = 0x0000; IFR = 0x0000; // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in F2837xS_DefaultIsr.c. // This function is found in F2837xS_PieVect.c. // InitPieVectTable(); // // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. // EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.EPWM2_INT = &epwm2_isr; PieVectTable.EPWM6_INT = &epwm6_isr; PieVectTable.EPWM7_INT = &epwm7_isr; PieVectTable.EPWM8_INT = &epwm8_isr; EDIS; // This is needed to disable write to EALLOW protected registers // // For this example, only initialize the ePWM // EALLOW; CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; InitEPwm2Example(); InitEPwm6Example(); InitEPwm7Example(); InitEPwm8Example(); EALLOW; CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; // // Step 4. User specific code, enable interrupts: // // // Enable CPU INT3 which is connected to EPWM1-3 INT: // IER |= M_INT3; // // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3 // PieCtrlRegs.PIEIER3.bit.INTx2 = 1; PieCtrlRegs.PIEIER3.bit.INTx6 = 1; // ePWM6 PieCtrlRegs.PIEIER3.bit.INTx7 = 1; // ePWM7 PieCtrlRegs.PIEIER3.bit.INTx8 = 1; // ePWM8 // // Enable global Interrupts and higher priority real-time debug events: // EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // // Step 5. IDLE loop. Just sit and loop forever (optional): // for(;;) { asm (" NOP"); } }
void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2803x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initalize GPIO: // This example function is found in the DSP2803x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example // For this case just init GPIO pins for ePWM1, ePWM2, ePWM3 // These functions are in the DSP2803x_EPwm.c file InitEPwm1Gpio(); InitEPwm2Gpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2803x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // GPIO0 = PWM1A GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // GPIO1 = PWM1B GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // GPIO2 = PWM2A GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; // GPIO3 = PWM2B GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; //GPIO0 = output GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //GPIO0 = output GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //GPIO0 = output GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; //GPIO0 = output // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. // The shell ISR routines are found in DSP2803x_DefaultIsr.c. // This function is found in DSP2803x_PieVect.c. InitPieVectTable(); // Interrupts that are used in this example are re-mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected registers // PieVectTable.EPWM1_INT = &epwm1_isr; // PieVectTable.EPWM2_INT = &epwm2_isr; EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in DSP2803x_InitPeripherals.c // InitPeripherals(); // Not required for this example // For this example, only initialize the ePWM EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS; InitEPwm1Example(); InitEPwm2Example(); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; // Step 5. User specific code, enable interrupts: // Enable CPU INT3 which is connected to EPWM1-3 INT: IER |= M_INT3; // PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // PieCtrlRegs.PIEIER3.bit.INTx2 = 1; EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Step 6. IDLE loop. Just sit and loop forever (optional): for(;;) { asm(" NOP"); } }
void main(void) { CPU_Handle myCpu; PLL_Handle myPll; WDOG_Handle myWDog; // Initialize all the handles needed for this application myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj)); myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj)); myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj)); myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj)); myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj)); myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj)); myPwm1 = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj)); myPwm2 = PWM_init((void *)PWM_ePWM2_BASE_ADDR, sizeof(PWM_Obj)); myPwm3 = PWM_init((void *)PWM_ePWM3_BASE_ADDR, sizeof(PWM_Obj)); myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj)); // Perform basic system initialization WDOG_disable(myWDog); CLK_enableAdcClock(myClk); (*Device_cal)(); CLK_disableAdcClock(myClk); //Select the internal oscillator 1 as the clock source CLK_setOscSrc(myClk, CLK_OscSrc_Internal); // Setup the PLL for x10 /2 which will yield 50Mhz = 10Mhz * 10 / 2 PLL_setup(myPll, PLL_Multiplier_10, PLL_DivideSelect_ClkIn_by_2); // Disable the PIE and all interrupts PIE_disable(myPie); PIE_disableAllInts(myPie); CPU_disableGlobalInts(myCpu); CPU_clearIntFlags(myCpu); // If running from flash copy RAM only functions to RAM #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Initialize GPIO GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A); GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B); GPIO_setPullUp(myGpio, GPIO_Number_2, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_3, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_EPWM2A); GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_EPWM2B); GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable); GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable); GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A); GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B); // Setup a debug vector table and enable the PIE PIE_setDebugIntVectorTable(myPie); PIE_enable(myPie); // Register interrupt handlers in the PIE vector table PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_1, (intVec_t)&epwm1_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_2, (intVec_t)&epwm2_isr); PIE_registerPieIntHandler(myPie, PIE_GroupNumber_3, PIE_SubGroupNumber_3, (intVec_t)&epwm3_isr); CLK_disableTbClockSync(myClk); InitEPwm1Example(); InitEPwm2Example(); InitEPwm3Example(); CLK_enableTbClockSync(myClk); // Enable CPU INT3 which is connected to EPWM1-3 INT: CPU_enableInt(myCpu, CPU_IntNumber_3); // Enable EPWM INTn in the PIE: Group 3 interrupt 1-3 PIE_enablePwmInt(myPie, PWM_Number_1); PIE_enablePwmInt(myPie, PWM_Number_2); PIE_enablePwmInt(myPie, PWM_Number_3); // Enable global Interrupts and higher priority real-time debug events CPU_enableGlobalInts(myCpu); CPU_enableDebugInt(myCpu); for(;;) { __asm(" NOP"); } }