32
Lab 3 EENG 3910: Project V - Digital Signal Processing System Design 9/28/2015 Joseph Chandler University of North Texas College of Engineering Electrical Engineering

DSP_Assign_3

Embed Size (px)

Citation preview

Page 1: DSP_Assign_3

Lab 3

EENG 3910: Project V - Digital Signal Processing System Design

9/28/2015

Joseph Chandler

University of North Texas

College of Engineering

Electrical Engineering

Page 2: DSP_Assign_3

IntroductionLab 3 continues the study of the TIVA C Series TM4C123G Microcontroller and CCS software. The lab introduces more software driver libraries and different types of system controls. The analog to digital converter (ADC) API and system controls are the main focus of the lab.

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"

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

Page 3: DSP_Assign_3

"#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 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.

#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 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 "driverlib/adc.h"

This line contains the header file for ADC (Analog-to-Digital) 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 ADC API provides a set of functions for using the TIVA ADC 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 utility provides quick control of the peripherals and allows for quick application. The file

Page 4: DSP_Assign_3

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 ADC0_SEQ_NUM 0

Creates a constant used for the ADC sample sequence number.

#define RED_LED GPIO_PIN_1

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

#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 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.

void init_UART(void);

Page 5: DSP_Assign_3

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 init_ADC(void);

This line declares the function prototype " init_ADC ". 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;

Creates an unsigned 8-bit global variable for the red LED.

const char *disp_text[NUM_DISP_TEXT_LINE] = {

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

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

uint32_t cur_temp=0, cur_temp_C=0, cur_temp_F=0;

Creates an unsigned 32-bit global variable for the temperatures.

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.

Page 6: DSP_Assign_3

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_ADC();

Initializes ADC 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);

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();

Page 7: DSP_Assign_3

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.

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.

Page 8: DSP_Assign_3

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.

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.

case 'T':

Switch case for temperature sensor.

Page 9: DSP_Assign_3

case 't':

Switch case for temperature sensor.

ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

This function enables the processor to trigger the ADC sequence capture.

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {

This function and while loop enables the ADC interrupt to capture data as long as data exists.

ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

This function clears the ADC interrupt from occurring again.

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);

This function assigns the captured data to a variable.

cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;

This variable is assigned the Celsius temperature conversion.

cur_temp_F = (cur_temp_C*9 + 160)/5;

This variable is assigned the Fahrenheit temperature conversion.

UARTprintf("\nTemp = %dC = %dF\n> ", cur_temp_C, cur_temp_F);

This function prints the temperature conversions on the putty console.

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 Timer. The function returns a value of 0.

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

The System Control API function enables TIMER0 peripheral.

Page 10: DSP_Assign_3

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 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.

Page 11: DSP_Assign_3

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 init_ADC(void)

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

The System Control API function enables the ADC0 peripheral.

ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0);

The ADC API function specifies the base address for configuration, the sequence number, the trigger type, and order importance.

ADCSequenceStepConfigure

(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

The ADC API function specifies the base address for configuration, , the sequence number, order importance, and sequence configuration options for temperature sensor, interrupts, and end.

ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM);

The ADC API function enables the specific sequence number for the selected base.

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 pins 1,2, or 3 from port F, read line 194.

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.

Page 12: DSP_Assign_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.

Figure 1 Putty Display

Problem 2

#define TIMER1_FREQ 0.5

I defined another timer frequency constant (global) for the temperature to display every 2 seconds.

void init_timer1(void);

I created a prototype for timer1's initialization.

void Timer1_ISR(void);

I created a prototype for timer1's interrupt.

init_timer1();

I called the init_timer1 function to initialize the new timer.

TimerEnable(TIMER1_BASE, TIMER_A);

I enabled the timer module for operation.

while(1) {

While loop provides continuous loop.

void init_timer1(void)

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

The System Control API function enables the timer1 peripheral.

Page 13: DSP_Assign_3

TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

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

TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER1_FREQ );

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_TIMER1A, Timer1_ISR);

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

IntEnable(INT_TIMER1A);

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

TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

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

void Timer1_ISR(void)

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

TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

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

ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

This function enables the processor to trigger the ADC sequence capture.

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {

This function and while loop enables the ADC interrupt to capture data as long as data exists.

ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

This function clears the interrupt from occurring again.

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);

This function assigns the captured data to a variable.

cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;

Page 14: DSP_Assign_3

This variable is assigned the Celsius temperature conversion.

cur_temp_F = (cur_temp_C*9 + 160)/5;

This variable is assigned the Fahrenheit temperature conversion.

UARTprintf("\nTemp = %dC = %dF\n> ", cur_temp_C, cur_temp_F);

This function prints the temperature conversions on the putty console.

Figure 2 Putty Display

Problem 3

FPU is used for higher precision calculations and variables for storing the results in memory. The function FPULazyStackingEnable allocates space on the stack for floating-point storage. The processor only saves the context if it is involved in an instruction. The interrupt handler does not save floating-point data and takes more time to configure the stack for its use.

There is a software driver library that provides FPU API. The header file is included at the beginning of the source file. A constant is also defined for the space allocated for storage. The temperature variables are saved as floating point as they will be used multiple times to display the temperature if needed. A variable of type char array is essentially used for the string of characters displaying the temperatures. The function snprintf stores the formatted temperatures in a buffer string for format declaration and ease of use with repetition.

Problem 4

#include <stdio.h>

The standard input/output library was added for the function snprintf.

Page 15: DSP_Assign_3

#include "driverlib/fpu.h"

The FPU driver library was added for the FPU API availability.

#define TIMER1_FREQ .5

I defined another timer frequency constant (global) for the temperature to display every 2 seconds.

#define TEMP_STR_LEN 20

The constant was repeated from Lab3_3 for the length of the string.

uint32_t cur_temp=0;

The constant was repeated from Lab3_3 for the unsigned 32-bit integer.

float cur_temp_C=0, cur_temp_F=0;

The constants was repeated from Lab3_3 for the floating-point temperatures.

char temp_str[TEMP_STR_LEN];

The constant was repeated from Lab3_3 for the char array.

void Timer1_ISR(void)

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

TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

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

FPUEnable();

I enabled the FPU module for operation.

FPULazyStackingEnable();

I enabled the floating-point lazy stacking for memory access.

ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

This function enables the processor to trigger the ADC sequence capture.

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {

This function and while loop enables the ADC interrupt to capture data as long as data exists.

ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

This function clears the interrupt from occurring again.

Page 16: DSP_Assign_3

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);

This function assigns the captured data to a variable.

cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;

This variable is assigned the Celsius temperature conversion.

cur_temp_F = (cur_temp_C*9 + 160)/5;

This variable is assigned the Fahrenheit temperature conversion.

snprintf(temp_str, TEMP_STR_LEN, "%.1fC = %.1fF", cur_temp_C, cur_temp_F);

This function configures and registers a variable for frequent use of printing floating-point.

UARTprintf("\nTemp = %s\n> ", temp_str);

This function prints the temperature conversions on the putty console from the configured variable.

Figure 3 Putty Display

Problem 5

#include <stdint.h>

This line contains the header file for variable definitions. 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"

Page 17: DSP_Assign_3

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"

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.

#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 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 drivers

Page 18: DSP_Assign_3

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 "driverlib/adc.h"

This line contains the header file for ADC (Analog-to-Digital) 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 ADC API provides a set of functions for using the TIVA ADC module.

#include "utils/uartstdio.h"

This line contains the header file for UART. The header file is in the directory "utils" of the CCS softwareThe 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

I defined another timer frequency constant (global) for 2 Hz.

#define TIMER1_FREQ 1

I defined another timer frequency constant (global) for 1 Hz.

#define ADC_PIN GPIO_PIN_0

Defined constant for the pin used as input for ADC module.

#define TIMER_PIN GPIO_PIN_4

Defined constant for the pin used as input for Timer module.

void init_timer(void);

I created a prototype for timer0's initialization.

void Timer0_ISR(void);

I created a prototype for timer0's interrupt.

void init_GPIO(void);

I created a prototype for timer0's initialization.

void init_timer1(void);

I created a prototype for timer0's initialization.

void Timer1_ISR(void);

I created a prototype for timer0's interrupt.

Page 19: DSP_Assign_3

uint8_t cur_LED = RED_LED;

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

uint32_t sys_clock;

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

uint32_t analog_input;

Creates a 32-bit global variable for the analog sample.

int main(void){

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

unsigned char user_cmd;

Creates an unsigned character variable for user input.

uint32_t i;

Creates an unsigned 32-bit variable for loops.

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_ADC();

Initializes ADC 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.

init_GPIO();

Page 20: DSP_Assign_3

Initializes GPIO configuration and enables by calling the function definition.

init_timer1();

Initializes Timer1 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);

Enable timer with interrupts for LEDS.

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':

Page 21: DSP_Assign_3

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.

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> ");

Page 22: DSP_Assign_3

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

break;

Switch case break.

case 'G':

Switch case for green led.

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.

case 'A':

Switch case for analog sensor.

case 'a':

Switch case for analog sensor.

ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);

This function enables the processor to trigger the ADC sequence capture.

while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {

This function and while loop enables the ADC interrupt to capture data as long as data exists.

ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);

This function clears the ADC interrupt from occurring again.

ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &analog_input);

This function assigns the captured data to a variable.

UARTprintf("\nAnalog Input = %d\n> ", analog_input);

Page 23: DSP_Assign_3

This function prints the analog input on the putty console.

case 'D':

Switch case for digital sensor.

case 'd':

Switch case for digital sensor

TimerEnable(TIMER1_BASE, TIMER_A);

This function enables the processor to trigger the ADC sequence capture.

break;

Switch case break.

void init_GPIO(void)

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

The System Control API function enables the GPIOD peripheral.

GPIOPinTypeADC(GPIO_PORTD_BASE, ADC_PIN);

This function enables the pin of choice to support ADC type configurations.

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

The System Control API function enables the GPIOE peripheral.

GPIOPinConfigure(GPIO_PE4_U5RX);

The GPIO API function configures the alternate function of a GPIO pin. GPIO Port E's pin mux is configured for the UART peripheral. Pin 4 is configured for the receiving buffer.

GPIOPinTypeTimer(GPIO_PORTE_BASE, TIMER_PIN);

This function enables the pin of choice to support Timer type configurations.

void init_timer1(void)

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

The System Control API function enables the TIMER1 peripheral.

TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

Page 24: DSP_Assign_3

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

TimerLoadSet(TIMER1_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_TIMER1A, Timer1_ISR);

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

IntEnable(INT_TIMER1A);

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

TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

The Timer API function enables the specific timer module(TIMER1_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_1|GPIO_PIN_2|GPIO_PIN_3)) {

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

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.

void init_timer(void)

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

Page 25: DSP_Assign_3

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);

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 Timer1_ISR(void)

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

TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

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

GPIOPinRead(GPIO_PORTE_BASE, TIMER_PIN);

This GPIO API function reads pin 4 from port E.

UARTprintf("\nTimer Input = %d\n> ", TIMER_PIN);

This function prints the timer data to the putty console.

TimerDisable(TIMER1_BASE, TIMER_A);

This function disables the timer for other interrupts to occur from user input.

Summary and Conclusions

Page 26: DSP_Assign_3

Timers and Sequences are vital control components when utilizing the Tiva C Series TM4C123GH6PM microcontroller. The timer and ADC have interrupt routines using the NVIC controller to establish periods for sampling. The samples are used in analog-to-digital conversion.

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