Programs For DSP
Programs For DSP
Programs For DSP
#include "DSP2833x_Device.h"
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
//###########################################################################
// main code
//###########################################################################
void main(void)
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);
long i;
asm(" NOP");
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
void Gpio_select(void)
EALLOW;
GpioCtrlRegs.GPADIR.all = 0;
EDIS;
void InitSystem(void)
EALLOW;
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
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
#include "DSP2833x_Device.h"
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
//###########################################################################
// main code
//###########################################################################
void main(void)
unsigned int i;
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
long i;
asm(" NOP");
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
void Gpio_select(void)
EALLOW;
GpioCtrlRegs.GPADIR.all = 0;
GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9
EDIS;
void InitSystem(void)
EALLOW;
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
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
// and copy the value to 4 LEDs GPIO9, GPIO11, GPIO34 and GPIO49
#include "DSP2833x_Device.h"
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
//###########################################################################
// main code
//###########################################################################
void main(void)
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);
long i;
asm(" NOP");
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
void Gpio_select(void)
EALLOW;
GpioCtrlRegs.GPADIR.all = 0;
EDIS;
void InitSystem(void)
EALLOW;
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
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
// and LD4(GPIO49)
// watchdog enabled
// solution file for Lab5_4
#include "DSP2833x_Device.h"
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
//###########################################################################
// main code
//###########################################################################
void main(void)
long delay;
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;
long i;
asm(" NOP");
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
void Gpio_select(void)
EALLOW;
GpioCtrlRegs.GPADIR.all = 0;
EDIS;
void InitSystem(void)
EALLOW;
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
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
// and LD4(GPIO49)
// watchdog enabled
#include "DSP2833x_Device.h"
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
//###########################################################################
// main code
//###########################################################################
void main(void)
long delay;
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;
counter++;
long i;
do
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA; // service watchdog
EDIS;
while(!run);
void Gpio_select(void)
EALLOW;
GpioCtrlRegs.GPADIR.all = 0;
EDIS;
}
void InitSystem(void)
EALLOW;
SysCtrlRegs.PLLSTS.bit.DIVSEL = 2;
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
#include "DSP2833x_Device.h"
void Gpio_select(void);
interrupt void cpu_timer0_isr(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
CpuTimer0.InterruptCount = 0;
EALLOW;
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.GPADIR.all = 0;
EDIS;
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
//
// Lab7_1: TMS320F28335
#include "DSP2833x_Device.h"
void Gpio_select(void);
void Setup_ePWM1A(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100000);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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;
EDIS;
void Setup_ePWM1A(void)
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//
// Lab7_2: TMS320F28335
// TITLE: DSP28335ControlCARD;
#include "DSP2833x_Device.h"
void Gpio_select(void);
void Setup_ePWM(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100000);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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.GPADIR.all = 0;
EDIS;
void Setup_ePWM(void)
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
EPwm2Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm2Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
EPwm3Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//
// Lab7_3: TMS320F28335
#include "DSP2833x_Device.h"
void Gpio_select(void);
void Setup_ePWM1A(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
{
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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;
EDIS;
void Setup_ePWM1A(void)
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
// clear ePWM1A
on CMPA down
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
if(up_down)
else up_down = 0;
else
else up_down = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
//
// Lab7_4: TMS320F28335
#include "DSP2833x_Device.h"
void Gpio_select(void);
void Setup_ePWM1(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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.GPADIR.all = 0;
EDIS;
void Setup_ePWM1(void)
{
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
// clear ePWM1A
on CMPA down
// set ePWM1B
on CMPA down
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
if(up_down)
else up_down = 0;
else
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
//
// Lab7_5: TMS320F28335
#include "DSP2833x_Device.h"
void Gpio_select(void);
void Setup_ePWM1(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
{
int counter=0; // binary counter for digital output
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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.GPADIR.all = 0;
EDIS;
void Setup_ePWM1(void)
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
// clear ePWM1A
on CMPA down
// clear ePWM1B on
CMPB down
EPwm1Regs.TBPRD = 37500; // 1KHz - PWM signal
EPwm1Regs.CMPB = EPwm1Regs.TBPRD / 2;
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
//
// Lab7_6: TMS320F28335
#include "DSP2833x_Device.h"
void Setup_ePWM1(void);
//###########################################################################
// main code
//###########################################################################
void main(void)
EALLOW;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
EDIS;
ConfigCpuTimer(&CpuTimer0,150,100);
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |=1;
EINT;
ERTM;
while(1)
while(CpuTimer0.InterruptCount == 0);
CpuTimer0.InterruptCount = 0;
EALLOW;
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.GPADIR.all = 0;
EDIS;
void Setup_ePWM1(void)
{
EPwm1Regs.TBCTL.bit.CLKDIV = 0; // CLKDIV = 1
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 1; // HSPCLKDIV = 2
// clear ePWM1A
on CMPA down
CpuTimer0.InterruptCount++;
EALLOW;
EDIS;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;