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
Introduction
Lab 2 continuesthe studyof the TivaTM
C SeriesEK-TM4C123GXL andCCS software. Lab2 has software
driverlibrariesand typesof systemcontrols.The timingAPIandfrequencyare the mainaspectsof the
systemcontrolsanddifferentmodules.
Results and Discussions
Problem 1
#include <stdint.h>
Thisline containsthe headerfile forvariabledefinitions.The headerfileisalreadydefinedinthe CCS
software.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers.
#include <stdbool.h>
Thisline containsthe header file forBooleandefinitions.The headerfile isalreadydefinedinthe CCS
software The file definitionsare usedforoperations,comparingvariables,andprogramcontrol flow.
#include "inc/tm4c123gh6pm.h"
Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart-
specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand
interruptcontrol.Thisiscontainedinthe incdirectory.The .c file forthe TM4C123GH6PM
microcontrollerisincludedinthe projectfolderfordirectaccess.
#include "inc/hw_memmap.h"
Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile
containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros
and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis
containedinthe incdirectory.The definitionsare usedbydriverlibrariesandare hiddenfromthe
programmer.
#include "inc/hw_types.h"
Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare
usedbydriverlibrariesand are hiddenfromthe programmer.The valuesare a wide varietyof general
use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition.
#include "driverlib/sysctl.h"
Thisline containsthe headerfile forthe SystemControl API definitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand
allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol.
#include "driverlib/interrupt.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand
allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol.
#include "driverlib/gpio.h"
Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The driverprovidesasetof functionstocontrol the inputand output
module.
#include "driverlib/timer.h"
Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The driversprovide quickcontrol of the peripheralsandallowsforquick
application.The timerAPIprovidesasetof functionsforusingthe timermodule.
#define TIMER0_FREQ 10
Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 10 Hz.
void init_LEDs(void);
Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona
global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe
functionandaccessible bythe function.
void init_timer(void);
Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void Timer0_ISR(void);
Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
uint32_t sys_clock;
Createsan unsigned32-bitglobal variable forthe systemclock.
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystemfunctions.
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource.
XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides
the clock bythe numberspecifiedgivingcontrol of the frequency
sys_clock = SysCtlClockGet();
Thisline retrievesthe processorclockrate andassignsit toa variable.
init_LEDs();
InitializesLEDconfigurationandenables by calling the function definition.
init_timer();
InitializesTimerconfigurationandenables by calling the function definition.
IntMasterEnable();
ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller.
TimerEnable(TIMER0_BASE, TIMER_A);
ThisTIMER API functionenablesoperationof the timer module.
while(1) {
The while loopprovidesacontinuousloopwhensetto"1".
void init_LEDs(void)
User-definedfunctiondefinitionforinitializingLEDs.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
The SystemControl APIfunctionenablesthe GPIOportF peripheral.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
The GPIO APIfunctionconfigurespins1,2, or 3 of port F for use as GPIOoutputs.
void init_timer(void)
User-definedfunctiondefinitionforinitializingTIMER0.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
The SystemControl APIfunctionenablesTIMER0 peripheral.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer.
TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);
The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width
timer,andthe load value specifiedbyuser-definedconstants.
IntRegister(INT_TIMER0A, Timer0_ISR);
The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER0A);
The NVICAPIfunctionenables"TIMER0A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timerinterruptsource.
The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT".
void Timer0_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) {
If the GPIOAPIfunctionreadspin 2 fromport F,read line 88.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
The GPIO APIfunctionwritesa0 to pins1,2, or 3 clearingthe blue LED.
else {
Else the GPIO APIfunction...
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
Writesthe value of 4 to pin2 displayingthe blue LED.
Port F interface
The GPIO APIfunctionconfiguresportFforoutput.It furtherspecifiesthatpins1,2,and 3, inport F, will
be usedfor output. The launchpadschematicshowsPortFhas 5 pins.Pin1 is the redLED, Pin2 is the
blue LED, and Pin3 is the greenLED. The remainingpins(0and 4) are forthe USR SV.Afterthe GPIO
functionconfiguresthe pinsasoutput,itcanwrite valuesof 2, 3, and 4 for red,green,andblue,
respectively.The programactuallywritesa"4"to the pin2 whichoperatesthe blue LED.
Calculated TIMER0_FREQ
Timer0_Freq 1 2 5 10
Calculated 1Hz 2Hz 5Hz 10Hz
#define TIMER0_FREQ 1
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 TimerLoadSetfunction hasaparameterfor the "loadvalue".The loadvalue is
"sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe
value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset
to 1. Therefore,
40,000,000/1 = 1 period
1/period= frequency
1/40,000,000 = 0.000000025 = frequencyof timer
The timeris enabledalongwiththe runningsystemclock.The frequenciesof boththe timerandsystem
clock mustbe takenintoaccount for the overall frequency of the interruptcausedbyenablingthe timer.
Therefore,
frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt
0.000000025 * 40,000,000 = 1 Hz
#define TIMER0_FREQ 2
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 TimerLoadSetfunctionhasaparameterfor the "loadvalue".The loadvalue is
"sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe
value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset
to 2. Therefore,
40,000,000/2 = 1 period
1/period= frequency
1/20,000,000 = 0.00000005 = frequencyof timer
The timeris enabledalongwiththe runningsystemclock.The frequenciesof boththe timerandsystem
clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer.
Therefore,
frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt
0.00000005 * 40,000,000 = 2 Hz
#define TIMER0_FREQ 5
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 TimerLoadSetfunctionhasaparameterfor the "loadvalue".The loadvalue is
"sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe
value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset
to 5. Therefore,
40,000,000/5 = 1 period
1/period= frequency
1/8,000,000 = 0.000000125 = frequencyof timer
The timeris enabledalongwiththe runningsystem clock.The frequenciesof boththe timerandsystem
clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer.
Therefore,
frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt
0.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 TimerLoadSetfunction hasaparameterfor the "loadvalue".The loadvalue is
"sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe
value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset
to 10. Therefore,
40,000,000/10 = 1 period
1/period= frequency
1/4,000,000 = 0.00000025 = frequencyof timer
The timeris enabledalongwiththe runningsystemclock.The frequenciesof boththe timerandsystem
clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer.
Therefore,
frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt
0.00000025 * 40,000,000 = 10 Hz
Captured Oscilloscope Signal Waveform
Figure 1 10 Hz
Figure 2 5 Hz
Figure 3 2 Hz
Figure 4 1 Hz
Problem 2
/*************************************************
Blink LEDs on Tiva C Series LaunchPad
with SysTick timer.
By Dr. Xinrong Li, xinrong@UNT.EDU, Aug. 25, 2014
Adapted from Tiva example code.
*************************************************/
Commentsaboutthe programusuallybythe programmer.
#include <stdint.h>
Thisline containsthe headerfile forvariabledefinitions.The headerfileisalreadydefinedinthe CCS
software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
of the headerfile.Examplesof the valuesare bitsize,precision, andsignedorunsignedintegers.
#include <stdbool.h>
Thisline containsthe headerfile forBooleandefinitions.The headerfile isalreadydefinedinthe CCS
software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
of the headerfile.The file definitionsare usedforoperations,comparingvariables,andprogramcontrol
flow.
#include "inc/tm4c123gh6pm.h"
Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart-
specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand
interruptcontrol.Thisiscontainedinthe incdirectory. The file isconsideredpartof the currentprogram
when"#include"isstatedbefore the name of the headerfile.The .cfile forthe TM4C123GH6PM
microcontrollerisincludedinthe projectfolderfordirectaccess.
#include "inc/hw_memmap.h"
Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile
containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros
and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis
containedinthe incdirectory.The file isconsideredpartof the current programwhen"#include"is
statedbefore the name of the headerfile.The definitionsare usedbydriverlibrariesandare hidden
fromthe programmer.
#include "inc/hw_types.h"
Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The file is
consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile.
The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide
varietyof general use foritemssuchas arithmetic,clocktiming,file recognition,anddevice recognition.
#include "driverlib/sysctl.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when
"#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the
peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol.
#include "driverlib/interrupt.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when
"#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the
peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol.
#include "driverlib/gpio.h"
Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is
statedbefore the name of the headerfile.The driverprovidesasetof functionstocontrol the inputand
outputmodule.
#include "driverlib/systick.h"
Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is
statedbefore the name of the headerfile.The driversprovide quickcontrol of the peripheralsand
allowsforquickapplication.The timerAPIprovidesasetof functionsforusingthe timermodule.
#define TIMER0_FREQ 10
Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 10 Hz.
void init_LEDs(void);
Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona
global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe
functionandaccessible bythe function.
void init_timer(void);
Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void Timer0_ISR(void);
Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
uint32_t sys_clock;
Createsan unsigned32-bitglobal variable forthe systemclock.
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystemfunctions.
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource.
XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_2_5
dividesthe clockbythe numberspecifiedgivingcontrol of the frequency.
sys_clock = 80000000;
Thisline retrievesthe processorclockrate andassignsit toa variable.
init_LEDs();
InitializesLEDconfigurationandenables by calling the function definition.
init_SysTick();
InitializesSysTick configurationandenables by calling the function definition.
IntMasterEnable();
ThisNVICAPIfunctionenables interruptsfromthe microprocessortointerruptcontroller.
SysTickEnable();
ThisSysTickAPI functionenablesoperationof the timer module.
while(1) {
The while loopprovidesacontinuousloopwhensetto"1".
void init_LEDs(void)
User-definedfunction definitionforinitializingLEDs.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
The SystemControl APIfunctionenablesthe GPIOportF peripheral.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
The GPIO APIfunctionconfigurespins1,2, and3 of portF for use as GPIO outputs.
void init_SysTick(void)
User-definedfunctiondefinitionforinitializingSysTick.The functionreturnsavalue of 0.
SysTickPeriodSet(sys_clock/TIMER0_FREQ);
The SysTick APIfunctionconfigures the value specifiedbyuser-definedconstants.
SysTickIntRegister(SysTick_ISR);
The NVICAPIfunctionregistersthe "SysTick_ISR"functiontobe calledwhenthe "SysTick"interruptis
enabled.
SysTickIntEnable();
The SysTickAPIfunctionenablesthe specificSysTickmodule(TIMER0_Base) forthe SysTickinterrupt
source.
void SysTick_ISR(void)
User-definedfunctiondefinitionforinitializingSysTick_ISR.The functionreturnsavalue of 0.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3)) {
If the GPIOAPIfunctionreadspin 3 fromport F,read line 80.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
The GPIO APIfunctionwritesa0 to pins1,2, or 3 clearingthe greenLED.
else {
Else the GPIO APIfunction ...
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 8);
Writesthe value of 8 to pin3 turningonthe greenLED.
Calculated Timer0_Freq
Timer0_Freq 10 8 5 2 1
Signal Freq 10Hz 8 Hz 5 Hz 13.33 Hz 6.45 Hz
I was unable togetthe correct frequencywhenIwentto 2 Hz. The smallestfrequencythatIcan
generate correctlywiththe SysTicktimeris5 Hz.
Problem 3
/*************************************************
Interaction through UART, and
print debug messages on UART terminal.
By Dr. Xinrong Li, xinrong@UNT.EDU, Aug. 28, 2014
Adapted from Tiva example code.
*************************************************/
Commentsaboutthe programusuallybythe programmer.
#include <stdint.h>
Thisline containsthe headerfile forvariabledefinitions.The headerfile isalreadydefinedinthe CCS
software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
of the headerfile.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers.
#include <stdbool.h>
Thisline containsthe headerfile forBooleandefinitions.The headerfile isalreadydefinedinthe CCS
software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
of the headerfile.The file definitionsare usedforoperations,comparingvariables,andprogramcontrol
flow.
#include "inc/tm4c123gh6pm.h"
Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart-
specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand
interruptcontrol.Thisiscontainedinthe incdirectory.The file isconsideredpartof the currentprogram
when"#include"isstatedbefore the name of the headerfile.The .cfile forthe TM4C123GH6PM
microcontrollerisincludedinthe projectfolderfordirectaccess.
#include "inc/hw_memmap.h"
Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile
containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros
and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis
containedinthe incdirectory.The file isconsideredpartof the current programwhen"#include"is
statedbefore the name of the headerfile.The definitionsare usedbydriverlibrariesandare hidden
fromthe programmer.
#include "inc/hw_types.h"
Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The file is
consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile.
The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide
varietyof general use foritemssuchas arithmetic,clocktiming,file recognition,anddevice recognition.
#include "driverlib/sysctl.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when
"#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the
peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol.
#include "driverlib/interrupt.h"
Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin
the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when
"#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the
peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol.
#include "driverlib/gpio.h"
Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is
statedbefore the name of the headerfile.The driverprovidesasetof functionstocontrol the inputand
outputmodule.
#include "driverlib/timer.h"
Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory
"driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is
statedbefore the name of the headerfile.The driversprovide quickcontrol of the peripheralsand
allowsforquickapplication.The timerAPIprovidesasetof functionsforusingthe timermodule.
#include "driverlib/pin_map.h"
Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe
directory"driverlib"of the CCSsoftware.The file isconsideredpartof the current programwhen
"#include"isstatedbefore the name of the headerfile.The driversprovide quickcontrol of the
peripheralsandallowsforquickapplication.The pin_map APIprovidesamapof the peripheral topin
configuration.
#include "driverlib/uart.h"
Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API
definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The file is
consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile.
The driversprovide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPI
providesasetof functionsforusingthe TIVA UART module.
#include "utils/uartstdio.h"
Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS
software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
of the headerfile.The utilityprovidesquickcontrol of the peripheralsand allowsforquickapplication.
The file containsprototypesforthe UARTconsole functions.Onbuildingthe project,the .cfile hadtobe
addedmanuallytolinkthe filestogether.
#define TIMER0_FREQ 2
Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 2 Hz.
#define UART0_BAUDRATE 115200
Createsa constantusedfor baudrate inthe UART APImacro witha of value 115200 bps.
#define RED_LED GPIO_PIN_1
Createsa constantfor pin1 inthe GPIO APImodule thatdisplaysthe redLED.
#define BLUE_LED GPIO_PIN_2
Createsa constantfor pin2 inthe GPIO APImodule thatdisplaysthe blue LED.
#define GREEN_LED GPIO_PIN_3
Createsa constantfor pin3 inthe GPIO APImodule thatdisplaysthe greenLED.
#define NUM_DISP_TEXT_LINE 4
Createsa constantfor the numberof linesof textdisplayinthe characterpointer"disp_text"witha
value of 4.
void init_LEDs(void);
Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona
global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe
functionandaccessible bythe function.
void init_timer(void);
Thisline declaresthe functionprototype " init_timer".Declarationatthispoint givesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void init_UART(void);
Thisline declaresthe functionprototype " init_UART". Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
functionandaccessible bythe function.
void Timer0_ISR(void);
Thisline declaresthe function prototype "Timer0_ISR".Declarationat thispointgivesthe actual
functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess
to the functionandaccessible bythe function.
extern void UARTStdioIntHandler(void);
Thisline declaresafunctionprototype of type "extern".Thisinformsthe microprocessorthatitneedsto
access a functionthatexistsoutsideof thissource file.The uartstdio.cfileisincludedinthe project
folderfordirectaccess.The uartstdio.cfile hasadditional functionsforthe UARTconsole.Thisparticular
functionhandlesinterruptsfromthe UART.The UART has a transmitandreceive bufferthatisusedfor
data transfersbetweenthe microprocessorandthe puttyconsole.
uint32_t sys_clock;
Createsan unsigned32-bitglobal variable forthe systemclock.
uint8_t cur_LED = RED_LED;
Createsan unsigned32-bitglobal variable forthe systemclock.
const char *disp_text[NUM_DISP_TEXT_LINE] = {
"n",
"UART and LED Demon",
"H: help, R: red, G: green, B: blue.n",
"> " };
Thisline createsa pointer fora systemmessage communicatedtothe userviaputtyconsole..
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystem functions.
uint32_t i;
Createsan unsigned32-bitvariable forloops.
unsigned char user_cmd;
Createsan unsignedcharactervariable foruserinput.
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SystemControl Clock Setsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource.
XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides
the clock bythe numberspecifiedgivingcontrol of the frequency.
sys_clock = SysCtlClockGet();
Thisline retrievesthe processorclockrate andassignsit toa variable.
init_LEDs();
InitializesLEDconfigurationandenables by calling the function definition.
init_UART();
InitializesUARTconfigurationandenables by calling the function definition.
init_timer();
InitializesTimerconfigurationandenables by calling the function definition.
IntMasterEnable();
ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller.
TimerEnable(TIMER0_BASE, TIMER_A);
ThisTIMER API functionenablesoperationof the timer module.
for(i=0; i<NUM_DISP_TEXT_LINE; i++)
Thisline isa for loopto displayprogrammessage onconsole.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe console.
while(1) {
The while loopprovidesacontinuousloopwhensetto"1".
if(UARTRxBytesAvail())
If the UART has available userinput.
user_cmd = UARTgetc();
Thisline retrievesthe userinputandstoresitina variable.
else
user_cmd = 0;
Else,the usercommandvariable issetto 0.
switch(user_cmd){
Switchcase for the userinputdata.
case 'r':
Switchcase for red.
case ' ':
Switchcase for empty.
case 'H':
Switchcase for H.
case 'h':
Switchcase for h.
for(i=0; i<NUM_DISP_TEXT_LINE; i++)
Switchcase displayforlines87-90 is a for looptodisplayconsole message touser viaputty console.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe putty console.
break;
Switchcase break.
case 'R':
Switchcase for redled.
case 'r':
Switchcase for redled.
cur_LED = RED_LED;
Storesthe red ledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'B':
Switchcase for blue led.
case 'b':
Switchcase for blue led.
cur_LED = BLUE_LED;
Storesthe blue ledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'G':
Switchcase for green led.
case 'g':
Switchcase for greenled.
cur_LED = GREEN_LED;
Storesthe greenledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
void init_LEDs(void)
User-defined functiondefinitionforinitializingLEDs.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
The SystemControl APIfunctionenablesthe GPIOportF peripheral.
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
The GPIO APIfunctionconfigurespins1,2, and3 of portF for use as GPIO outputs.
void init_timer(void)
User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
The SystemControl APIfunctionenablesthe timer0peripheral.
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer.
TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1);
The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width
timer,andthe load value specifiedbyuser-definedconstants.
IntRegister(INT_TIMER0A, Timer0_ISR);
The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER0A);
The NVICAPIfunctionenables"TIMER0A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timerinterruptsource.
The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT".
void init_UART(void)
User-definedfunctiondefinitionforinitializingUART.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
The SystemControl APIfunctionenablesthe UART0 peripheral.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
The SystemControl APIfunctionenablesthe GPIOA peripheral.
GPIOPinConfigure(GPIO_PA0_U0RX);
The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is
configuredforthe UART peripheral.Pin0is configuredforthe UARTreceiverbuffer.
GPIOPinConfigure(GPIO_PA1_U0TX);
The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is
configuredforthe UART0 peripheral.Pin1isconfiguredforthe UART transmitterbuffer.
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
The GPIO APIfunctionconfigurespinsforuse bythe UART peripheral.GPIOPortA will be the peripheral
usedforUART communication.Pins1and2 of port A are available.
IntRegister(INT_UART0, UARTStdioIntHandler);
The NVICAPIfunctionregistersthe "UARTStdioIntHandler"functiontobe calledwhenthe "UART0"
interruptisenabled.
UARTStdioConfig(0, UART0_BAUDRATE, sys_clock);
The UART driverfunctionconfiguresthe UARTforinput/output.UARTPort0 isthe base that will be
used.The user-definedconstant"UART0_BAUDRATE"isthe bitrate forthe UART and the user-defined
constant "sys_clock"isthe frequencyusedforthe source clockof the UART module.
void Timer0_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) {
If the GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 164.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
The GPIO APIfunctionwritesa0 to pins1,2, or 3.
else {
Else the GPIO APIfunction...
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED);
Writesthe value of the variable "cur_LED" to the correct pin.
Problem 4
The NestedVectorInterruptController(NVIC) functionsasaninterrupthandler.Itcansetpriorities in
interruptsandenable ordisable themtoo.A registercanbe dedicatedfortopperformance.The
controllerhasthe abilitytonestprioritiesandchoose betweenstaticcompilesordynamicrun-time
environment.
The TimerAPI hasa setof functionsforcontrolling,modifying,andmanaginginterrupts.Itcanrun
continuouslyorjustone time ceasingatzeroor the load.It is alsoa full-widthtimerat32.768. Half-
widthgivesthe optionof pulse widthmodulationandsynchronization.
The Universal AsynchronousReceiver/Transmitter(UART) APIfunctionsasaninterrupthandler,send
and receive data,andconfigure andcontrol UART modules.Some of the featuresinclude:
programmable baudrate generator,programmable serial interface,line breakgeneration,and
detection.
UART standard IOmodule hasunbufferedandbufferedoperationwithgoodinterrupthandling.
Modificationcanbe made if the bufferisfull.The processorcaneliminate instructionsforfull buffersor
clearprior to utilization.
The ARM Cortex-Mprocessorprovidesimpressive performance andlow powerconsumption.Ithas32-
bitarchitecture withsingle-cyclemultiplyinstructionandexcellentinterrupthandling.Unaligneddata
access providesefficientmemoryandfastcode executionincreases sleeptime.Itmaintainshigh
precisionandhas32 dedicated32-bitregisters.Itsupportsmultiple software platformsand some
controllerscome withabuiltinlibraryforquickapplication.
Summary and Conclusions
The Tiva C SeriesTM4C123G microcontrollerhasattainedbetterprecision,durability,power
management,and interruptcontrol. 32-bitarchitecture andunaligneddataaccessdeliversafast
processingenvironment.These improvementssetanew tone formicro processingandcreative
environments.
References
TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide. Austin,Texas:TI.

DSP_Assign_2 (Autosaved)

  • 1.
    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
  • 2.
    Introduction Lab 2 continuesthestudyof the TivaTM C SeriesEK-TM4C123GXL andCCS software. Lab2 has software driverlibrariesand typesof systemcontrols.The timingAPIandfrequencyare the mainaspectsof the systemcontrolsanddifferentmodules. Results and Discussions Problem 1 #include <stdint.h> Thisline containsthe headerfile forvariabledefinitions.The headerfileisalreadydefinedinthe CCS software.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers. #include <stdbool.h> Thisline containsthe header file forBooleandefinitions.The headerfile isalreadydefinedinthe CCS software The file definitionsare usedforoperations,comparingvariables,andprogramcontrol flow. #include "inc/tm4c123gh6pm.h" Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart- specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand interruptcontrol.Thisiscontainedinthe incdirectory.The .c file forthe TM4C123GH6PM microcontrollerisincludedinthe projectfolderfordirectaccess. #include "inc/hw_memmap.h" Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis containedinthe incdirectory.The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer. #include "inc/hw_types.h" Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare usedbydriverlibrariesand are hiddenfromthe programmer.The valuesare a wide varietyof general use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition. #include "driverlib/sysctl.h"
  • 3.
    Thisline containsthe headerfileforthe SystemControl API definitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol. #include "driverlib/interrupt.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The driversprovideguidedcontrol of the peripheralsand allowsforquickapplication.Enablingperipheralsisanexampleof thiscontrol. #include "driverlib/gpio.h" Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The driverprovidesasetof functionstocontrol the inputand output module. #include "driverlib/timer.h" Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The driversprovide quickcontrol of the peripheralsandallowsforquick application.The timerAPIprovidesasetof functionsforusingthe timermodule. #define TIMER0_FREQ 10 Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 10 Hz. void init_LEDs(void); Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe functionandaccessible bythe function. void init_timer(void); Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void Timer0_ISR(void); Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. uint32_t sys_clock; Createsan unsigned32-bitglobal variable forthe systemclock. int main(void){
  • 4.
    The main processcallsandactson variables,macros,definitions,andothersystemfunctions. SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource. XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides the clock bythe numberspecifiedgivingcontrol of the frequency sys_clock = SysCtlClockGet(); Thisline retrievesthe processorclockrate andassignsit toa variable. init_LEDs(); InitializesLEDconfigurationandenables by calling the function definition. init_timer(); InitializesTimerconfigurationandenables by calling the function definition. IntMasterEnable(); ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller. TimerEnable(TIMER0_BASE, TIMER_A); ThisTIMER API functionenablesoperationof the timer module. while(1) { The while loopprovidesacontinuousloopwhensetto"1". void init_LEDs(void) User-definedfunctiondefinitionforinitializingLEDs.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); The SystemControl APIfunctionenablesthe GPIOportF peripheral. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); The GPIO APIfunctionconfigurespins1,2, or 3 of port F for use as GPIOoutputs. void init_timer(void) User-definedfunctiondefinitionforinitializingTIMER0.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); The SystemControl APIfunctionenablesTIMER0 peripheral.
  • 5.
    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); The TimerAPIfunctionconfiguresthe timerasa 32-bitfull-widthperiodictimer. TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1); The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width timer,andthe load value specifiedbyuser-definedconstants. IntRegister(INT_TIMER0A, Timer0_ISR); The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER0A); The NVICAPIfunctionenables"TIMER0A"asa full-widthtimer tobe usedforthe interruptfunction process. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timerinterruptsource. The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT". void Timer0_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) { If the GPIOAPIfunctionreadspin 2 fromport F,read line 88. GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); The GPIO APIfunctionwritesa0 to pins1,2, or 3 clearingthe blue LED. else { Else the GPIO APIfunction... GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4); Writesthe value of 4 to pin2 displayingthe blue LED. Port F interface
  • 6.
    The GPIO APIfunctionconfiguresportFforoutput.Itfurtherspecifiesthatpins1,2,and 3, inport F, will be usedfor output. The launchpadschematicshowsPortFhas 5 pins.Pin1 is the redLED, Pin2 is the blue LED, and Pin3 is the greenLED. The remainingpins(0and 4) are forthe USR SV.Afterthe GPIO functionconfiguresthe pinsasoutput,itcanwrite valuesof 2, 3, and 4 for red,green,andblue, respectively.The programactuallywritesa"4"to the pin2 whichoperatesthe blue LED. Calculated TIMER0_FREQ Timer0_Freq 1 2 5 10 Calculated 1Hz 2Hz 5Hz 10Hz #define TIMER0_FREQ 1 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 TimerLoadSetfunction hasaparameterfor the "loadvalue".The loadvalue is "sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset to 1. Therefore, 40,000,000/1 = 1 period 1/period= frequency 1/40,000,000 = 0.000000025 = frequencyof timer The timeris enabledalongwiththe runningsystemclock.The frequenciesof boththe timerandsystem clock mustbe takenintoaccount for the overall frequency of the interruptcausedbyenablingthe timer. Therefore, frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt 0.000000025 * 40,000,000 = 1 Hz #define TIMER0_FREQ 2 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 TimerLoadSetfunctionhasaparameterfor the "loadvalue".The loadvalue is "sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset to 2. Therefore, 40,000,000/2 = 1 period 1/period= frequency 1/20,000,000 = 0.00000005 = frequencyof timer
  • 7.
    The timeris enabledalongwiththerunningsystemclock.The frequenciesof boththe timerandsystem clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer. Therefore, frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt 0.00000005 * 40,000,000 = 2 Hz #define TIMER0_FREQ 5 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 TimerLoadSetfunctionhasaparameterfor the "loadvalue".The loadvalue is "sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset to 5. Therefore, 40,000,000/5 = 1 period 1/period= frequency 1/8,000,000 = 0.000000125 = frequencyof timer The timeris enabledalongwiththe runningsystem clock.The frequenciesof boththe timerandsystem clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer. Therefore, frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt 0.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 TimerLoadSetfunction hasaparameterfor the "loadvalue".The loadvalue is "sys_clock/TIMER0_FREQ -1". Thissetsthe periodforthe timer.The sys_clockvariable issettothe value of the systemclock.The systemclockisconfiguredfor40 MHz. The TIMER0_FREQ variable isset to 10. Therefore, 40,000,000/10 = 1 period 1/period= frequency 1/4,000,000 = 0.00000025 = frequencyof timer The timeris enabledalongwiththe runningsystemclock.The frequenciesof boththe timerandsystem clock mustbe takenintoaccount for the overall frequencyof the interruptcausedbyenablingthe timer. Therefore, frequencyof timer*frequencyof systemclock= frequencyof timerinterrupt 0.00000025 * 40,000,000 = 10 Hz
  • 8.
    Captured Oscilloscope SignalWaveform Figure 1 10 Hz
  • 9.
    Figure 2 5Hz Figure 3 2 Hz
  • 10.
    Figure 4 1Hz Problem 2 /************************************************* Blink LEDs on Tiva C Series LaunchPad with SysTick timer. By Dr. Xinrong Li, xinrong@UNT.EDU, Aug. 25, 2014 Adapted from Tiva example code. *************************************************/ Commentsaboutthe programusuallybythe programmer. #include <stdint.h> Thisline containsthe headerfile forvariabledefinitions.The headerfileisalreadydefinedinthe CCS software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name of the headerfile.Examplesof the valuesare bitsize,precision, andsignedorunsignedintegers. #include <stdbool.h>
  • 11.
    Thisline containsthe headerfileforBooleandefinitions.The headerfile isalreadydefinedinthe CCS software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name of the headerfile.The file definitionsare usedforoperations,comparingvariables,andprogramcontrol flow. #include "inc/tm4c123gh6pm.h" Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart- specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand interruptcontrol.Thisiscontainedinthe incdirectory. The file isconsideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile.The .cfile forthe TM4C123GH6PM microcontrollerisincludedinthe projectfolderfordirectaccess. #include "inc/hw_memmap.h" Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis containedinthe incdirectory.The file isconsideredpartof the current programwhen"#include"is statedbefore the name of the headerfile.The definitionsare usedbydriverlibrariesandare hidden fromthe programmer. #include "inc/hw_types.h" Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The file is consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile. The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use foritemssuchas arithmetic,clocktiming,file recognition,anddevice recognition. #include "driverlib/sysctl.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when "#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol. #include "driverlib/interrupt.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when "#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol. #include "driverlib/gpio.h"
  • 12.
    Thisline containsthe headerfileforGPIOAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is statedbefore the name of the headerfile.The driverprovidesasetof functionstocontrol the inputand outputmodule. #include "driverlib/systick.h" Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is statedbefore the name of the headerfile.The driversprovide quickcontrol of the peripheralsand allowsforquickapplication.The timerAPIprovidesasetof functionsforusingthe timermodule. #define TIMER0_FREQ 10 Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 10 Hz. void init_LEDs(void); Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe functionandaccessible bythe function. void init_timer(void); Thisline declaresthe functionprototype " init_timer".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void Timer0_ISR(void); Thisline declaresthe functionprototype " Timer0_ISR".Declarationat thispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. uint32_t sys_clock; Createsan unsigned32-bitglobal variable forthe systemclock. int main(void){ The main processcallsandacts on variables,macros,definitions,andothersystemfunctions. SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SystemControl ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource. XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_2_5 dividesthe clockbythe numberspecifiedgivingcontrol of the frequency. sys_clock = 80000000;
  • 13.
    Thisline retrievesthe processorclockrateandassignsit toa variable. init_LEDs(); InitializesLEDconfigurationandenables by calling the function definition. init_SysTick(); InitializesSysTick configurationandenables by calling the function definition. IntMasterEnable(); ThisNVICAPIfunctionenables interruptsfromthe microprocessortointerruptcontroller. SysTickEnable(); ThisSysTickAPI functionenablesoperationof the timer module. while(1) { The while loopprovidesacontinuousloopwhensetto"1". void init_LEDs(void) User-definedfunction definitionforinitializingLEDs.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); The SystemControl APIfunctionenablesthe GPIOportF peripheral. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); The GPIO APIfunctionconfigurespins1,2, and3 of portF for use as GPIO outputs. void init_SysTick(void) User-definedfunctiondefinitionforinitializingSysTick.The functionreturnsavalue of 0. SysTickPeriodSet(sys_clock/TIMER0_FREQ); The SysTick APIfunctionconfigures the value specifiedbyuser-definedconstants. SysTickIntRegister(SysTick_ISR); The NVICAPIfunctionregistersthe "SysTick_ISR"functiontobe calledwhenthe "SysTick"interruptis enabled. SysTickIntEnable(); The SysTickAPIfunctionenablesthe specificSysTickmodule(TIMER0_Base) forthe SysTickinterrupt source.
  • 14.
    void SysTick_ISR(void) User-definedfunctiondefinitionforinitializingSysTick_ISR.The functionreturnsavalueof 0. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3)) { If the GPIOAPIfunctionreadspin 3 fromport F,read line 80. GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); The GPIO APIfunctionwritesa0 to pins1,2, or 3 clearingthe greenLED. else { Else the GPIO APIfunction ... GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 8); Writesthe value of 8 to pin3 turningonthe greenLED. Calculated Timer0_Freq Timer0_Freq 10 8 5 2 1 Signal Freq 10Hz 8 Hz 5 Hz 13.33 Hz 6.45 Hz I was unable togetthe correct frequencywhenIwentto 2 Hz. The smallestfrequencythatIcan generate correctlywiththe SysTicktimeris5 Hz. Problem 3 /************************************************* Interaction through UART, and print debug messages on UART terminal. By Dr. Xinrong Li, xinrong@UNT.EDU, Aug. 28, 2014 Adapted from Tiva example code. *************************************************/ Commentsaboutthe programusuallybythe programmer. #include <stdint.h> Thisline containsthe headerfile forvariabledefinitions.The headerfile isalreadydefinedinthe CCS software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name of the headerfile.Examplesof the valuesare bitsize,precision,andsignedorunsignedintegers. #include <stdbool.h> Thisline containsthe headerfile forBooleandefinitions.The headerfile isalreadydefinedinthe CCS software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name
  • 15.
    of the headerfile.Thefile definitionsare usedforoperations,comparingvariables,andprogramcontrol flow. #include "inc/tm4c123gh6pm.h" Thisline containsthe headerfile forthe TM4C123GH6PM microcontroller.The headerfile ispart- specificandcontainsmacrosand definitionstosimplifyprogrammingthe peripheral'sregistersand interruptcontrol.Thisiscontainedinthe incdirectory.The file isconsideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile.The .cfile forthe TM4C123GH6PM microcontrollerisincludedinthe projectfolderfordirectaccess. #include "inc/hw_memmap.h" Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis containedinthe incdirectory.The file isconsideredpartof the current programwhen"#include"is statedbefore the name of the headerfile.The definitionsare usedbydriverlibrariesandare hidden fromthe programmer. #include "inc/hw_types.h" Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The file is consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile. The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use foritemssuchas arithmetic,clocktiming,file recognition,anddevice recognition. #include "driverlib/sysctl.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when "#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol. #include "driverlib/interrupt.h" Thisline containsthe headerfile forthe SystemControl APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when "#include"isstatedbefore the name of the headerfile.The driversprovide guidedcontrol of the peripheralsandallowsforquickapplication.Enablingperipheralsisanexample of thiscontrol. #include "driverlib/gpio.h" Thisline containsthe headerfile forGPIOAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is
  • 16.
    statedbefore the nameof the headerfile.The driverprovidesasetof functionstocontrol the inputand outputmodule. #include "driverlib/timer.h" Thisline containsthe headerfile forTimerAPIdefinitionsandmacros.The headerfile isinthe directory "driverlib"of the CCSsoftware.The fileisconsideredpartof the currentprogram when"#include"is statedbefore the name of the headerfile.The driversprovide quickcontrol of the peripheralsand allowsforquickapplication.The timerAPIprovidesasetof functionsforusingthe timermodule. #include "driverlib/pin_map.h" Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The file isconsideredpartof the current programwhen "#include"isstatedbefore the name of the headerfile.The driversprovide quickcontrol of the peripheralsandallowsforquickapplication.The pin_map APIprovidesamapof the peripheral topin configuration. #include "driverlib/uart.h" Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The file is consideredpartof the currentprogram when"#include"isstatedbefore the name of the headerfile. The driversprovide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPI providesasetof functionsforusingthe TIVA UART module. #include "utils/uartstdio.h" Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS software.The file isconsideredpartof the currentprogram when"#include"isstatedbeforethe name of the headerfile.The utilityprovidesquickcontrol of the peripheralsand allowsforquickapplication. The file containsprototypesforthe UARTconsole functions.Onbuildingthe project,the .cfile hadtobe addedmanuallytolinkthe filestogether. #define TIMER0_FREQ 2 Createsa constantusedfor frequencyinthe TimerAPImacrowitha value of 2 Hz. #define UART0_BAUDRATE 115200 Createsa constantusedfor baudrate inthe UART APImacro witha of value 115200 bps. #define RED_LED GPIO_PIN_1 Createsa constantfor pin1 inthe GPIO APImodule thatdisplaysthe redLED. #define BLUE_LED GPIO_PIN_2
  • 17.
    Createsa constantfor pin2inthe GPIO APImodule thatdisplaysthe blue LED. #define GREEN_LED GPIO_PIN_3 Createsa constantfor pin3 inthe GPIO APImodule thatdisplaysthe greenLED. #define NUM_DISP_TEXT_LINE 4 Createsa constantfor the numberof linesof textdisplayinthe characterpointer"disp_text"witha value of 4. void init_LEDs(void); Thisline declaresthe functionprototype "init_LEDs".Declarationatthispointgivesthe actual functiona global scope.Anyotherfunction,header,or.c file containedinthissource file isgivenaccesstothe functionandaccessible bythe function. void init_timer(void); Thisline declaresthe functionprototype " init_timer".Declarationatthispoint givesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void init_UART(void); Thisline declaresthe functionprototype " init_UART". Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void Timer0_ISR(void); Thisline declaresthe function prototype "Timer0_ISR".Declarationat thispointgivesthe actual functionaglobal scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccess to the functionandaccessible bythe function. extern void UARTStdioIntHandler(void); Thisline declaresafunctionprototype of type "extern".Thisinformsthe microprocessorthatitneedsto access a functionthatexistsoutsideof thissource file.The uartstdio.cfileisincludedinthe project folderfordirectaccess.The uartstdio.cfile hasadditional functionsforthe UARTconsole.Thisparticular functionhandlesinterruptsfromthe UART.The UART has a transmitandreceive bufferthatisusedfor data transfersbetweenthe microprocessorandthe puttyconsole. uint32_t sys_clock; Createsan unsigned32-bitglobal variable forthe systemclock. uint8_t cur_LED = RED_LED;
  • 18.
    Createsan unsigned32-bitglobal variableforthe systemclock. const char *disp_text[NUM_DISP_TEXT_LINE] = { "n", "UART and LED Demon", "H: help, R: red, G: green, B: blue.n", "> " }; Thisline createsa pointer fora systemmessage communicatedtothe userviaputtyconsole.. int main(void){ The main processcallsandacts on variables,macros,definitions,andothersystem functions. uint32_t i; Createsan unsigned32-bitvariable forloops. unsigned char user_cmd; Createsan unsignedcharactervariable foruserinput. SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SystemControl Clock Setsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource. XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloopat400MHZ. SYSDIV_5 divides the clock bythe numberspecifiedgivingcontrol of the frequency. sys_clock = SysCtlClockGet(); Thisline retrievesthe processorclockrate andassignsit toa variable. init_LEDs(); InitializesLEDconfigurationandenables by calling the function definition. init_UART(); InitializesUARTconfigurationandenables by calling the function definition. init_timer(); InitializesTimerconfigurationandenables by calling the function definition. IntMasterEnable(); ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller. TimerEnable(TIMER0_BASE, TIMER_A); ThisTIMER API functionenablesoperationof the timer module.
  • 19.
    for(i=0; i<NUM_DISP_TEXT_LINE; i++) Thislineisa for loopto displayprogrammessage onconsole. UARTprintf(disp_text[i]); Thisfunctionprintsthe message onthe console. while(1) { The while loopprovidesacontinuousloopwhensetto"1". if(UARTRxBytesAvail()) If the UART has available userinput. user_cmd = UARTgetc(); Thisline retrievesthe userinputandstoresitina variable. else user_cmd = 0; Else,the usercommandvariable issetto 0. switch(user_cmd){ Switchcase for the userinputdata. case 'r': Switchcase for red. case ' ': Switchcase for empty. case 'H': Switchcase for H. case 'h': Switchcase for h. for(i=0; i<NUM_DISP_TEXT_LINE; i++) Switchcase displayforlines87-90 is a for looptodisplayconsole message touser viaputty console. UARTprintf(disp_text[i]);
  • 20.
    Thisfunctionprintsthe message ontheputty console. break; Switchcase break. case 'R': Switchcase for redled. case 'r': Switchcase for redled. cur_LED = RED_LED; Storesthe red ledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'B': Switchcase for blue led. case 'b': Switchcase for blue led. cur_LED = BLUE_LED; Storesthe blue ledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'G': Switchcase for green led. case 'g':
  • 21.
    Switchcase for greenled. cur_LED= GREEN_LED; Storesthe greenledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. void init_LEDs(void) User-defined functiondefinitionforinitializingLEDs.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); The SystemControl APIfunctionenablesthe GPIOportF peripheral. GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); The GPIO APIfunctionconfigurespins1,2, and3 of portF for use as GPIO outputs. void init_timer(void) User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); The SystemControl APIfunctionenablesthe timer0peripheral. TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer. TimerLoadSet(TIMER0_BASE, TIMER_A, sys_clock/TIMER0_FREQ -1); The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width timer,andthe load value specifiedbyuser-definedconstants. IntRegister(INT_TIMER0A, Timer0_ISR); The NVICAPIfunctionregistersthe "TIMER0_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER0A);
  • 22.
    The NVICAPIfunctionenables"TIMER0A"asa full-widthtimertobe usedforthe interruptfunction process. TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenablesthe specifictimermodule(TIMER0_Base) forthe timerinterruptsource. The bit maskof the interruptsource tobe enabledis"TIMER_TIMA_TIMEOUT". void init_UART(void) User-definedfunctiondefinitionforinitializingUART.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); The SystemControl APIfunctionenablesthe UART0 peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); The SystemControl APIfunctionenablesthe GPIOA peripheral. GPIOPinConfigure(GPIO_PA0_U0RX); The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is configuredforthe UART peripheral.Pin0is configuredforthe UARTreceiverbuffer. GPIOPinConfigure(GPIO_PA1_U0TX); The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort A's pinmux is configuredforthe UART0 peripheral.Pin1isconfiguredforthe UART transmitterbuffer. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); The GPIO APIfunctionconfigurespinsforuse bythe UART peripheral.GPIOPortA will be the peripheral usedforUART communication.Pins1and2 of port A are available. IntRegister(INT_UART0, UARTStdioIntHandler); The NVICAPIfunctionregistersthe "UARTStdioIntHandler"functiontobe calledwhenthe "UART0" interruptisenabled. UARTStdioConfig(0, UART0_BAUDRATE, sys_clock); The UART driverfunctionconfiguresthe UARTforinput/output.UARTPort0 isthe base that will be used.The user-definedconstant"UART0_BAUDRATE"isthe bitrate forthe UART and the user-defined constant "sys_clock"isthe frequencyusedforthe source clockof the UART module. void Timer0_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
  • 23.
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); The TimerAPIfunctionclearsthe timerinterruptsources.TIMER0 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3)) { If the GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 164. GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); The GPIO APIfunctionwritesa0 to pins1,2, or 3. else { Else the GPIO APIfunction... GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, cur_LED); Writesthe value of the variable "cur_LED" to the correct pin. Problem 4 The NestedVectorInterruptController(NVIC) functionsasaninterrupthandler.Itcansetpriorities in interruptsandenable ordisable themtoo.A registercanbe dedicatedfortopperformance.The controllerhasthe abilitytonestprioritiesandchoose betweenstaticcompilesordynamicrun-time environment. The TimerAPI hasa setof functionsforcontrolling,modifying,andmanaginginterrupts.Itcanrun continuouslyorjustone time ceasingatzeroor the load.It is alsoa full-widthtimerat32.768. Half- widthgivesthe optionof pulse widthmodulationandsynchronization. The Universal AsynchronousReceiver/Transmitter(UART) APIfunctionsasaninterrupthandler,send and receive data,andconfigure andcontrol UART modules.Some of the featuresinclude: programmable baudrate generator,programmable serial interface,line breakgeneration,and detection.
  • 24.
    UART standard IOmodulehasunbufferedandbufferedoperationwithgoodinterrupthandling. Modificationcanbe made if the bufferisfull.The processorcaneliminate instructionsforfull buffersor clearprior to utilization. The ARM Cortex-Mprocessorprovidesimpressive performance andlow powerconsumption.Ithas32- bitarchitecture withsingle-cyclemultiplyinstructionandexcellentinterrupthandling.Unaligneddata access providesefficientmemoryandfastcode executionincreases sleeptime.Itmaintainshigh precisionandhas32 dedicated32-bitregisters.Itsupportsmultiple software platformsand some controllerscome withabuiltinlibraryforquickapplication. Summary and Conclusions The Tiva C SeriesTM4C123G microcontrollerhasattainedbetterprecision,durability,power management,and interruptcontrol. 32-bitarchitecture andunaligneddataaccessdeliversafast processingenvironment.These improvementssetanew tone formicro processingandcreative environments. References TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide. Austin,Texas:TI.