Vous êtes sur la page 1sur 13

LAB EXERCISE

GENERATE 1Khz PWM USING TMS320F2812 DSP

GENERATE 1Khz PWM USING TMS320F2812 DSP Aim To Generate the 1 Khz PWM 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. 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)

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

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. 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 8. Project Add files to project. a. In file of type : All files b. Ctrl + Select the following files Join the Technical Community Today! http://www.pantechsolutions.net

projectname.c DSP281x_GlobalVariableDefs.c F2812_EzDSP_RAM_lnk.cmd DSP281x_Headers_nonBIOS.cmd open. 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 Join the Technical Community Today! http://www.pantechsolutions.net

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 // DSP281x Examples Include // Prototype statements for functions found within this file. void InitSystem(void); void main(void) { InitSystem(); Join the Technical Community Today! http://www.pantechsolutions.net

#include "DSP281x_Examples.h" File

EALLOW; GpioMuxRegs.GPAMUX.all = 0x01FF; // EVA PWM 1-6 pins GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins EDIS; DINT; EvaRegs.T1PR = 0xF424; EvaRegs.T1CMPR = 0x7A12; EvaRegs.T1CNT = 0x0000; // Timer1 period // Timer1 compare // Timer1 counter // TMODE = continuous

EvaRegs.T1CON.all = 0x1042; up & Timer enable EvaRegs.T2PR = 0xF424; EvaRegs.T2CMPR = 0x7A12; EvaRegs.T2CNT = 0x0000;

// Timer2 period // Timer2 compare // Timer2 counter

EvaRegs.T2CON.all = 0x1042; EvaRegs.GPTCONA.bit.TCMPOE = 1; by compare logic // Drive T1/T2 PWM

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

EvaRegs.GPTCONA.bit.T1PIN = 1; Compare = Active low EvaRegs.GPTCONA.bit.T2PIN = 2; Compare = Active high EvaRegs.CMPR1 = 0x7A12; PWM1-PWM6 EvaRegs.CMPR2 = 0x7A12; EvaRegs.CMPR3 = 0x7A12; EvaRegs.ACTRA.all = 0x0666;

// Polarity of GP Timer 1 // Polarity of GP Timer 2 // Enable compare for

EvaRegs.DBTCONA.all = 0x0530; // Disable deadband EvaRegs.COMCONA.all = 0xA600; EvaRegs.CAPCONA.bit.CAPRES = 0; // to zero EvaRegs.CAPCONA.all = 0x2240; gp timer 1 & detecting rising edge EvaRegs.CAPFIFOA.all = 0x0100; for(;;); } Join the Technical Community Today! http://www.pantechsolutions.net reset all capture regs

// enable CAP1, selcting

void InitSystem(void) { EALLOW; SysCtrlRegs.WDCR= 0x0068; Watchdog , Prescaler = 1 // 0x00AF to NOT disable the Watchdog, Prescaler = 64 SysCtrlRegs.SCSR = 0; RESET // Watchdog generates a // Setup the watchdog // 0x00E8 to disable the

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

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.

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