You have no items in your shopping cart.

Subtotal: 0.00

Aim

To Generate the 50 Hz SINE PWM using look up table 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.

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.





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.

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.     -  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

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" 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,9548, 10317,11080,11837,12586,13328,14061,14786,15502,16208,16905, 17592,18267,18932,19585,20226,20855,21472,22075,22665,23241, 23803,24351,24883,25401,25903,26390,26860,27315,27752,28173, 28577,28963,29332,29683,30016,30330,30627,30904,31163,31403, 31624,31826,32008,32171,32315,32439,32543,32627,32692,32737, 32761,32766,32751,32717,32662,32587,32493,32379,32246,32092, 31920,31728,31516,31286,31036,30768,30481,30175,29851,29510, 29150,28772,28377,27965,27536,27090,26627,26149,25654,25144, 24619,24079,23524,22955,22372,21775,21165,20542,19907,19260, 18601,17931,17250,16558,15856,15145,14425,13695,12958,12212, 11459,10700,9933,9161,8383,7600,6813,6021,5226,4427,3626,2822, 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, ­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 }; 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 = 0x186A; EvaRegs.T1CMPR = 0x0C35; 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 = 1; EvaRegs.T1CON.all = 0x1042; 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) { Index1 = Index1 + 327; ////////////// Step_freq = 327 ;;;frequency if(Index1>65536) Index1=0; Sine_Loc1 = Index1 >> 8; Sine_Value1 = lookup[Sine_Loc1]; Value1 = (Sine_Value1 * (long)2812) >> 15; //////amplitude EvaRegs.T1CMPR = Value1 + 0x0c35; 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 }

Result

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