Other Parts Discussed in Thread: TMS320F28335
Hi Community,
We are using the TMS320F28335 in ordre to create a PWM signal to control an inverter. We want to have a 50kHz signal at the end so we set up the TBPRD to 1500. We also want nine specific impulsion width. So we created a table containing these values and set up a for loop to set the PWM correctly. Our problem is that the clock that runs the loop seems to be the CPU clock. We would like to set the frequency of the clock at the same frequency of the PWM. Is it possible ?
Here is our code :
#include "DSP28x_Project.h"
#include <math.h>
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 2048 // Sample buffer size
// ADC start parameters
#define ADC_SHCLK 0xf // S/H width in ADC module periods = 16 ADC clocks
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 2048 // Sample buffer size
// Global variable for this example
double alpha;
int i;
int table_alpha[9] = { 39, 56, 62, 56, 39, 20, 8, 8, 20};
int m=9;
// external function prototypes
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
// Prototype statements for functions found within this file.
void Gpio_select(void);
void Setup_ePWM(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
{
InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c
DINT; // Disable all interrupts
Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output
// to 4 LEDs at Peripheral Explorer)
Setup_ePWM(); // init of ePWM
InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c
InitPieVectTable(); // default ISR's in PIE
InitCpuTimers();
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1){
for(i=0; i<m;i=i+1){
alpha=table_alpha[i]/100;
EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD*alpha;
}
}
EALLOW;
SysCtrlRegs.WDKEY = 0x55; // service WD #1
SysCtrlRegs.WDKEY = 0xAA; // service WD #2
EDIS;
}
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // ePWM1B active
GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O
GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O
GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O
GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O
GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O
GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs
GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs
EDIS;
}
void Setup_ePWM(void)
{
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0; // HSPCLKDIV = 1
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode
EPwm1Regs.AQCTLA.all = 0x0600; //set up when CTR=CMPA on DOWM Count
//clear when CTR=CMPA on UP Count
EPwm1Regs.AQCTLB.all = 0x0060; //set up when CTR=CMPB on UP Count
//clear when CTR=CMPB on DOWM Count
EPwm1Regs.TBPRD = 2000; // 50KHz - PWM signal TBPRD = fcpu / (2*fPWM * CLKDIV * HSPCLKDIV)
}
//===========================================================================
// End of SourceCode.
//===========================================================================
We are not very experienced with this type of technology.
Thanks for the help
JB