You have no items in your shopping cart.

Subtotal: 0.00

GENERATE 1Khz PWM USING TMS320F2812 DSP

Aim

To Generate the 1 Khz PWM in TMS320F2812 KIT.

Requirements

 

Theory

Pulse Width Modulation(PWM), is a commonly used technique for controlling power to inertial electrical devices, made practical by modern electronic power switches.

In TMS320F2812 KIT, The F2812 processor core have an Event Manager to generate the PWMs. The Core has a 2 Event manager, EVA & EVB. Up to eight PWM waveforms (outputs) can be generated simultaneously by each event manager. So, totally 16 PWMs get at F2812 processor Which is more than enough to control a five phase device control. EV have certain Registers to perform.

There are two GP timers in each EV module. The GP timer x (x = 1 or 2 for EVA, x = 3 or 4 for EVB) includes

  • A 16-bit timer, up-/down-counter, TxCNT, for reads or writes
  • A 16-bit timer-compare register, TxCMPR (double-buffered with shadow register), for reads or writes
  • A 16-bit timer-period register, TxPR (double-buffered with shadow register), for reads or writes
  • A 16-bit timer-control register,TxCON, for reads or writes

These four registers are very important and needed to generate the pwm., some more register(GPTCONA, DBTCONA, COMCONA, ACTRA, CMPR1, CMPR2, CMPR3, CAPCONA) are available to Control the PWM.

Calculating the period value for 1 Khz pwm





Where,

SYSCLKOUT = 125 Mhz

HISPCP – 2

TPS – 1 (Load the TPS Value in T1con register).

TIPWM – 1000 (1 khZ).

T1PR = F424; for 1 Khz period value.

T1CMPR = 7A12.(50 % Duty Cycle)

Procedure

Note: Once you install the Code Composer Studio v 3.3 software, the two icons will display in desktop

  • Setup Code Composer Studio v3.3
  • Code Composer Studio

1. Open Setup Code Composer Studio v3.3.

2. In System Configuration, select the board then → Remove all → yes.

  • In family, select C28xx.
  • In platform, select xds100 usb emulator.
  • In Endianness, select little.
  • Select F2812 XDS100 USB Emulator → add → save & quit no.

Note: The above two steps only for first time to setup the processor in CCS.

3. Open Code Composer Studio v3.3.

4. Project → New.

  • Project name: type the project name.
  • Location: Browse, select the project location .
  • Project Type: Executable(.out)
  • Target: TMS320C28XX. → Finish.

5. File → New → Source file.

  • Type the program in untitled window.

6. File → Save.

  • Browse our project location then type our project name.c ( .c extension is must) → save.

7. Paste the following two cmd files in our project folder.

  • F2812_EzDSP_RAM_lnk.cmd
  • DSP281x_Headers_nonBIOS.cmd
  • DSP281x_GlobalVariableDefs.c

8. Project → Add files to project.

  • In file of type : All files
  • Ctrl + Select the following files - projectname.c - DSP281x_GlobalVariableDefs.c - F2812_EzDSP_RAM_lnk.cmd - DSP281x_Headers_nonBIOS.cmd → open.

9. Project → Build Option.

In compiler tab, select Preprocessor

  • Include search path(-i) : C:\tidcs\c28\DSP281x\v120\DSP281x_headers\include

In linker tab, select libraries

  • Search path(-i) : C:\CCStudio_v3.3\C2000\cgtools\lib
  • Incl libraries(-l) : rts2800_ml.lib.

In linker tab, select Basic

  • Stack Size(-stack) : 0x400 → ok.

10. Project → Build (or) Rebuild all.

11. Connections forTMS320F2812 KIT

12. Debug → connect.

13. File → Load Program → Browse and select the projectname.out file → open

14. Debug → Go main.

15. Debug → Run.

16. See the output at CRO by connecting probe positive terminal to (Port A) PWM pins & probe negative terminal to Ground.

17. Debug → Halt.

Program

#include "DSP281x_Device.h"     // DSP281x Headerfile Include File
#include "DSP281x_Examples.h"   // DSP281x Examples Include File
								// Prototype statements for functions found within this file.
void InitSystem(void);
void main(void)
{
InitSystem();
	EALLOW;
    	GpioMuxRegs.GPAMUX.all = 0x01FF; // EVA PWM 1-6  pins
   	GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
   	EDIS;    
       	DINT;
        EvaRegs.T1PR = 0xF424;       // Timer1 period
   	EvaRegs.T1CMPR = 0x7A12;     // Timer1 compare
   	EvaRegs.T1CNT = 0x0000;      // Timer1 counter
    	EvaRegs.T1CON.all = 0x1042;		// TMODE = continuous up & Timer enable 
  	EvaRegs.T2PR = 0xF424;       // Timer2 period
  	EvaRegs.T2CMPR = 0x7A12;     // Timer2 compare
	EvaRegs.T2CNT = 0x0000;      // Timer2 counter
EvaRegs.T2CON.all = 0x1042;   
 	EvaRegs.GPTCONA.bit.TCMPOE = 1;	  // Drive T1/T2 PWM by compare logic
EvaRegs.GPTCONA.bit.T1PIN = 1;	// Polarity of GP Timer 1 Compare = Active low
EvaRegs.GPTCONA.bit.T2PIN = 2;	// Polarity of GP Timer 2 Compare = Active high
  	EvaRegs.CMPR1 = 0x7A12;			  // Enable compare for PWM1-PWM6
  	EvaRegs.CMPR2 = 0x7A12;
  	EvaRegs.CMPR3 = 0x7A12;
  	EvaRegs.ACTRA.all = 0x0666;
  	EvaRegs.DBTCONA.all = 0x0530; // Disable deadband
  	EvaRegs.COMCONA.all = 0xA600;
 	EvaRegs.CAPCONA.bit.CAPRES = 0;	// 	reset all capture regs to zero
  	EvaRegs.CAPCONA.all = 0x2240;	// enable CAP1, selcting gp timer 1 & detecting rising edge
  	EvaRegs.CAPFIFOA.all = 0x0100;
   for(;;);													
}
void InitSystem(void)
{
   	EALLOW;
   	SysCtrlRegs.WDCR= 0x0068;		// Setup the watchdog 
   									// 0x00E8  to disable the Watchdog , Prescaler = 1
   									// 0x00AF  to NOT disable the Watchdog, Prescaler = 64
   	SysCtrlRegs.SCSR = 0; 			// Watchdog generates a RESET	
   	SysCtrlRegs.PLLCR.bit.DIV = 10;	// Setup the Clock PLL to multiply by 5
       	SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to divide by 2
   	SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to divide by 4
       	// Peripheral clock enables set for the selected peripherals.   
   	SysCtrlRegs.PCLKCR.bit.EVAENCLK=1;
   	SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
   	EDIS;
}

Result

Thus, the 1 Khz PWM was generated using TMS320F2812 KIT.