Programs For DSP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

// Lab5_1: TMS320F28335

// TITLE: DSP28335ControlCARD; Digital Output

// 4 - bit - counter at 4 LEDs LD1(GPIO9), LD2(GPIO11), LD3(GPIO34)

// and LD4 (GPIO49)

// software delay loop; watchdog disabled

// template file for Lab5_1

#include "DSP2833x_Device.h"

// Prototype statements for functions found within this file.

void Gpio_select(void);

void InitSystem(void);

void delay_loop(long);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSystem(); // Basic Core Initialization

DINT; // Disable all interrupts

Gpio_select(); // GPIO9,GPIO11,GPIO34 and GPIO49 as output (LEDs @ peripheral


explorer)

while(1)

counter++;
if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

delay_loop(1000000);

void delay_loop(long end)

long i;

for (i = 0; i < end; i++)

asm(" NOP");

EALLOW;

SysCtrlRegs.WDKEY = 0x55;

SysCtrlRegs.WDKEY = 0xAA;

EDIS;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO00 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O


GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void InitSystem(void)

EALLOW;

SysCtrlRegs.WDCR = 0x0028; // Watchdog enabled, 4.3 milliseconds

SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;

SysCtrlRegs.PLLCR.bit.DIV = 10; // 30MHz * 10 / 2 = 150 MHz

SysCtrlRegs.HISPCP.all = 0x0001;

SysCtrlRegs.LOSPCP.all = 0x0002;

SysCtrlRegs.PCLKCR0.all = 0x0000;

SysCtrlRegs.PCLKCR1.all = 0x0000;

SysCtrlRegs.PCLKCR3.all = 0x0000;

SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;

EDIS;

//
// Lab5_2: TMS320F28335

// TITLE: DSP28335ControlCARD; Digital Output

// 4 - bit "knight rider" at 4 LEDs LD1(GPIO9), LD2(GPIO11), LD3(GPIO34)

// and LD4 (GPIO49)

// software delay loop; watchdog enabled

// solution file for Lab5_2

#include "DSP2833x_Device.h"

// Prototype statements for functions found within this file.

void Gpio_select(void);

void InitSystem(void);

void delay_loop(long);

//###########################################################################

// main code

//###########################################################################

void main(void)

unsigned int i;

InitSystem(); // Basic Core Initialization

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

while(1)

for(i=0;i<6;i++)

{
switch (i)

case 0:
// LEDs: 0001

GpioDataRegs.GPASET.bit.GPIO9 = 1;

GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;

case 1:
// LEDs: 0010

GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPASET.bit.GPIO11 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;

case 2:
// LEDs: 0100

GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

GpioDataRegs.GPBSET.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;

case 3:
// LEDs: 1000

{
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

GpioDataRegs.GPBSET.bit.GPIO49 = 1;

break;

case 4:
// LEDs: 0100

GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

GpioDataRegs.GPBSET.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;

case 5:
// LEDs: 0010

GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPASET.bit.GPIO11 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;

default:
// LEDs: 0000

GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

break;
}

} // end switch

delay_loop(1000000);

} // end for

} // end while(1)

} // end main

void delay_loop(long end)

long i;

for (i = 0; i < end; i++)

asm(" NOP");

EALLOW;

SysCtrlRegs.WDKEY = 0x55;

SysCtrlRegs.WDKEY = 0xAA;

EDIS;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void InitSystem(void)

EALLOW;

SysCtrlRegs.WDCR = 0x0028; // Watchdog enabled, 4.3 milliseconds

SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;

SysCtrlRegs.PLLCR.bit.DIV = 10; // 30MHz * 10 / 2 = 150 MHz

SysCtrlRegs.HISPCP.all = 0x0001;

SysCtrlRegs.LOSPCP.all = 0x0002;

SysCtrlRegs.PCLKCR0.all = 0x0000;

SysCtrlRegs.PCLKCR1.all = 0x0000;

SysCtrlRegs.PCLKCR3.all = 0x0000;

SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;

EDIS;

//
// Lab5_3: TMS320F28335

// TITLE: DSP28335ControlCARD and Peripheral Explorer Board

// Digital Input and Digital Output

// read value from 4 -Bit Hex - Encoder (GPIO12...GPIO15)

// and copy the value to 4 LEDs GPIO9, GPIO11, GPIO34 and GPIO49

// software delay loop; watchdog enabled

// solution file for Lab5_3

#include "DSP2833x_Device.h"

// Prototype statements for functions found within this file.

void Gpio_select(void);

void InitSystem(void);

void delay_loop(long);

//###########################################################################

// main code

//###########################################################################

void main(void)

InitSystem(); // Basic Core Initialization

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

while(1)

GpioDataRegs.GPADAT.bit.GPIO9 = GpioDataRegs.GPADAT.bit.GPIO12;

GpioDataRegs.GPADAT.bit.GPIO11 = GpioDataRegs.GPADAT.bit.GPIO13;

GpioDataRegs.GPBDAT.bit.GPIO34 = GpioDataRegs.GPADAT.bit.GPIO14;
GpioDataRegs.GPBDAT.bit.GPIO49 = GpioDataRegs.GPADAT.bit.GPIO15;

delay_loop(1000000);

void delay_loop(long end)

long i;

for (i = 0; i < end; i++)

asm(" NOP");

EALLOW;

SysCtrlRegs.WDKEY = 0x55;

SysCtrlRegs.WDKEY = 0xAA;

EDIS;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9


GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void InitSystem(void)

EALLOW;

SysCtrlRegs.WDCR = 0x0028; // Watchdog enabled, 4.3 milliseconds

SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;

SysCtrlRegs.PLLCR.bit.DIV = 10; // 30MHz * 10 / 2 = 150 MHz

SysCtrlRegs.HISPCP.all = 0x0001;

SysCtrlRegs.LOSPCP.all = 0x0002;

SysCtrlRegs.PCLKCR0.all = 0x0000;

SysCtrlRegs.PCLKCR1.all = 0x0000;

SysCtrlRegs.PCLKCR3.all = 0x0000;

SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;

EDIS;

//

// Lab5_4: TMS320F28335

// TITLE: DSP28335ControlCARD; Digital Output

// 4 - bit - counter at LEDs LD1 (GPIO9), LD2(GPIO11), LD3(GPIO34)

// and LD4(GPIO49)

// software delay loop controlled by 4-bit hex encoder (GPIO12...15)

// watchdog enabled
// solution file for Lab5_4

#include "DSP2833x_Device.h"

// Prototype statements for functions found within this file.

void Gpio_select(void);

void InitSystem(void);

void delay_loop(long);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

long delay;

InitSystem(); // Basic Core Initialization

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

while(1)

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

// read GPIO15..12 only

delay = (GpioDataRegs.GPADAT.all >> 12) &0x0000000F;

delay_loop((delay+1)*577000); // 100 ms take aprox.577000 loops

void delay_loop(long end)

long i;

for (i = 0; i < end; i++)

asm(" NOP");

EALLOW;

SysCtrlRegs.WDKEY = 0x55;

SysCtrlRegs.WDKEY = 0xAA;

EDIS;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O


GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void InitSystem(void)

EALLOW;

SysCtrlRegs.WDCR = 0x0028; // Watchdog enabled, 4.3 milliseconds

SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;

SysCtrlRegs.PLLCR.bit.DIV = 10; // 30MHz * 10 / 2 = 150 MHz

SysCtrlRegs.HISPCP.all = 0x0001;

SysCtrlRegs.LOSPCP.all = 0x0002;

SysCtrlRegs.PCLKCR0.all = 0x0000;

SysCtrlRegs.PCLKCR1.all = 0x0000;

SysCtrlRegs.PCLKCR3.all = 0x0000;

SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;

EDIS;

}
// Lab5_5: TMS320F28335

// TITLE: DSP28335ControlCARD; Digital Output

// 4 - bit - counter at LEDs LD1 (GPIO9), LD2(GPIO11), LD3(GPIO34)

// and LD4(GPIO49)

// software delay loop controlled by 4-bit hex encoder (GPIO12...15)

// PB1 (GPIO17) = start; PB2(GPIO48) = stop

// watchdog enabled

#include "DSP2833x_Device.h"

#define START GpioDataRegs.GPADAT.bit.GPIO17 // Button PB1

#define STOP GpioDataRegs.GPBDAT.bit.GPIO48 // Button PB2

// Prototype statements for functions found within this file.

void Gpio_select(void);

void InitSystem(void);

void delay_loop(long);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

long delay;

InitSystem(); // Basic Core Initialization

DINT; // Disable all interrupts


Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

while(1)

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

// read GPIO15..12 only

delay = (GpioDataRegs.GPADAT.all >> 12) &0x0000000F;

delay_loop((delay+1)*308000); // 100 ms take aprox.308000 loops

counter++;

void delay_loop(long end)

long i;

static unsigned int run = 0; // control flag

for (i = 0; i < end; i++)

do

EALLOW;

SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA; // service watchdog

EDIS;

if(START == 0 && STOP == 1) run = 1; // run control code if PB1=0

while(!run);

if(STOP == 0) run = 0; // stop execution

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

}
void InitSystem(void)

EALLOW;

SysCtrlRegs.WDCR = 0x0028; // Watchdog enabled, 4.3 milliseconds

SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;

SysCtrlRegs.PLLCR.bit.DIV = 10; // 30MHz * 10 / 2 = 150 MHz

SysCtrlRegs.HISPCP.all = 0x0001;

SysCtrlRegs.LOSPCP.all = 0x0002;

SysCtrlRegs.PCLKCR0.all = 0x0000;

SysCtrlRegs.PCLKCR1.all = 0x0000;

SysCtrlRegs.PCLKCR3.all = 0x0000;

SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;

EDIS;

// Lab6: TMS320F28335

// TITLE: DSP28335ControlCARD; Digital Output

// 4 - bit - counter at 4 LEDs LD1(GPIO9), LD2(GPIO11), LD3(GPIO34)

// and LD4 (GPIO49)

// CPU Timer 0 period and Interrupt Service

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.

void Gpio_select(void);
interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;

EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2


ConfigCpuTimer(&CpuTimer0,150,100000); // CPU - Timer0 at 100 milliseconds

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)

while(CpuTimer0.InterruptCount == 0); //interrupt not received

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

}
void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

interrupt void cpu_timer0_isr(void)

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

//
// Lab7_1: TMS320F28335

// TITLE: DSP28335ControlCARD; ePWM1A 1KHz output

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.

void Gpio_select(void);

void Setup_ePWM1A(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64


DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

Setup_ePWM1A(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;

EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100000);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)

while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O


GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM1A(void)

EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0006; // ZRO = set 10, PRD = clear 01 0110=6

EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

interrupt void cpu_timer0_isr(void)

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}
//

// Lab7_2: TMS320F28335

// TITLE: DSP28335ControlCARD;

// 3 phase signal system

// 1KHz output at ePWM1A, ePWM2A and ePWM3A

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.

void Gpio_select(void);

void Setup_ePWM(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c


EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer)

Setup_ePWM(); // init of ePWM1, ePWM2 and ePWM3

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;

EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100000);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0


while(1)

while(CpuTimer0.InterruptCount == 0);

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // ePWM2A active

GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 1; // ePWM3A active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O


GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM(void)

EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0006; // ZRO = set, PRD = clear

EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm2Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm2Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm2Regs.AQCTLA.all = 0x0006; // ZRO = set, PRD = clear

EPwm2Regs.TBPRD = 37500; // 1KHz - PWM signal


EPwm3Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm3Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm3Regs.AQCTLA.all = 0x0006; // ZRO = set, PRD = clear

EPwm3Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; // generate a syncout if CTR = 0

EPwm2Regs.TBCTL.bit.PHSEN = 1; // enable phase shift for ePWM2

EPwm2Regs.TBCTL.bit.SYNCOSEL = 0; // syncin = syncout

EPwm2Regs.TBPHS.half.TBPHS = 12500; // 1/3 phase shift

EPwm3Regs.TBCTL.bit.PHSEN = 1; // enable phase shift for ePWM3

EPwm3Regs.TBPHS.half.TBPHS = 25000; // 2/3 phase shift

interrupt void cpu_timer0_isr(void)

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}
//

// Lab7_3: TMS320F28335

// TITLE: DSP28335ControlCARD; ePWM1A 1KHz output

// variable pulse width

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.

void Gpio_select(void);

void Setup_ePWM1A(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog


EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer

Setup_ePWM1A(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;

EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)
{

while(CpuTimer0.InterruptCount == 0);

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O


GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM1A(void)

EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up

// clear ePWM1A
on CMPA down

EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm1Regs.CMPA.half.CMPA = 0; // 100% duty cycle first

interrupt void cpu_timer0_isr(void)

static int up_down = 1;

CpuTimer0.InterruptCount++;
EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

if(up_down)

if(EPwm1Regs.CMPA.half.CMPA < EPwm1Regs.TBPRD)


EPwm1Regs.CMPA.half.CMPA++;

else up_down = 0;

else

if(EPwm1Regs.CMPA.half.CMPA > 0) EPwm1Regs.CMPA.half.CMPA--;

else up_down = 1;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

//

// Lab7_4: TMS320F28335

// TITLE: DSP28335ControlCARD; ePWM1A 1KHz output

// variable pulse width

// complementary signal at ePWM1B

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);


// Prototype statements for functions found within this file.

void Gpio_select(void);

void Setup_ePWM1(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer

Setup_ePWM1(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)

while(CpuTimer0.InterruptCount == 0);

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // ePWM1B active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM1(void)
{

EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up

// clear ePWM1A
on CMPA down

EPwm1Regs.AQCTLB.all = 0x0090; // clear ePWM1B on CMPA up

// set ePWM1B
on CMPA down

EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm1Regs.CMPA.half.CMPA = 0; // 100% duty cycle first

interrupt void cpu_timer0_isr(void)

static int up_down = 1;

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

if(up_down)

if(EPwm1Regs.CMPA.half.CMPA < EPwm1Regs.TBPRD)


EPwm1Regs.CMPA.half.CMPA++;

else up_down = 0;

else

if(EPwm1Regs.CMPA.half.CMPA > 0) EPwm1Regs.CMPA.half.CMPA--;


else up_down = 1;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

//

// Lab7_5: TMS320F28335

// TITLE: DSP28335ControlCARD; ePWM1A 1KHz output

// variable pulse width independently

// ePWM1A controlled by CMPA

// ePWM1B controlled by CMPB

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.

void Gpio_select(void);

void Setup_ePWM1(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

{
int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer Board

Setup_ePWM1(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;

EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;
EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)

while(CpuTimer0.InterruptCount == 0);

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;

if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active


GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // ePWM1B active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM1(void)

EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up

// clear ePWM1A
on CMPA down

EPwm1Regs.AQCTLB.all = 0x0600; // set ePWM1B on CMPB up

// clear ePWM1B on
CMPB down
EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm1Regs.CMPA.half.CMPA = EPwm1Regs.TBPRD / 2; // 50% duty cycle first

EPwm1Regs.CMPB = EPwm1Regs.TBPRD / 2;

interrupt void cpu_timer0_isr(void)

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

//

// Lab7_6: TMS320F28335

// TITLE: DSP28335ControlCARD; ePWM1A 1KHz output

// variable pulse width

// complementary signal at ePWM1B

// plus dead band rising edge delay

#include "DSP2833x_Device.h"

// external function prototypes

extern void InitSysCtrl(void);

extern void InitPieCtrl(void);

extern void InitPieVectTable(void);

extern void InitCpuTimers(void);

extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float);

// Prototype statements for functions found within this file.


void Gpio_select(void);

void Setup_ePWM1(void);

interrupt void cpu_timer0_isr(void);

//###########################################################################

// main code

//###########################################################################

void main(void)

int counter=0; // binary counter for digital output

InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c

EALLOW;

SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog

EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64

DINT; // Disable all interrupts

Gpio_select(); // GPIO9, GPIO11, GPIO34 and GPIO49 as output

// to 4 LEDs at Peripheral Explorer Board

Setup_ePWM1(); // init of ePWM1A

InitPieCtrl(); // basic setup of PIE table; from DSP2833x_PieCtrl.c

InitPieVectTable(); // default ISR's in PIE

EALLOW;

PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;

InitCpuTimers(); // basic setup CPU Timer0, 1 and 2

ConfigCpuTimer(&CpuTimer0,150,100);

PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

IER |=1;

EINT;

ERTM;

CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0

while(1)

while(CpuTimer0.InterruptCount == 0);

CpuTimer0.InterruptCount = 0;

EALLOW;

SysCtrlRegs.WDKEY = 0x55; // service WD #1

EDIS;

counter++;

if(counter&1) GpioDataRegs.GPASET.bit.GPIO9 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;

if(counter&2) GpioDataRegs.GPASET.bit.GPIO11 = 1;

else GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;

if(counter&4) GpioDataRegs.GPBSET.bit.GPIO34 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
if(counter&8) GpioDataRegs.GPBSET.bit.GPIO49 = 1;

else GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;

void Gpio_select(void)

EALLOW;

GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O

GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // ePWM1A active

GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // ePWM1B active

GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O

GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O

GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O

GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O

GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O

GpioCtrlRegs.GPADIR.all = 0;

GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9

GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11

GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs

GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34

GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49

GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs

EDIS;

void Setup_ePWM1(void)

{
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1

EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2

EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up - down mode

EPwm1Regs.AQCTLA.all = 0x0060; // set ePWM1A on CMPA up

// clear ePWM1A
on CMPA down

EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal

EPwm1Regs.CMPA.half.CMPA = 18750; // 50% duty cycle first

EPwm1Regs.DBRED = 750; // 10 microseconds delay

EPwm1Regs.DBFED = 750; // for rising and falling edge

EPwm1Regs.DBCTL.bit.OUT_MODE = 3; // ePWM1A = RED

EPwm1Regs.DBCTL.bit.POLSEL = 2; // S3=1 inverted signal at ePWM1B

EPwm1Regs.DBCTL.bit.IN_MODE = 0; // ePWM1A = source for RED & FED

interrupt void cpu_timer0_isr(void)

CpuTimer0.InterruptCount++;

EALLOW;

SysCtrlRegs.WDKEY = 0xAA; // service WD #2

EDIS;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy