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.

why can't I have PWM output?

I am trying to use the library files from DMC to generate PWM signals from F2812 DSP. However, there is no PWM output at all. I checked the registers but still no clues. Here is file I used

/* ==================================================================================
File name:       F281XPWM.C
                    
Originator:    Digital Control Systems Group
            Texas Instruments

Description:   This file contains source for the Full Compare PWM  drivers for the F281x

Target: TMS320F281x family
     
=====================================================================================
History:
-------------------------------------------------------------------------------------
 04-15-2005    Version 3.20: Using DSP281x v. 1.00 or higher
----------------------------------------------------------------------------------*/

#include "DSP281x_Device.h"
#include "f281xpwm_an.h"
#define ACTR_DISABLE_STATE ( COMPARE1_FL + \
                          COMPARE2_FL + \
                          COMPARE3_FL + \
                          COMPARE4_FL + \
                          COMPARE5_FL + \
                          COMPARE6_FL )


void F281X_EV1_PWM_Init(PWMGEN *p)
{       
        EvaRegs.T1PR = p->PeriodMax;                // Init Timer 1 period Register
        EvaRegs.T1CON.all = PWM_INIT_STATE;            // Symmetrical Operation
        EvaRegs.DBTCONA.all = DBTCON_INIT_STATE;    // Init DBTCONA Register
//        EvaRegs.ACTRA.all = ACTR_INIT_STATE;        // Init ACTRA Register
        EvaRegs.ACTRA.all = ACTR_DISABLE_STATE;
        
        EvaRegs.COMCONA.all = 0xA200;                // Init COMCONA Register

        EvaRegs.CMPR1 = p->PeriodMax;                // Init CMPR1 Register
        EvaRegs.CMPR2 = p->PeriodMax;                // Init CMPR2 Register
        EvaRegs.CMPR3 = p->PeriodMax;                // Init CMPR3 Register
        EALLOW;                                       // Enable EALLOW
        GpioMuxRegs.GPAMUX.all |= 0x003F;            // Setting PWM1-6 as primary output pins
        EDIS;                                        // Disable EALLOW
}


void F281X_EV1_PWM_Update(PWMGEN *p)
{       
        int16 MPeriod;
        int32 Tmp;
        Uint16 Tmp2;
// Compute the timer period (Q0) from the period modulation input (Q15)
        Tmp = (int32)p->PeriodMax*(int32)p->MfuncPeriod;           // Q15 = Q0*Q15
        MPeriod = (int16)(Tmp>>16) + (int16)(p->PeriodMax>>1);     // Q0 = (Q15->Q0)/2 + (Q0/2)
        EvaRegs.T1PR = MPeriod;  

// Compute the compare 1 (Q0) from the PWM 1&2 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC1;                    // Q15 = Q0*Q15
        Tmp2 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);    // Q0 = (Q15->Q0)/2 + (Q0/2)
        if (p->IaDir >0) {
            Tmp2 += p->deadTime;
        }else {
            if (Tmp2 > p->deadTime) {
                Tmp2 -= p->deadTime;
            }else {
                Tmp2 = 0;
            }            
        }
        if (Tmp2 >= MPeriod) {
            Tmp2 = MPeriod-1;
        }
        EvaRegs.CMPR1 = Tmp2;

// Compute the compare 2 (Q0) from the PWM 3&4 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC2;                   // Q15 = Q0*Q15
        Tmp2 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);    // Q0 = (Q15->Q0)/2 + (Q0/2)
        if (p->IbDir >0) {
            Tmp2 += p->deadTime;
        }else {
            if (Tmp2 > p->deadTime) {
                Tmp2 -= p->deadTime;
            }else {
                Tmp2 = 0;
            }            
        }
        if (Tmp2 >= MPeriod) {
            Tmp2 = MPeriod-1;
        }
        EvaRegs.CMPR2 = Tmp2;

// Compute the compare 3 (Q0) from the PWM 5&6 duty cycle ratio (Q15)
        Tmp = (int32)MPeriod*(int32)p->MfuncC3;                   // Q15 = Q0*Q15
        Tmp2 = (int16)(Tmp>>16) + (int16)(MPeriod>>1);    // Q0 = (Q15->Q0)/2 + (Q0/2)
        if (p->IcDir >0) {
            Tmp2 += p->deadTime;
        }else {
            if (Tmp2 > p->deadTime) {
                Tmp2 -= p->deadTime;
            }else {
                Tmp2 = 0;
            }            
        }
        if (Tmp2 >= MPeriod) {
            Tmp2 = MPeriod-1;
        }
        EvaRegs.CMPR3 = Tmp2;
        
}

  • Hi Yue,

    Are you getting incorrect PWM or no PWM at all?
    What is the GPIO configuration? Can you check the same?

    -bharathi

  • Hi Bharathi,

    I don't have any PWM output at all.

    My GPIO configuration is as follows:

    GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA0 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA1 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA2 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA3 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA4 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA5 = 1;


    Thanks

    -Yue
  • Yue,

    I think you need to make the GPIO Mux bit to 1 for enabling peripheral functionality.
    Please try the following.


    EALLOW;
    // Enable PWM pins
    GpioMuxRegs.GPAMUX.all = 0x00FF;

    Let me know the result.

    -Bharathi.

  • Hi Bharathi,

    It still doesn't work. Here is the snapshot of the code

    //PWM pins
    EALLOW;
    // Enable PWM pins
    GpioMuxRegs.GPAMUX.all = 0x00FF;
    #if 0
    GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA0 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA1 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA2 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA3 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA4 = 1;

    GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5 = 0;
    GpioMuxRegs.GPADIR.bit.GPIOA5 = 1;
    #endif

    EDIS;
  • Yue,

    Can you download and check the PWM examples from -

    http://www.ti.com/lit/zip/sprc097

    -Bharathi.