Top Banner
Lab 2 EENG 3910: Project V - Digital Signal Processing System Design 9/21/2015 Joseph Chandler University of North Texas College of Engineering Electrical Engineering
30

DSP_Assign_2 (Autosaved)

Feb 21, 2017

Download

Documents

Joseph Chandler
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DSP_Assign_2 (Autosaved)

Lab 2

EENG 3910: Project V - Digital Signal Processing System Design

9/21/2015

Joseph Chandler

University of North Texas

College of Engineering

Electrical Engineering

Page 2: DSP_Assign_2 (Autosaved)

IntroductionLab 2 continues the study of the TivaTM C Series EK-TM4C123GXL and CCS software. Lab 2 has software driver libraries and types of system controls. The timing API and frequency are the main aspects of the system controls and different modules.

Results and Discussions

Problem 1

#include <stdint.h>

This line contains the header file for variable definitions. The header file is already defined in the CCS software. Examples of the values are bit size, precision, and signed or unsigned integers.

#include <stdbool.h>

This line contains the header file for Boolean definitions. The header file is already defined in the CCS software The file definitions are used for operations, comparing variables, and program control flow.

#include "inc/tm4c123gh6pm.h"

This line contains the header file for the TM4C123GH6PM microcontroller. The header file is part-specific and contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The .c file for the TM4C123GH6PM microcontroller is included in the project folder for direct access.

#include "inc/hw_memmap.h"

This line contains the header file for the Tiva C Series device memory map definitions. The header file contains many of the same definitions used for direct register access. The header file contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The definitions are used by driver libraries and are hidden from the programmer.

#include "inc/hw_types.h"

This line contains the header file for common types and macros. The header file contains many of the same definitions used for direct register access. This is contained in the inc directory. The definitions are used by driver libraries and are hidden from the programmer. The values are a wide variety of general use for items such as arithmetic, clock timing, file recognition, and device recognition.

#include "driverlib/sysctl.h"

Page 3: DSP_Assign_2 (Autosaved)

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/interrupt.h"

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/gpio.h"

This line contains the header file for GPIO API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The driver provides a set of functions to control the input and output module.

#include "driverlib/timer.h"

This line contains the header file for Timer API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The drivers provide quick control of the peripherals and allows for quick application. The timer API provides a set of functions for using the timer module.

#define TIMER0_FREQ 10

Creates a constant used for frequency in the Timer API macro with a value of 10 Hz.

void init_LEDs(void);

This line declares the function prototype "init_LEDs". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void init_timer(void);

This line declares the function prototype " init_timer ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void Timer0_ISR(void);

This line declares the function prototype " Timer0_ISR ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

uint32_t sys_clock;

Creates an unsigned 32-bit global variable for the system clock.

int main(void){

Page 4: DSP_Assign_2 (Autosaved)

The main process calls and acts on variables, macros, definitions, and other system functions.

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

System Control Clock Set sets the clocking of the device. Osc_Main configures the oscillator source. XTAL_16MHZ uses a 16 MHZ crystal clock. USE_PLL is a phase locked loop at 400MHZ. SYSDIV_5 divides the clock by the number specified giving control of the frequency

sys_clock = SysCtlClockGet();

This line retrieves the processor clock rate and assigns it to a variable.

init_LEDs();

Initializes LED configuration and enables by calling the function definition.

init_timer();

Initializes Timer configuration and enables by calling the function definition.

IntMasterEnable();

This NVIC API function enables interrupts from the microprocessor to interrupt controller.

TimerEnable(TIMER0_BASE, TIMER_A);

This TIMER API function enables operation of the timer module.

while(1) {

The while loop provides a continuous loop when set to "1".

void init_LEDs(void)

User-defined function definition for initializing LEDs. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

The System Control API function enables the GPIO port F peripheral.

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

The GPIO API function configures pins 1, 2, or 3 of port F for use as GPIO outputs.

void init_timer(void)

User-defined function definition for initializing TIMER0. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

The System Control API function enables TIMER0 peripheral.

Page 5: DSP_Assign_2 (Autosaved)

TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

The Timer API function configures the timer as a 32-bit full-width periodic timer.

TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The Timer API function specifies the base address for configuration, the correct name for a full-width timer, and the load value specified by user-defined constants.

IntRegister(INT_TIMER0A, Timer0_ISR);

The NVIC API function registers the "TIMER0_ISR" function to be called when the "TIMER0A" interrupt is enabled.

IntEnable(INT_TIMER0A);

The NVIC API function enables "TIMER0A" as a full-width timer to be used for the interrupt function process.

TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

The Timer API function enables the specific timer module(TIMER0_Base) for the timer interrupt source. The bit mask of the interrupt source to be enabled is "TIMER_TIMA_TIMEOUT".

void Timer0_ISR(void)

User-defined function definition for interrupt handler. The function returns a value of 0.

TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

The Timer API function clears the timer interrupt sources. TIMER0 is the base specified and "TIMER_TIMA_TIMEOUT" is the bit mask for the interrupt source cleared.

if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) {

If the GPIO API function reads pin 2 from port F, read line 88.

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);

The GPIO API function writes a 0 to pins 1,2, or 3 clearing the blue LED.

else {

Else the GPIO API function ...

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);

Writes the value of 4 to pin 2 displaying the blue LED.

Port F interface

Page 6: DSP_Assign_2 (Autosaved)

The GPIO API function configures port F for output. It further specifies that pins 1,2, and 3, in port F, will be used for output. The launchpad schematic shows Port F has 5 pins. Pin 1 is the red LED, Pin 2 is the blue LED, and Pin 3 is the green LED. The remaining pins (0 and 4) are for the USR SV. After the GPIO function configures the pins as output, it can write values of 2, 3, and 4 for red, green, and blue, respectively. The program actually writes a "4" to the pin 2 which operates the blue LED.

Calculated TIMER0_FREQ

Timer0_Freq 1 2 5 10Calculated 1Hz 2Hz 5Hz 10Hz

#define TIMER0_FREQ 1SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);sys_clock = SysCtlClockGet(); TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The TimerLoadSet function has a parameter for the "load value". The load value is "sys_clock/TIMER0_FREQ -1". This sets the period for the timer. The sys_clock variable is set to the value of the system clock. The system clock is configured for 40 MHz. The TIMER0_FREQ variable is set to 1. Therefore, 40,000,000/1 = 1 period 1/period = frequency1/40,000,000 = 0.000000025 = frequency of timer

The timer is enabled along with the running system clock. The frequencies of both the timer and system clock must be taken into account for the overall frequency of the interrupt caused by enabling the timer. Therefore,

frequency of timer * frequency of system clock = frequency of timer interrupt0.000000025 * 40,000,000 = 1 Hz

#define TIMER0_FREQ 2SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);sys_clock = SysCtlClockGet(); TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The TimerLoadSet function has a parameter for the "load value". The load value is "sys_clock/TIMER0_FREQ -1". This sets the period for the timer. The sys_clock variable is set to the value of the system clock. The system clock is configured for 40 MHz. The TIMER0_FREQ variable is set to 2. Therefore, 40,000,000/2 = 1 period 1/period = frequency1/20,000,000 = 0.00000005 = frequency of timer

Page 7: DSP_Assign_2 (Autosaved)

The timer is enabled along with the running system clock. The frequencies of both the timer and system clock must be taken into account for the overall frequency of the interrupt caused by enabling the timer. Therefore,

frequency of timer * frequency of system clock = frequency of timer interrupt0.00000005 * 40,000,000 = 2 Hz

#define TIMER0_FREQ 5SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);sys_clock = SysCtlClockGet(); TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The TimerLoadSet function has a parameter for the "load value". The load value is "sys_clock/TIMER0_FREQ -1". This sets the period for the timer. The sys_clock variable is set to the value of the system clock. The system clock is configured for 40 MHz. The TIMER0_FREQ variable is set to 5. Therefore, 40,000,000/5 = 1 period 1/period = frequency1/8,000,000 = 0.000000125 = frequency of timer

The timer is enabled along with the running system clock. The frequencies of both the timer and system clock must be taken into account for the overall frequency of the interrupt caused by enabling the timer. Therefore,

frequency of timer * frequency of system clock = frequency of timer interrupt0.000000125 * 40,000,000 = 5 Hz

#define TIMER0_FREQ 10 SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);sys_clock = SysCtlClockGet(); TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The TimerLoadSet function has a parameter for the "load value". The load value is "sys_clock/TIMER0_FREQ -1". This sets the period for the timer. The sys_clock variable is set to the value of the system clock. The system clock is configured for 40 MHz. The TIMER0_FREQ variable is set to 10. Therefore, 40,000,000/10 = 1 period 1/period = frequency1/4,000,000 = 0.00000025 = frequency of timer

The timer is enabled along with the running system clock. The frequencies of both the timer and system clock must be taken into account for the overall frequency of the interrupt caused by enabling the timer. Therefore,

frequency of timer * frequency of system clock = frequency of timer interrupt

Page 8: DSP_Assign_2 (Autosaved)

0.00000025 * 40,000,000 = 10 Hz

Captured Oscilloscope Signal Waveform

Figure 1 10 Hz

Page 9: DSP_Assign_2 (Autosaved)

Figure 2 5 Hz

Figure 3 2 Hz

Page 10: DSP_Assign_2 (Autosaved)

Figure 4 1 Hz

Problem 2

/************************************************* Blink LEDs on Tiva C Series LaunchPad with SysTick timer.

By Dr. Xinrong Li, [email protected], Aug. 25, 2014 Adapted from Tiva example code. *************************************************/Comments about the program usually by the programmer.

#include <stdint.h>

This line contains the header file for variable definitions. The header file is already defined in the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. Examples of the values are bit size, precision, and signed or unsigned integers.

#include <stdbool.h>

Page 11: DSP_Assign_2 (Autosaved)

This line contains the header file for Boolean definitions. The header file is already defined in the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The file definitions are used for operations, comparing variables, and program control flow.

#include "inc/tm4c123gh6pm.h"

This line contains the header file for the TM4C123GH6PM microcontroller. The header file is part-specific and contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The .c file for the TM4C123GH6PM microcontroller is included in the project folder for direct access.

#include "inc/hw_memmap.h"

This line contains the header file for the Tiva C Series device memory map definitions. The header file contains many of the same definitions used for direct register access. The header file contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The definitions are used by driver libraries and are hidden from the programmer.

#include "inc/hw_types.h"

This line contains the header file for common types and macros. The header file contains many of the same definitions used for direct register access. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The definitions are used by driver libraries and are hidden from the programmer. The values are a wide variety of general use for items such as arithmetic, clock timing, file recognition, and device recognition.

#include "driverlib/sysctl.h"

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/interrupt.h"

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/gpio.h"

Page 12: DSP_Assign_2 (Autosaved)

This line contains the header file for GPIO API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The driver provides a set of functions to control the input and output module.

#include "driverlib/systick.h"

This line contains the header file for Timer API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide quick control of the peripherals and allows for quick application. The timer API provides a set of functions for using the timer module.

#define TIMER0_FREQ 10

Creates a constant used for frequency in the Timer API macro with a value of 10 Hz.

void init_LEDs(void);

This line declares the function prototype "init_LEDs". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void init_timer(void);

This line declares the function prototype " init_timer ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void Timer0_ISR(void);

This line declares the function prototype " Timer0_ISR ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

uint32_t sys_clock;

Creates an unsigned 32-bit global variable for the system clock.

int main(void){

The main process calls and acts on variables, macros, definitions, and other system functions.

SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

System Control Clock Set sets the clocking of the device. Osc_Main configures the oscillator source. XTAL_16MHZ uses a 16 MHZ crystal clock. USE_PLL is a phase locked loop at 400MHZ. SYSDIV_2_5 divides the clock by the number specified giving control of the frequency.

Page 13: DSP_Assign_2 (Autosaved)

sys_clock = 80000000;

This line retrieves the processor clock rate and assigns it to a variable.

init_LEDs();

Initializes LED configuration and enables by calling the function definition.

init_SysTick();

Initializes SysTick configuration and enables by calling the function definition.

IntMasterEnable();

This NVIC API function enables interrupts from the microprocessor to interrupt controller.

SysTickEnable();

This SysTick API function enables operation of the timer module.

while(1) {

The while loop provides a continuous loop when set to "1".

void init_LEDs(void)

User-defined function definition for initializing LEDs. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

The System Control API function enables the GPIO port F peripheral.

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

The GPIO API function configures pins 1, 2, and 3 of port F for use as GPIO outputs.

void init_SysTick(void)

User-defined function definition for initializing SysTick. The function returns a value of 0.

SysTickPeriodSet(sys_clock/TIMER0_FREQ);

The SysTick API function configures the value specified by user-defined constants.

SysTickIntRegister(SysTick_ISR);

The NVIC API function registers the "SysTick_ISR" function to be called when the "SysTick" interrupt is enabled.

SysTickIntEnable();

Page 14: DSP_Assign_2 (Autosaved)

The SysTick API function enables the specific SysTick module(TIMER0_Base) for the SysTick interrupt source.

void SysTick_ISR(void)

User-defined function definition for initializing SysTick_ISR. The function returns a value of 0.

if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3)) {

If the GPIO API function reads pin 3 from port F, read line 80.

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);

The GPIO API function writes a 0 to pins 1,2, or 3 clearing the green LED.

else {

Else the GPIO API function ...

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 8);

Writes the value of 8 to pin 3 turning on the green LED.

Calculated Timer0_Freq

Timer0_Freq 10 8 5 2 1Signal Freq 10Hz 8 Hz 5 Hz 13.33 Hz 6.45 Hz

I was unable to get the correct frequency when I went to 2 Hz. The smallest frequency that I can generate correctly with the SysTick timer is 5 Hz.

Problem 3

/************************************************* Interaction through UART, and print debug messages on UART terminal.

By Dr. Xinrong Li, [email protected], Aug. 28, 2014 Adapted from Tiva example code. *************************************************/Comments about the program usually by the programmer.

#include <stdint.h>

This line contains the header file for variable definitions. The header file is already defined in the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. Examples of the values are bit size, precision, and signed or unsigned integers.

#include <stdbool.h>

Page 15: DSP_Assign_2 (Autosaved)

This line contains the header file for Boolean definitions. The header file is already defined in the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The file definitions are used for operations, comparing variables, and program control flow.

#include "inc/tm4c123gh6pm.h"

This line contains the header file for the TM4C123GH6PM microcontroller. The header file is part-specific and contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The .c file for the TM4C123GH6PM microcontroller is included in the project folder for direct access.

#include "inc/hw_memmap.h"

This line contains the header file for the Tiva C Series device memory map definitions. The header file contains many of the same definitions used for direct register access. The header file contains macros and definitions to simplify programming the peripheral's registers and interrupt control. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The definitions are used by driver libraries and are hidden from the programmer.

#include "inc/hw_types.h"

This line contains the header file for common types and macros. The header file contains many of the same definitions used for direct register access. This is contained in the inc directory. The file is considered part of the current program when "#include" is stated before the name of the header file. The definitions are used by driver libraries and are hidden from the programmer. The values are a wide variety of general use for items such as arithmetic, clock timing, file recognition, and device recognition.

#include "driverlib/sysctl.h"

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/interrupt.h"

This line contains the header file for the System Control API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide guided control of the peripherals and allows for quick application. Enabling peripherals is an example of this control.

#include "driverlib/gpio.h"

Page 16: DSP_Assign_2 (Autosaved)

This line contains the header file for GPIO API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The driver provides a set of functions to control the input and output module.

#include "driverlib/timer.h"

This line contains the header file for Timer API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide quick control of the peripherals and allows for quick application. The timer API provides a set of functions for using the timer module.

#include "driverlib/pin_map.h"

This line contains the header file for pin_map API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide quick control of the peripherals and allows for quick application. The pin_map API provides a map of the peripheral to pin configuration.

#include "driverlib/uart.h"

This line contains the header file for UART (Universal Asynchronous Receiver/Transmitter) API definitions and macros. The header file is in the directory "driverlib" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The drivers provide quick control of the peripherals and allows for quick application. The UART API provides a set of functions for using the TIVA UART module.

#include "utils/uartstdio.h"

This line contains the header file for UART. The header file is in the directory "utils" of the CCS software. The file is considered part of the current program when "#include" is stated before the name of the header file. The utility provides quick control of the peripherals and allows for quick application. The file contains prototypes for the UART console functions. On building the project, the .c file had to be added manually to link the files together.

#define TIMER0_FREQ 2

Creates a constant used for frequency in the Timer API macro with a value of 2 Hz.

#define UART0_BAUDRATE 115200

Creates a constant used for baud rate in the UART API macro with a of value 115200 bps.

#define RED_LED GPIO_PIN_1

Creates a constant for pin 1 in the GPIO API module that displays the red LED.

Page 17: DSP_Assign_2 (Autosaved)

#define BLUE_LED GPIO_PIN_2

Creates a constant for pin 2 in the GPIO API module that displays the blue LED.

#define GREEN_LED GPIO_PIN_3

Creates a constant for pin 3 in the GPIO API module that displays the green LED.

#define NUM_DISP_TEXT_LINE 4

Creates a constant for the number of lines of text display in the character pointer "disp_text" with a value of 4.

void init_LEDs(void);

This line declares the function prototype "init_LEDs". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void init_timer(void);

This line declares the function prototype " init_timer ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void init_UART(void);

This line declares the function prototype " init_UART ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

void Timer0_ISR(void);

This line declares the function prototype " Timer0_ISR ". Declaration at this point gives the actual function a global scope. Any other function, header, or .c file contained in this source file is given access to the function and accessible by the function.

extern void UARTStdioIntHandler(void);

This line declares a function prototype of type "extern". This informs the microprocessor that it needs to access a function that exists outside of this source file. The uartstdio.c file is included in the project folder for direct access. The uartstdio.c file has additional functions for the UART console. This particular function handles interrupts from the UART. The UART has a transmit and receive buffer that is used for data transfers between the microprocessor and the putty console.

uint32_t sys_clock;

Creates an unsigned 32-bit global variable for the system clock.

uint8_t cur_LED = RED_LED;

Page 18: DSP_Assign_2 (Autosaved)

Creates an unsigned 32-bit global variable for the system clock.

const char *disp_text[NUM_DISP_TEXT_LINE] = {

"\n","UART and LED Demo\n","H: help, R: red, G: green, B: blue.\n","> " };

This line creates a pointer for a system message communicated to the user via putty console..

int main(void){

The main process calls and acts on variables, macros, definitions, and other system functions.

uint32_t i;

Creates an unsigned 32-bit variable for loops.

unsigned char user_cmd;

Creates an unsigned character variable for user input.

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

System Control Clock Set sets the clocking of the device. Osc_Main configures the oscillator source. XTAL_16MHZ uses a 16 MHZ crystal clock. USE_PLL is a phase locked loop at 400MHZ. SYSDIV_5 divides the clock by the number specified giving control of the frequency.

sys_clock = SysCtlClockGet();

This line retrieves the processor clock rate and assigns it to a variable.

init_LEDs();

Initializes LED configuration and enables by calling the function definition.

init_UART();

Initializes UART configuration and enables by calling the function definition.

init_timer();

Initializes Timer configuration and enables by calling the function definition.

IntMasterEnable();

This NVIC API function enables interrupts from the microprocessor to interrupt controller.

TimerEnable(TIMER0_BASE, TIMER_A);

Page 19: DSP_Assign_2 (Autosaved)

This TIMER API function enables operation of the timer module.

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

This line is a for loop to display program message on console.

UARTprintf(disp_text[i]);

This function prints the message on the console.

while(1) {

The while loop provides a continuous loop when set to "1".

if(UARTRxBytesAvail())

If the UART has available user input.

user_cmd = UARTgetc();

This line retrieves the user input and stores it in a variable.

else

user_cmd = 0;

Else, the user command variable is set to 0.

switch(user_cmd){

Switch case for the user input data.

case '\r':

Switch case for red.

case ' ':

Switch case for empty.

case 'H':

Switch case for H.

case 'h':

Switch case for h.

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

Switch case display for lines 87-90 is a for loop to display console message to user via putty console.

Page 20: DSP_Assign_2 (Autosaved)

UARTprintf(disp_text[i]);

This function prints the message on the putty console.

break;

Switch case break.

case 'R':

Switch case for red led.

case 'r':

Switch case for red led.

cur_LED = RED_LED;

Stores the red led in current led variable.

UARTprintf("\n> ");

This function prints a new line with a > on the console. break;

Switch case break.

case 'B':

Switch case for blue led.

case 'b':

Switch case for blue led.

cur_LED = BLUE_LED;

Stores the blue led in current led variable.

UARTprintf("\n> ");

This function prints a new line with a > on the console.

break;

Switch case break.

case 'G':

Switch case for green led.

Page 21: DSP_Assign_2 (Autosaved)

case 'g':

Switch case for green led.

cur_LED = GREEN_LED;

Stores the green led in current led variable.

UARTprintf("\n> ");

This function prints a new line with a > on the console.

break;

Switch case break.

void init_LEDs(void)

User-defined function definition for initializing LEDs. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

The System Control API function enables the GPIO port F peripheral.

GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

The GPIO API function configures pins 1, 2, and 3 of port F for use as GPIO outputs.

void init_timer(void)

User-defined function definition for initializing Timer. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

The System Control API function enables the timer0 peripheral.

TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

The Timer API function configures the timer as a 32-bit full-width periodic timer.

TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);

The Timer API function specifies the base address for configuration, the correct name for a full-width timer, and the load value specified by user-defined constants.

IntRegister(INT_TIMER0A, Timer0_ISR);

The NVIC API function registers the "TIMER0_ISR" function to be called when the "TIMER0A" interrupt is enabled.

IntEnable(INT_TIMER0A);

Page 22: DSP_Assign_2 (Autosaved)

The NVIC API function enables "TIMER0A" as a full-width timer to be used for the interrupt function process.

TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

The Timer API function enables the specific timer module(TIMER0_Base) for the timer interrupt source. The bit mask of the interrupt source to be enabled is "TIMER_TIMA_TIMEOUT".

void init_UART(void)

User-defined function definition for initializing UART. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

The System Control API function enables the UART0 peripheral.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

The System Control API function enables the GPIOA peripheral.

GPIOPinConfigure(GPIO_PA0_U0RX);

The GPIO API function configures the alternate function of a GPIO pin. GPIO Port A's pin mux is configured for the UART peripheral. Pin 0 is configured for the UART receiver buffer.

GPIOPinConfigure(GPIO_PA1_U0TX);

The GPIO API function configures the alternate function of a GPIO pin. GPIO Port A's pin mux is configured for the UART0 peripheral. Pin 1 is configured for the UART transmitter buffer.

GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

The GPIO API function configures pins for use by the UART peripheral. GPIO Port A will be the peripheral used for UART communication. Pins 1 and 2 of port A are available.

IntRegister(INT_UART0, UARTStdioIntHandler);

The NVIC API function registers the "UARTStdioIntHandler" function to be called when the "UART0" interrupt is enabled.

UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);

The UART driver function configures the UART for input/output. UART Port 0 is the base that will be used. The user-defined constant "UART0_BAUDRATE" is the bit rate for the UART and the user-defined constant "sys_clock" is the frequency used for the source clock of the UART module.

void Timer0_ISR(void)

User-defined function definition for interrupt handler. The function returns a value of 0.

Page 23: DSP_Assign_2 (Autosaved)

TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

The Timer API function clears the timer interrupt sources. TIMER0 is the base specified and "TIMER_TIMA_TIMEOUT" is the bit mask for the interrupt source cleared.

if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {

If the GPIO API function reads pins 1,2, or 3 from port F, read line 164.

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);

The GPIO API function writes a 0 to pins 1,2, or 3.

else {

Else the GPIO API function ...

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);

Writes the value of the variable "cur_LED" to the correct pin.

Problem 4

The Nested Vector Interrupt Controller (NVIC) functions as an interrupt handler. It can set priorities in interrupts and enable or disable them too. A register can be dedicated for top performance. The controller has the ability to nest priorities and choose between static compiles or dynamic run-time environment.

The Timer API has a set of functions for controlling, modifying, and managing interrupts. It can run continuously or just one time ceasing at zero or the load. It is also a full-width timer at 32.768. Half-width gives the option of pulse width modulation and synchronization.

The Universal Asynchronous Receiver/Transmitter (UART) API functions as an interrupt handler, send and receive data, and configure and control UART modules. Some of the features include: programmable baud rate generator, programmable serial interface, line break generation, and detection.

Page 24: DSP_Assign_2 (Autosaved)

UART standard IO module has unbuffered and buffered operation with good interrupt handling. Modification can be made if the buffer is full. The processor can eliminate instructions for full buffers or clear prior to utilization.

The ARM Cortex-M processor provides impressive performance and low power consumption. It has 32-bit architecture with single-cycle multiply instruction and excellent interrupt handling. Unaligned data access provides efficient memory and fast code execution increases sleep time. It maintains high precision and has 32 dedicated 32-bit registers. I t supports multiple software platforms and some controllers come with a built in library for quick application.

Summary and ConclusionsThe Tiva C Series TM4C123G microcontroller has attained better precision, durability, power management, and interrupt control. 32-bit architecture and unaligned data access delivers a fast processing environment. These improvements set a new tone for micro processing and creative environments.

References Texas Instruments. (2014). TivaWare Peripheral Driver Library: User's Guide. Austin, Texas: TI.