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.

LAUNCHXL-F28069M: PWM frequency

Part Number: LAUNCHXL-F28069M


Hello,

I'm trying to set the frequency of a pwm signal but can't quite figure out the results.

The microcontroller'sTechnical Reference Manual gives a formula to choose a TBPRD value according to the frequency that I want. 

Using CLKDIV and HSPCLKDIV = 0, and knowing the SYSCLK (90 MHz, according to the technical documentation of the microcontroller), I'd need TBPRD = 899 to achieve a pwm frequency of 100 kHz. But, instead, this TBPRD results in about 11,2 kHz. Doing the reverse math, it means that SYSCLK = 10 MHz, approximately. 

What am I doing wrong? Does the launchpad affect the SYSCLK?

Below is the example code.

#include "DSP28x_Project.h"

float D = 0.5;

int main(void){
    DisableDog();
    InitPeripheralClocks();
    InitGpio();                                             

    EALLOW;                                                
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;                    
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;                     
    EDIS;                                                  

    EPwm1Regs.TBCTR = 0;
    EPwm1Regs.TBPRD = 1000;                                  
    EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD * D;         
    EPwm1Regs.TBPHS.all = 0;                              
    EPwm1Regs.TBCTL.all = 0;                               
    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;             
    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;                
    EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
    EPwm1Regs.TBCTL.bit.SYNCOSEL= TB_SYNC_DISABLE;
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;                
    EPwm1Regs.TBCTL.bit.CLKDIV = 0;                   
    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;           
    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;           
    EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;                     
    EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;                    

    while(1) {}

 }

Thanks in advance.

  • Hello,

    You may also want to initialize device clocks as needed to set the proper SYSCLK output, currently as the code stands the peripherals are utilizing the internal clock frequency i.e 10 Mhz.
    As a reference I would suggest to start with Clocking section in System Control and Interrupts Topic in Technical Reference Manual.

    Instead of  initializing peripheral clocks with InitPeripheralClocks();  I would suggest to use InitSysCtrl() which Initializes System Control including PLL, WatchDog and enabling Peripheral Clocks
    --> This example function is found in the F2806x_SysCtrl.c file.

    or use reference code below for selecting oscillator and initializing PLL:


    // Select Internal Oscillator 1 as Clock Source (default), and turn off all
    // unused clocks to conserve power.
    IntOsc1Sel();
    // Initialize the PLL control: PLLCR and CLKINDIV
    InitPll();

    Thank you.