This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to mask pwm outputs

Other Parts Discussed in Thread: TMS320F28335, CONTROLSUITE

I want pwm output to be there for 10ms and it should be off for 10ms . How to configure this? Please help.

  • Hi,

    Which device you are using to generate the your PWM?

  • I'm using tms320f28335. 

  • Please can someone help me.

  • Shivraj,

    I would recommend looking at the following post:
    http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/250345/876885.aspx#876885

    You would create a PWM as in some of the examples in controlSUITE.  You'd then use one of the suggestions in the linked post to stop the PWM signal over some length of time. 
    (\controlSUITE\device_support\f2833x\v133\DSP2833x_examples_ccsv4\)

    I generally prefer the trip zone (TZ) method.


    Thank you,
    Brett

  • HI shivraj,

    Steps to create ePWM for 10ms ON and OFF

    1. Configure a ePWMx.

    2. Configure a Timer interrupt.

    3. In the timer ISR enable and disable the GPIOMUX reg.

     e.g  

    if(GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 == 1) {
    EALLOW;
    GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 = 0;
    EDIS;
    }else{
    EALLOW;
    GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 = 1;
    EDIS;
    }

    =========================================================================================================

    Configuration of ePWM output:

    // Time-base registers
    EPwm1Regs.TBPRD = PERIOD; // Set EPWM timer period
    EPwm1Regs.TBCTR = 0; // Time-Base Counter Register
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count-up mode: used for asymmetric PW
    // Set TBCLK frequency
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLKOUT
    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
    EPwm1Regs.AQCTLA.all = 6; // ZRO = set, PRD = clear
    EPwm1Regs.AQCTLB.all = 6; // ZRO = set, PRD = clear

    =========================================================================================================

    Configuration of Timer0:

    void InitCpuTimers(void)
    {
    CpuTimer0.RegsAddr = &CpuTimer0Regs;

    CpuTimer0Regs.PRD.all = 0xFFFFFFFF;

    CpuTimer0Regs.TPR.all = 0;
    CpuTimer0Regs.TPRH.all = 0;

    CpuTimer0Regs.TCR.bit.TSS = 1;

    CpuTimer0Regs.TCR.bit.TRB = 1;

    CpuTimer0.InterruptCount = 0;

    }

    ===================================================================

    void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
    {
    Uint32 temp;

    // Initialize timer period:
    Timer->CPUFreqInMHz = Freq;
    Timer->PeriodInUSec = Period;
    temp = (long) (Freq * Period);
    Timer->RegsAddr->PRD.all = temp;

    // Set pre-scale counter to divide by 1 (SYSCLKOUT):
    Timer->RegsAddr->TPR.all = 0;
    Timer->RegsAddr->TPRH.all = 0;

    // Initialize timer control register:
    Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart
    // Timer
    Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
    Timer->RegsAddr->TCR.bit.SOFT = 0;
    Timer->RegsAddr->TCR.bit.FREE = 0; // Timer Free Run Disabled
    Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer
    // Interrupt
    // Reset interrupt counter:
    Timer->InterruptCount = 0;
    }

    =========================================================================================================

    Main function:

    #define PERIOD 50
    #define C28_FREQ 100 //CPU frequency in MHz

    void ConfigEpwm1( void );
    interrupt void cpu_timer0_isr(void);

    // Global variables used in this example:
    Uint16 LoopCount;
    Uint16 ConversionCount;

    main()
    {

    // Step 1. Initialize System Control for Control and Analog Subsytems
    // Enable Peripheral Clocks
    // This example function is found in the F28M36x_SysCtrl.c file.
    InitSysCtrl();

    // If project is linked into flash, copy critical code sections to RAM.
    #ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif

    EDIS;

    // Step 2. Initialize GPIO:
    // This example function is found in the F28M36x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    InitGpio(); // Skipped for this example
    EALLOW;
    GpioG1CtrlRegs.GPADIR.bit.GPIO0 = 1; // Set as output
    GpioG1CtrlRegs.GPAMUX1.bit.GPIO0 = 1; // Select EPWM1SOCA as driving source
    GpioG1CtrlRegs.GPADIR.bit.GPIO1 = 1; // Set as output
    GpioG1CtrlRegs.GPAMUX1.bit.GPIO1 = 1; // Select EPWM1SOCB as driving source
    GpioG1CtrlRegs.GPCDIR.bit.GPIO70 = 1; //set PC6_GPIO70 as output
    EDIS;

    // 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 F28M36x_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 F28M36x_DefaultIsr.c.
    // This function is found in F28M36x_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.TINT0 = &cpu_timer0_isr;
    EDIS; // This is needed to disable write to EALLOW protected registers

    // Step 4. Initialize the Device Peripheral. This function can be
    // found in F28M36x_CpuTimers.c
    InitCpuTimers(); // For this example, only initialize the Cpu Timers

    ConfigEpwm1();
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // C28_FREQ in MHz, 1 second Period (in uSeconds)

    ConfigCpuTimer(&CpuTimer0, C28_FREQ, 10);
    // To ensure precise timing, use write-only instructions to write to the entire
    // register. Therefore, if any
    // of the configuration bits are changed in ConfigCpuTimer and InitCpuTimers (in
    // F28M36x_CpuTimers.h), the
    // below settings must also be updated.

    CpuTimer0Regs.TCR.all = 0x4000; // Use write-only instruction to set TSS bit

    // Step 5. User specific code, enable interrupts:

    // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
    IER |= M_INT1;

    // Enable TINT0 in the PIE: Group 1 interrupt 7
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

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

    LoopCount = 0;
    ConversionCount = 0;

    // Wait for ADC interrupt
    for(;;)
    {
    LoopCount++;
    }

    }

    =========================================================================================================

    Please select " Verify answer" if its work fine.

    Regards 

    Thirumoorthy.R