コード例 #1
0
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));
    myPwm4 = PWM_init((void *)PWM_ePWM4_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 x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
    PLL_setup(myPll, PLL_Multiplier_12, 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

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the f2802x_SysCtrl.c file.
//   InitSysCtrl();

// Step 2. Initialize GPIO:
// This example function is found in the f2802x_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 for EPwm1-EPwm4

// For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4
// These functions are in the f2802x_EPwm.c file
//   InitEPwm1Gpio();
//   InitEPwm2Gpio();
//   InitEPwm3Gpio();
//   InitEPwm4Gpio();

// 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 f2802x_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 f2802x_DefaultIsr.c.
// This function is found in f2802x_PieVect.c.
//   InitPieVectTable();

// For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4
    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);

    GPIO_setPullUp(myGpio, GPIO_Number_6, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_7, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_6, GPIO_6_Mode_EPWM4A);
    GPIO_setMode(myGpio, GPIO_Number_7, GPIO_7_Mode_EPWM4B);

// Setup a debug vector table and enable the PIE
    PIE_setDebugIntVectorTable(myPie);
    PIE_enable(myPie);

    CLK_enablePwmClock(myClk, PWM_Number_1);
    CLK_enablePwmClock(myClk, PWM_Number_2);
    CLK_enablePwmClock(myClk, PWM_Number_3);
    CLK_enablePwmClock(myClk, PWM_Number_4);

// For this example, only initialize the EPwm
// Step 4. User specific code, enable interrupts:
   update =1;
   DutyFine =0;

   CLK_disableTbClockSync(myClk);

// Some useful Period vs Frequency values
//  SYSCLKOUT =     60 MHz       40 MHz
//  --------------------------------------
//    Period            Frequency    Frequency
//    1000               60 kHz       40 kHz
//    800                75 kHz       50 kHz
//    600                100 kHz      67 kHz
//    500                120 kHz      80 kHz
//    250                240 kHz      160 kHz
//    200                300 kHz      200 kHz
//    100                600 kHz      400 kHz
//    50                 1.2 Mhz      800 kHz
//    25                 2.4 Mhz      1.6 MHz
//    20                 3.0 Mhz      2.0 MHz
//    12                 5.0 MHz      3.3 MHz
//    10                 6.0 MHz      4.0 MHz
//    9                  6.7 MHz      4.4 MHz
//    8                  7.5 MHz      5.0 MHz
//    7                  8.6 MHz      5.7 MHz
//    6                  10.0 MHz     6.6 MHz
//    5                  12.0 MHz     8.0 MHz

//====================================================================
// EPwm and HRPWM register initialization
//====================================================================
   HRPWM1_Config(10);         // EPwm1 target, Period = 10
   HRPWM2_Config(20);         // EPwm2 target, Period = 20
   HRPWM3_Config(10);         // EPwm3 target, Period = 10
   HRPWM4_Config(20);         // EPwm4 target, Period = 20

   CLK_enableTbClockSync(myClk);

   while (update ==1)
   {
        PWM_setCmpAHr(myPwm1, DutyFine << 8);
        PWM_setCmpAHr(myPwm2, DutyFine << 8);
        PWM_setCmpAHr(myPwm3, DutyFine << 8);
        PWM_setCmpAHr(myPwm4, DutyFine << 8);
   }
}
コード例 #2
0
ファイル: Example_2802xHRPWM.c プロジェクト: smarley2/PSE
void main(void)
{
// WARNING: Always ensure you call memcpy before running any functions from RAM
// InitSysCtrl includes a call to a RAM based function and without a call to
// memcpy first, the processor will go "into the weeds"
   #ifdef _FLASH
	memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
   #endif

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the f2802x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initialize GPIO:
// This example function is found in the f2802x_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 for EPwm1-EPwm4

// For this case just init GPIO pins for EPwm1, EPwm2, EPwm3, EPwm4
// These functions are in the f2802x_EPwm.c file
   InitEPwm1Gpio();
   InitEPwm2Gpio();
   InitEPwm3Gpio();
   InitEPwm4Gpio();

// 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 f2802x_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 f2802x_DefaultIsr.c.
// This function is found in f2802x_PieVect.c.
   InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// Not required for this example

// For this example, only initialize the EPwm
// Step 5. User specific code, enable interrupts:
   update =1;
   DutyFine =0;

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
   EDIS;

// Some useful Period vs Frequency values
//  SYSCLKOUT =     60 MHz       40 MHz
//  --------------------------------------
//	Period	        Frequency    Frequency
//	1000	        60 kHz       40 kHz
//	800		        75 kHz       50 kHz
//	600		        100 kHz      67 kHz
//	500		        120 kHz      80 kHz
//	250		        240 kHz      160 kHz
//	200		        300 kHz      200 kHz
//	100		        600 kHz      400 kHz
//	50		        1.2 Mhz      800 kHz
//	25		        2.4 Mhz      1.6 MHz
//	20		        3.0 Mhz      2.0 MHz
//	12		        5.0 MHz      3.3 MHz
//	10		        6.0 MHz      4.0 MHz
//	9		        6.7 MHz      4.4 MHz
//	8		        7.5 MHz      5.0 MHz
//	7		        8.6 MHz      5.7 MHz
//	6		        10.0 MHz     6.6 MHz
//	5		        12.0 MHz     8.0 MHz

//====================================================================
// ePWM and HRPWM register initialization
//====================================================================
   HRPWM1_Config(10);	    // ePWM1 target, Period = 10
   HRPWM2_Config(20);	    // ePWM2 target, Period = 20
   HRPWM3_Config(10);	    // ePWM3 target, Period = 10
   HRPWM4_Config(20);	    // ePWM4 target, Period = 20

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
   EDIS;

   while (update ==1)
   {
        for(DutyFine =1; DutyFine <256 ;DutyFine ++)
        {
            // Example, write to the HRPWM extension of CMPA
            EPwm1Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits
            EPwm2Regs.CMPA.half.CMPAHR = DutyFine << 8;     // Left shift by 8 to write into MSB bits

            // Example, 32-bit write to CMPA:CMPAHR
            EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);
            EPwm4Regs.CMPA.all = ((Uint32)EPwm4Regs.CMPA.half.CMPA << 16) + (DutyFine << 8);

            for (i=0;i<10000;i++){}   // Dummy delay between MEP changes
		}
   }
}
コード例 #3
0
//
// Main
//
void main(void)
{
   EALLOW;
//
// Step 1. Initialize System Control for Control and Analog Subsystems
// Enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
    InitSysCtrl();
    EDIS;

    InitEPwmGpio();                   // EPWM1A and EPWM1B through all PWMS

    ePWM[1] = &EPwm1Regs;             // PWM Address Map
    ePWM[2] = &EPwm2Regs;             // PWM Address Map
    ePWM[3] = &EPwm3Regs;             // PWM Address Map
    ePWM[4] = &EPwm4Regs;             // PWM Address Map
    ePWM[5] = &EPwm5Regs;             // PWM Address Map
    ePWM[6] = &EPwm6Regs;             // PWM Address Map
    ePWM[7] = &EPwm7Regs;             // PWM Address Map
    ePWM[8] = &EPwm8Regs;             // PWM Address Map
    ePWM[9] = &EPwm9Regs;             // PWM Address Map

    InitEPwmGpio();                   // EPWM1A and EPWM1B -

    DINT; // Disable CPU interrupts

//
// Initialize 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:
//
    EALLOW;
    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
 // EDIS;   // This is needed to disable write to EALLOW protected registers

//
// Enable interrupts required for this example
//
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
    IER = 0x400;                         // Enable CPU INT

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//

//
// Step 5. User specific code, enable interrupts:
//
    update =1;
    DutyFine =0;

    EALLOW;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    EDIS;

//
// EPwm and HRPWM register initialization
//
    HRPWM1_Config(30);         // EPwm1 target, Period = 10
    HRPWM2_Config(20);         // EPwm2 target, Period = 20
    HRPWM3_Config(20);         // EPwm3 target, Period = 10
    HRPWM4_Config(20);         // EPwm4 target, Period = 20
    HRPWM5_Config(20);         // EPwm1 target, Period = 10
    HRPWM6_Config(20);         // EPwm2 target, Period = 20
    HRPWM7_Config(20);         // EPwm3 target, Period = 10
    HRPWM8_Config(20);         // EPwm4 target, Period = 20

    EALLOW;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    EDIS;

    while(update == 1)
    {
        //
        // Example, write to the HRPWM extension of CMPA / CMPB
        //
        EPwm1Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm1Regs.CMPB.all = DutyFine << 8;
        EPwm2Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm2Regs.CMPB.all = DutyFine << 8;

        //
        // Example, 32-bit write to CMPA:CMPAHR
        //
        EPwm3Regs.CMPA.all = ((Uint32)EPwm3Regs.CMPA.bit.CMPA << 16) +
                             (DutyFine << 8);
        EPwm3Regs.CMPB.all = DutyFine << 8;
        EPwm4Regs.CMPB.all = (DutyFine << 8);
        EPwm4Regs.CMPA.bit.CMPAHR = (DutyFine << 8);

        //
        // Example, write to the HRPWM extension of CMPA / CMPB
        //
        EPwm5Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm5Regs.CMPB.all = DutyFine << 8;
        EPwm6Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm6Regs.CMPB.all = DutyFine << 8;

        //
        // Example, write to the HRPWM extension of CMPA / CMPB
        //
        EPwm7Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm7Regs.CMPB.all = DutyFine << 8;
        EPwm8Regs.CMPA.bit.CMPAHR = DutyFine << 8;
        EPwm8Regs.CMPB.all = DutyFine << 8;
    }

//
// Enable global Interrupts and higher priority real-time debug events:
//
    EINT;   // Enable Global interrupt INTM
    ERTM;   // Enable Global realtime interrupt DBGM

    for(;;); // Step 6. IDLE loop. Just sit and loop forever (optional):
}