You are currently viewing 50Hz Sine PWM Using TMS320F2812 DSP

50Hz Sine PWM Using TMS320F2812 DSP

Spread the love

Aim

To Generate the 50 Hz SINE PWM using boot rom sine table in TMS320F2812 KIT.

Requirements

☞CCS v3.3

TMS320F2812 KIT

☞USB Cable

☞5V Adapter

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.

Example: 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)

SPWM

Sinusoidal pulse width modulation is a method of pulse width modulation used in inverters. An inverter produces an AC output voltage from a DC input by using switching circuits to simulate a sine wave by producing one or more square pulses of voltage per half cycle. If the widths of the pulses are adjusted as a means of regulating the output voltage, the output is said to be pulse width modulated.

With sinusoidal or sine weighted pulse width modulation, several pulses are produced per half cycle. The pulses near the edges of the half cycle are always narrower than the pulses near the center of the half cycle such that the pulse widths are proportional to the corresponding amplitude of a sine wave at that portion of the cycle. To change the effective output voltage, the widths of all pulses are increased or decreased while maintaining the sinusoidal proportionality. With pulse width modulation, only the widths (on-time) of the pulses are modulated. The amplitudes (voltage) during the “on-time” is constant unless a multi-step circuit is used. The line-to neutral voltage of a 3-phase inverter has two voltage levels.

Boot ROM Table

From Address 0x3F F000 to 0x3F F3FF we find 512 values for sin(x). The numbers are stored as 32 Bit – numbers in “Q30”-notation. With 512 entries we have an angle step of 0.703° (360°/512) for a unit circle.

The following table shows the contents of the sine wave area of the Boot ROM:

Procedure for build a project on 50Hz Sine PWM Using TMS320F2812

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.

Paste the following two cmd files in our project folder.

☞F2812_EzDSP_RAM_lnk.cmd

☞DSP281x_Headers_nonBIOS.cmd

☞DSP281x_GlobalVariableDefs.c

☞DSP281x_DefaultIsr.c

☞DSP281x_PieCtrl.c

☞DSP281x_PieVect.c

8. Project → Add files to project.

☞ In file of type : All files

☞Ctrl + Select the following files – projectname.c – DSP281x_GlobalVariableDefs.c – DSP281x_DefaultIsr.c – DSP281x_PieCtrl.c – DSP281x_PieVect.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 for TMS320F2812 KIT

☞Connect 5v adpter to TMS320F2812 KIT.

☞Connect usb cable to TMS320F2812 KIT from pc.

☞Power on the TMS320F2812 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 & negative terminal to Ground.

17. Debug → Halt.

Program for 50Hz Sine PWM Using TMS320F2812

#include "DSP281x_Device.h"
#include "IQmathLib.h"
#pragma DATA_SECTION(sine_table,"IQmathTables");
_iq30 sine_table[512];

void InitSystem(void);
void InitPieCtrl();
void InitPieVectTable();
interrupt void T1_Compare_isr(void);
void main()
{
	InitSystem();
	EALLOW;
	GpioMuxRegs.GPAMUX.all = 0x0040;
	EDIS;
	InitPieCtrl();		
	InitPieVectTable(); 	 
	EALLOW;
	PieVectTable.T1CINT = &T1_Compare_isr;
	EDIS;
PieCtrlRegs.PIEIER2.bit.INTx5 = 1;					// enable PIE GP Timer 1 compare interrupt                    
	IER = 2;
	EINT;
	ERTM;

	EvaRegs.T1CNT = 0x0000;			
	EvaRegs.T1PR = 0x1312;								// period value for 12.8khz carrier pwm freq
	EvaRegs.T1CMPR = 0x0989;							// 50% duty cycle

	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.EVAIMRA.bit.T1CINT = 0;						// enable GP Timer 1 compare interrupt
	EvaRegs.T1CON.all = 0x1042;							// Enable GP Timer 
	for(;;);
}
void InitSystem()
{
		EALLOW;
	   	SysCtrlRegs.WDCR= 0x0068;						// Setup the watchdog 
   														// 0x0068  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;
}
void T1_Compare_isr(void)
{
		static int index=0;
		EvaRegs.T1CMPR =  EvaRegs.T1PR - _IQsat(_IQ30mpy(sine_table[index]+_IQ30(0.9999),EvaRegs.T1PR/2),EvaRegs.T1PR,0);
	    index +=1; 
		if (index >511) index = 0;
		   
 		EvaRegs.EVAIFRA.bit.T1CINT = 1;				 	// Reset T1 Compare Interrupt Flag
   	PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;			// Acknowledge this interrupt to receive more interrupts from group 2
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.