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.

40kHz PWM and 16-bit Resolution with the TMS320F2812?

Other Parts Discussed in Thread: TMS320F2812

Hey,

I've to  get a PWM with 40kHz and 16-bit Resolution with a TMS320F2812. At first, is this possible? I need it for my bachelor thesis but I can´t get the right PWM. Either I get the 40kHz or the 16-bit Resolution  on the Compare Register...

Actually I use the ev-pwm Code Sample and I've changed the Timer Period to 0x0E9F to get the higher PWM (40kHz)

EvaRegs.T1PR = 0x0E9F; // Timer1 period

After that I've changed the timer compare value( Is this the maximum value for the CMPRx register?) Now I thought I have a 16-bit resolution but the PWM Output is steady high until CMPR1 fall below 0x1000.

EvaRegs.T1CMPR = 0xFFFF; // Timer1 compare

Thanks in advance for your help!

FIY here is my whole EVA- Init

void init_eva()
{
// EVA Configure T1PWM, T2PWM, PWM1-PWM6
// Initalize the timers
// Initalize EVA Timer1
EvaRegs.T1PR = 0x0E9F; // Timer1 period
EvaRegs.T1CMPR = 0xFFFF; // 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 = 0x0E9F; // Timer2 period
EvaRegs.T2CMPR = 0xFFFF; // Timer2 compare
EvaRegs.T2CNT = 0x0000; // Timer2 counter
// TMODE = continuous up/down
// Timer enable
// Timer compare enable
EvaRegs.T2CON.all = 0x1042;


// Setup T1PWM and T2PWM
// Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.TCMPOE = 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;

// Enable compare for PWM1-PWM6
EvaRegs.CMPR1 = 0x0F00;
EvaRegs.CMPR2 = 0x1F00;
EvaRegs.CMPR3 = 0xDF00;

EvaRegs.ACTRA.all = 0x0555;
EvaRegs.DBTCONA.all = 0x0000; // Disable deadband
EvaRegs.COMCONA.all = 0xA600;
}

  • Hi Merben,

    merben said:
    I've to  get a PWM with 40kHz and 16-bit Resolution with a TMS320F2812. At first, is this possible? I need it for my bachelor thesis but I can´t get the right PWM. Either I get the 40kHz or the 16-bit Resolution  on the Compare Register...

    Can you give info on what is your sysclkout? ie what is the input clock?

    If you input 75Mhz clock to run your PWM timer then in order to generate a PWM frequency of 50KHz the period register should be loaded with 1500 (75MHz/50KHz ). By the way, there is also prescalar to further slow down your timer clock but that will lower your PWM resolution.

    Regards,

    Gautam

  • Hi Gautam,

    my SYSCLK shall be 150MHz. I´ve used a sysclk/2 prescaler (  SysCtrlRegs.HISPCP.all = 0x0001;).

    To avoid missunderstanding, I´ve attached my InitPeripheralClocks(). It´s from the DSP281x_SysCtrl.c-File ;-)   

    To get the 40kHz I have to load the TxCMPR register with 1875 ? So I couldn't get the 16-bit resolution? 

    Like I said, my prof. demands a 40kHz PWm with 16-bit resolution.... 

    I'm sorry for the questions...It's my first time working with a tms320....

    kind regards,

    Benjamin

    void InitPeripheralClocks(void)
    {
    EALLOW;
    // HISPCP/LOSPCP prescale register settings, normally it will be set to default values
    SysCtrlRegs.HISPCP.all = 0x0001;
    SysCtrlRegs.LOSPCP.all = 0x0002;

    // Peripheral clock enables set for the selected peripherals.
    SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
    SysCtrlRegs.PCLKCR.bit.EVBENCLK=1;
    SysCtrlRegs.PCLKCR.bit.SCIAENCLK=1;
    SysCtrlRegs.PCLKCR.bit.SCIBENCLK=1;
    SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=1;
    SysCtrlRegs.PCLKCR.bit.SPIENCLK=1;
    SysCtrlRegs.PCLKCR.bit.ECANENCLK=1;
    SysCtrlRegs.PCLKCR.bit.ADCENCLK=1;
    EDIS;
    }