LED BLINKING USING DSP BY CPU TIMERS
To
blink LED using Switch by using 4-GPIO Pins that are connected to 4- LED’s at
the Peripheral Explorer Board.
SOFTWARE:
Code Composer Studio
HARDWARE REQUIRED:
DSP controller board (TMS320F28335), JTAG,
XDS100V2 board
THEORY:
A Light Emitting Diodes (LEDs)
are the most commonly used components, usually for displaying pin’s digital
states.
The TMS320F28335 board has 4- LED Connected
with DSP general-purpose I/O pins. The Anode of each LED connects
to ground and Cathode of each LED connects port via
220Ω resistor. To light an individual LED, drive the associated
port signal to High.
The general-purpose input/output (GPIO)
peripheral in the TMS320 Digital Signal Processor (DSP). The GPIO peripheral
provides dedicated general-purpose pins that can be configured as either inputs
or outputs. When configured as an input, we can detect the state of the input
by reading the state of an internal register. When configured as an output, we
can write to an internal register to control the state driven on the output
pin.
Embedded
‘C’ CODE for LED Blinking:
#include "DSP2833x_Device.h"
// Prototype statements for functions found
within this file.
void Gpio_select(void);
void InitSystem(void);
void delay_loop(long);
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)
{
switch(counter&3)
{
case
0:
GpioDataRegs.GPASET.bit.GPIO9 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;
break;
case
1:
GpioDataRegs.GPASET.bit.GPIO11 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;
break;
case
2:
GpioDataRegs.GPBSET.bit.GPIO34 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO49 = 1;
break;
case
3:
GpioDataRegs.GPBSET.bit.GPIO49 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO11 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
break;
}
counter++;
delay_loop(10000000);
}
}
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;
//0x0028 to Watchdog enabled, 4.3 milliseconds, 0xE8 to disable
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;
}
OBSERVATION:
The LED is blinked in the fashion that the first LED with the
minimum blinking, the second one with the more and it keeps the frequency of blink
increasing.
RESULT:
Hence by the above code, we have blinked
the LED with the 4 GPIO Pins.
Post a Comment
Please do not enter any spam links in the comments...