You are on page 1of 19

LAB EXERCISE

50Hz SINE PWM USING TMS320F2812 DSP

50HZ SINE PWM USING TMS320F2812 DSP Aim To Generate the 50 Hz SINE PWM using look up 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. Join the Technical Community Today! http://www.pantechsolutions.net

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 Join the Technical Community Today! http://www.pantechsolutions.net

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 Join the Technical Community Today! http://www.pantechsolutions.net

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.

Join the Technical Community Today! http://www.pantechsolutions.net

Procedure Note: Once you install the Code Composer Studio v 3.3 software, the two icons will display in desktop I. Setup Code Composer Studio v3.3 II. Code Composer Studio 1. Open Setup Code Composer Studio v3.3. 2. In System Configuration, select the board then Remove all yes. a. In family, select C28xx. b. In platform, select xds100 usb emulator. c. In Endianness, select little. d. 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. a. Project name: type the project name. b. Location: Browse, select the project location . c. Project Type: Executable(.out) d. Target: TMS320C28XX. Finish. Join the Technical Community Today! http://www.pantechsolutions.net

5. File New Source file. a. Type the program in untitled window. 6. File Save. a. 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. a. F2812_EzDSP_RAM_lnk.cmd b. DSP281x_Headers_nonBIOS.cmd c. DSP281x_GlobalVariableDefs.c d. DSP281x_DefaultIsr.c e. DSP281x_PieCtrl.c f. DSP281x_PieVect.c 8. Project Add files to project. a. In file of type : All files b. Ctrl + Select the following files projectname.c DSP281x_GlobalVariableDefs.c DSP281x_DefaultIsr.c DSP281x_PieCtrl.c DSP281x_PieVect. F2812_EzDSP_RAM_lnk.cmd DSP281x_Headers_nonBIOS.cmd open. Join the Technical Community Today! http://www.pantechsolutions.net

9. Project Build Option. a. In compiler tab, select Preprocessor Include search path(-i): C:\tidcs\c28\DSP281x\v120\DSP281x_headers\includ e b. In linker tab, select libraries Search path(-i): C:\CCStudio_v3.3\C2000\cgtools\lib Incl libraries(-l): rts2800_ml.lib. c. In linker tab, select Basic Stack Size(-stack): 0x400 ok. 10. Project Build (or) Rebuild all. 11. Connections for TMS320F2812 KIT: a. Connect 5v adpter to TMS320F2812 kit. b. Connect usb cable to TMS320F2812 kit from pc. c. 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 & probe negative terminal to Ground. 17. Debug Halt. Join the Technical Community Today! http://www.pantechsolutions.net

Program #include "DSP281x_Device.h" void InitSystem(void); void InitPieCtrl(); void InitPieVectTable(); interrupt void T1_Compare_isr(void); unsigned int Index1=0; signed int Sine_Value1=0,Value1=0,Sine_Loc1=0; signed int lookup[256] ={0,807,1614,2420,3224,4027,4827,5624,6417,7207,7992,8773,9 548, 10317,11080,11837,12586,13328,14061,14786,15502,16208,169 05, 17592,18267,18932,19585,20226,20855,21472,22075,22665,232 41,

Join the Technical Community Today! http://www.pantechsolutions.net

23803,24351,24883,25401,25903,26390,26860,27315,27752,281 73, 28577,28963,29332,29683,30016,30330,30627,30904,31163,314 03, 31624,31826,32008,32171,32315,32439,32543,32627,32692,327 37, 32761,32766,32751,32717,32662,32587,32493,32379,32246,320 92, 31920,31728,31516,31286,31036,30768,30481,30175,29851,295 10, 29150,28772,28377,27965,27536,27090,26627,26149,25654,251 44,

Join the Technical Community Today! http://www.pantechsolutions.net

24619,24079,23524,22955,22372,21775,21165,20542,19907,192 60, 18601,17931,17250,16558,15856,15145,14425,13695,12958,122 12, 11459,10700,9933,9161,8383,7600,6813,6021,5226,4427,3626,2 822, 2017,1211,404,-404,-1211,-2017,2822,-3626,-4427,-5226,-6021, -6813,-7600,-8383,-9161,-9933,10700,-11459,-12212,-12958,-13695, -14425,-15145,-15856,-16558,17250,-17931,-18601,-19260,-19907, -20542,-21165,-21775,-22372,22955,-23524,-24079,-24619,-25144, -25654,-26149,-26627,-27090,27536,-27965,-28377,-28772,-29150, Join the Technical Community Today! http://www.pantechsolutions.net

-29510,-29851,-30175,-30481,30768,-31036,-31286,-31516,-31728, -31920,-32092,-32246,-32379,32493,-32587,-32662,-32717,-32751, -32766,-32761,-32737,-32692,32627,-32543,-32439,-32315,-32171, -32008,-31826,-31624,-31403,31163,-30904,-30627,-30330,-30016, -29683,-29332,-28963,-28577,28173,-27752,-27315,-26860,-26390, -25903,-25401,-24883,-24351,23803,-23241,-22665,-22075,-21472, -20855,-20226,-19585,-18932,18267,-17592,-16905,-16208,-15502, -14786,-14061,-13328,-12586,11837,-11080,-10317,-9548,-8773, -7992,-7207,-6417,-5624,-4827,4027,-3224,-2420,-1614,-807, 0 }; Join the Technical Community Today! http://www.pantechsolutions.net

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; //

Join the Technical Community Today! http://www.pantechsolutions.net

EvaRegs.T1CNT = 0x0000; EvaRegs.T1PR = 0x186A; EvaRegs.T1CMPR = 0x0C35; EvaRegs.GPTCONA.bit.TCMPOE = 1; by compare logic // Drive T1/T2 PWM

EvaRegs.GPTCONA.bit.T1PIN = 1; // Polarity of GP Timer 1 Compare = Active low EvaRegs.EVAIMRA.bit.T1CINT = 1; EvaRegs.T1CON.all = 0x1042; for(;;); } void InitSystem() { EALLOW; SysCtrlRegs.WDCR= 0x0068; watchdog // Setup the

// 0x0068 to disable the Watchdog , Prescaler = 1 Join the Technical Community Today! http://www.pantechsolutions.net

// 0x00AF to NOT disable the Watchdog, Prescaler = 64 SysCtrlRegs.SCSR = 0; 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; Join the Technical Community Today! http://www.pantechsolutions.net // Watchdog generates a

SysCtrlRegs.PCLKCR.bit.ADCENCLK=0; EDIS; } void T1_Compare_isr(void) { Index1 = Step_freq = 327 ;;;frequency if(Index1>65536) Index1=0; Sine_Loc1 Sine_Value1 Value1 //////amplitude EvaRegs.T1CMPR = = = = Index1 >> 8; lookup[Sine_Loc1]; (Sine_Value1 * (long)2812) >> 15; Value1 + 0x0c35; // Reset T1 Index1 + 327; //////////////

EvaRegs.EVAIFRA.bit.T1CINT = 1; Compare Interrupt Flag

Join the Technical Community Today! http://www.pantechsolutions.net

PieCtrlRegs.PIEACK.all = PIEACK_GROUP2; // Acknowledge this interrupt to receive more interrupts from group 2 }

Result Thus, the 50Hz SPWM was generated using sine look up table in TMS320F2812 Kit.

Join the Technical Community Today! http://www.pantechsolutions.net

Did you enjoy the read?


Pantech solutions creates information packed technical documents like this one every month. And our website is a rich and trusted resource used by a vibrant online community of more than 1,00,000 members from organization of all shapes and sizes.

Join the Technical Community Today! http://www.pantechsolutions.net

What do we sell?
Our products range from Various Microcontroller development boards, DSP Boards, FPGA/CPLD boards, Communication Kits, Power electronics, Basic electronics, Robotics, Sensors, Electronic components and much more . Our goal is to make finding the parts and information you need easier and affordable so you can create awesome projects and training from Basic to Cutting edge technology.

Join the Technical Community Today! http://www.pantechsolutions.net

You might also like