SlideShare a Scribd company logo
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
Introduction
Lab 3 continuesthe studyof the TIVA C SeriesTM4C123G MicrocontrollerandCCSsoftware.The lab
introducesmore software driverlibrariesanddifferenttypesof systemcontrols.The analogtodigital
converter(ADC) API andsystemcontrols are the mainfocusof the lab.
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 contains the headerfile 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
usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general
use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition.
#include "driverlib/sysctl.h"
Thisline containsthe headerfile forthe System Control 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 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.
#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 drivers
provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesase tof
functionsforusingthe TIVA UART module.
#include "driverlib/adc.h"
Thisline containsthe header file forADC(Analog-to-Digital)APIdefinitionsandmacros.The header file
isin the directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripherals
and allowsforquickapplication.The ADCAPIprovidesasetof functionsforusingthe TIVA ADCmodule.
#include "utils/uartstdio.h"
Thisline containsthe header file forUART.The header file isinthe directory "utils"of the CCS
software.The utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication.The file
containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added
manuallytolinkthe 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 ADC0_SEQ_NUM 0
Createsa constantusedfor the ADCsample sequence number.
#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".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.
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 init_ADC(void);
Thisline declaresthe functionprototype " init_ADC".Declarationatthispointgivesthe actual function
a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe
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 unsigned8-bitglobal variable forthe redLED.
const char *disp_text[NUM_DISP_TEXT_LINE] = {
"n",
"UART and LED Demon",
"H: help, R: red, G: green, B: blue, T: temperature.n",
"> " };
Thisline createsa pointer fora systemmessage communicated tothe userviaputtyconsole.
uint32_t cur_temp=0, cur_temp_C=0, cur_temp_F=0;
Createsan unsigned32-bitglobal variable forthe temperatures.
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystemfunctions.
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 ClockSetsetsthe clockingof the device.Osc_Mainconfiguresthe oscillatorsource.
XTAL_16MHZ usesa 16 MHZ crystal clock. USE_PLL is a phase lockedloop at400MHZ. 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_ADC();
InitializesADCconfigurationandenables 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 timermodule.
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 usercommand variable 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 touserviaputty.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe puttyconsole.
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 greenled.
case 'g':
Switchcase for greenled.
cur_LED = GREEN_LED;
Storesthe greenledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'T':
Switchcase for temperature sensor.
case 't':
Switchcase for temperature sensor.
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionenablesthe processortotriggerthe ADC sequence capture.
while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas long as data exists.
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionclearsthe ADCinterruptfromoccurringagain.
ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);
Thisfunctionassignsthe captureddatato a variable.
cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;
Thisvariable isassignedthe Celsiustemperatureconversion.
cur_temp_F = (cur_temp_C*9 + 160)/5;
Thisvariable isassignedthe Fahrenheit temperature conversion.
UARTprintf("nTemp = %dC = %dFn> ", cur_temp_C, cur_temp_F);
Thisfunctionprintsthe temperature conversions onthe puttyconsole.
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-definedfunctiondefinitionforinitializingTimer.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 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 calledwhen the "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 init_ADC(void)
User-definedfunctiondefinitionforinitializingADC.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
The SystemControl APIfunctionenablesthe ADC0peripheral.
ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0);
The ADC APIfunctionspecifiesthe base addressforconfiguration,the sequence number,the trigger
type,andorder importance.
ADCSequenceStepConfigure
(ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
The ADC APIfunctionspecifiesthe base addressforconfiguration,,the sequence number,order
importance,andsequence configurationoptionsfortemperaturesensor,interrupts,andend.
ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM);
The ADC APIfunctionenablesthe specificsequence numberforthe selectedbase.
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 GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 194.
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 API function...
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.
Figure 1 Putty Display
Problem 2
#define TIMER1_FREQ 0.5
I defined anothertimerfrequency constant(global) forthe temperature todisplayevery2seconds.
void init_timer1(void);
I createda prototype fortimer1'sinitialization.
void Timer1_ISR(void);
I createda prototype fortimer1'sinterrupt.
init_timer1();
I calledthe init_timer1functiontoinitializethe new timer.
TimerEnable(TIMER1_BASE, TIMER_A);
I enabledthe timermoduleforoperation.
while(1) {
While loopprovidescontinuousloop.
void init_timer1(void)
User-definedfunctiondefinitionfor initializingTimer.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
The SystemControl APIfunctionenablesthe timer1peripheral.
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timer1asa 32-bit full-widthperiodictimer.
TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER1_FREQ );
The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width
timer,andthe load value specifiedbyuser-definedconstants.
IntRegister(INT_TIMER1A, Timer1_ISR);
The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER1A);
The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenablesthe specifictimermodule(TIMER1_Base) forthe timerinterruptsource.
The bit maskof the interruptsource tobe enabledis "TIMER_TIMA_TIMEOUT".
void Timer1_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionenablesthe processortotriggerthe ADC sequence capture.
while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas longas data exists.
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionclearsthe interruptfromoccurringagain.
ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);
Thisfunctionassignsthe captureddatato a variable.
cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;
Thisvariable isassignedthe Celsiustemperatureconversion.
cur_temp_F = (cur_temp_C*9 + 160)/5;
Thisvariable isassignedthe Fahrenheittemperatureconversion.
UARTprintf("nTemp = %dC = %dFn> ", cur_temp_C, cur_temp_F);
Thisfunctionprintsthe temperature conversionsonthe puttyconsole.
Figure 2 Putty Display
Problem 3
FPU isusedfor higherprecision calculationsandvariablesforstoringthe resultsinmemory.The
functionFPULazyStackingEnable allocatesspace onthe stackfor floating-pointstorage.The processor
onlysavesthe contextif itisinvolvedinaninstruction.The interrupthandlerdoesnotsave floating-
pointdata and takesmore time toconfigure the stackfor itsuse.
There isa software driverlibrarythatprovidesFPUAPI.The headerfile isincludedatthe beginningof
the source file.A constant isalso definedforthe space allocatedforstorage.The temperature variables
are savedas floatingpointastheywill be usedmultiple timestodisplaythe temperature if needed.A
variable of type char array isessentiallyusedforthe stringof charactersdisplayingthe temperatures.
The functionsnprintf storesthe formattedtemperaturesinabufferstringforformatdeclarationand
ease of use withrepetition.
Problem 4
#include <stdio.h>
The standard input/outputlibrarywasaddedforthe functionsnprintf.
#include "driverlib/fpu.h"
The FPU driverlibrarywasaddedforthe FPU APIavailability.
#define TIMER1_FREQ .5
I definedanothertimerfrequencyconstant(global) forthe temperature todisplayevery2seconds.
#define TEMP_STR_LEN 20
The constant wasrepeatedfromLab3_3 forthe lengthof the string.
uint32_t cur_temp=0;
The constant was repeatedfromLab3_3 for the unsigned32-bitinteger.
float cur_temp_C=0, cur_temp_F=0;
The constants wasrepeatedfromLab3_3 for the floating-pointtemperatures.
char temp_str[TEMP_STR_LEN];
The constant was repeatedfromLab3_3 for the char array.
void Timer1_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclears the timerinterruptsources.TIMER1 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared.
FPUEnable();
I enabledthe FPUmodule foroperation.
FPULazyStackingEnable();
I enabledthe floating-pointlazystackingformemoryaccess.
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionenablesthe processortotriggerthe ADC sequence capture.
while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
Thisfunctionandwhile loopenablesthe ADCinterruptto capture dataas longas data exists.
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionclearsthe interruptfromoccurringagain.
ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp);
Thisfunctionassignsthe captureddatato a variable.
cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;
Thisvariable isassignedthe Celsiustemperatureconversion.
cur_temp_F = (cur_temp_C*9 + 160)/5;
Thisvariable isassignedthe Fahrenheittemperatureconversion.
snprintf(temp_str, TEMP_STR_LEN, "%.1fC = %.1fF", cur_temp_C, cur_temp_F);
Thisfunctionconfiguresandregistersavariable forfrequentuse of printingfloating-point.
UARTprintf("nTemp = %sn> ", temp_str);
Thisfunctionprintsthe temperature conversionsonthe puttyconsole fromthe configuredvariable.
Figure 3 Putty Display
Problem 5
#include <stdint.h>
Thisline containsthe headerfile forvariabledefinitions.Examplesof the valuesare bitsize,precision,
and signedorunsignedintegers.
#include <stdbool.h>
Thisline containsthe headerfile 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 usedbydriverlibrariesand are hiddenfromthe
programmer.
#include "inc/hw_types.h"
Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the
same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare
usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general
use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition.
#include "driverlib/sysctl.h"
Thisline contains the headerfile forthe SystemControl APIdefinitionsandmacros.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.
#include "driverlib/pin_map.h"
Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe
directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripheralsandallows
for quickapplication.The pin_map APIprovidesamapof the peripheral topinconfiguration.
#include "driverlib/uart.h"
Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API
definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The drivers
provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesasetof
functionsforusingthe TIVA UART module.
#include "driverlib/adc.h"
Thisline containsthe header file forADC(Analog-to-Digital)APIdefinitionsandmacros.The header file
isin the directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripherals
and allowsforquickapplication.The ADCAPIprovidesasetof functionsforusingthe TIVA ADCmodule.
#include "utils/uartstdio.h"
Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS
softwareThe utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication.The file
containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added
manuallytolinkthe filestogether.
#define TIMER0_FREQ 2
I definedanothertimerfrequencyconstant(global) for2Hz.
#define TIMER1_FREQ 1
I definedanothertimerfrequencyconstant(global) for1Hz.
#define ADC_PIN GPIO_PIN_0
Definedconstantforthe pinusedasinput for ADCmodule.
#define TIMER_PIN GPIO_PIN_4
Definedconstantforthe pinusedasinput for Timermodule.
void init_timer(void);
I createda prototype fortimer0'sinitialization.
void Timer0_ISR(void);
I createda prototype fortimer0'sinterrupt.
void init_GPIO(void);
I createda prototype fortimer0'sinitialization.
void init_timer1(void);
I createda prototype fortimer0'sinitialization.
void Timer1_ISR(void);
I createda prototype fortimer0'sinterrupt.
uint8_t cur_LED = RED_LED;
Createsan unsigned8-bitglobal variable forthe systemclock.
uint32_t sys_clock;
Createsan unsigned32-bitglobal variable forthe systemclock.
uint32_t analog_input;
Createsa 32-bit global variable forthe analogsample.
int main(void){
The main processcallsandacts on variables,macros,definitions,andothersystemfunctions.
unsigned char user_cmd;
Createsan unsignedcharactervariable foruserinput.
uint32_t i;
Createsan unsigned32-bitvariable forloops.
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_ADC();
InitializesADCconfigurationandenables by calling the function definition.
init_UART();
InitializesUARTconfigurationandenables by calling the function definition.
init_timer();
InitializesTimerconfigurationandenables by calling the function definition.
init_GPIO();
InitializesGPIOconfigurationandenables by calling the function definition.
init_timer1();
InitializesTimer1configurationand enables by calling the function definition.
IntMasterEnable();
ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller.
TimerEnable(TIMER0_BASE, TIMER_A);
Enable timerwithinterruptsforLEDS.
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 touserviaputty.
UARTprintf(disp_text[i]);
Thisfunctionprintsthe message onthe puttyconsole.
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 greenled.
case 'g':
Switchcase for greenled.
cur_LED = GREEN_LED;
Storesthe greenledincurrentledvariable.
UARTprintf("n> ");
Thisfunctionprintsa newline witha> on the console.
break;
Switchcase break.
case 'A':
Switchcase for analogsensor.
case 'a':
Switchcase for analogsensor.
ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionenablesthe processortotriggerthe ADC sequence capture.
while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) {
Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas longas data exists.
ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM);
Thisfunctionclearsthe ADCinterruptfromoccurringagain.
ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &analog_input);
Thisfunctionassignsthe captureddatato a variable.
UARTprintf("nAnalog Input = %dn> ", analog_input);
Thisfunctionprintsthe analoginputonthe putty console.
case 'D':
Switchcase for digital sensor.
case 'd':
Switchcase for digital sensor
TimerEnable(TIMER1_BASE, TIMER_A);
Thisfunctionenablesthe processortotriggerthe ADC sequence capture.
break;
Switchcase break.
void init_GPIO(void)
User-definedfunctiondefinitionforinitializingGPIO.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
The SystemControl APIfunctionenablesthe GPIODperipheral.
GPIOPinTypeADC(GPIO_PORTD_BASE, ADC_PIN);
Thisfunctionenablesthe pinof choice tosupportADCtype configurations.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
The SystemControl APIfunctionenablesthe GPIOEperipheral.
GPIOPinConfigure(GPIO_PE4_U5RX);
The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort E's pinmux is
configuredforthe UART peripheral.Pin4is configuredforthe receivingbuffer.
GPIOPinTypeTimer(GPIO_PORTE_BASE, TIMER_PIN);
Thisfunctionenablesthe pinof choice tosupportTimertype configurations.
void init_timer1(void)
User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
The SystemControl APIfunctionenablesthe TIMER1 peripheral.
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer.
TimerLoadSet(TIMER1_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_TIMER1A, Timer1_ISR);
The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis
enabled.
IntEnable(INT_TIMER1A);
The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction
process.
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionenables the specifictimermodule(TIMER1_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_1|GPIO_PIN_2|GPIO_PIN_3)) {
If the GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 209.
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.
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 Timer1_ISR(void)
User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0.
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand
"TIMER_TIMA_TIMEOUT" isthe bit maskfor the interruptsource cleared.
GPIOPinRead(GPIO_PORTE_BASE, TIMER_PIN);
ThisGPIO APIfunctionreadspin4 from portE.
UARTprintf("nTimer Input = %dn> ", TIMER_PIN);
Thisfunctionprintsthe timerdatato the puttyconsole.
TimerDisable(TIMER1_BASE, TIMER_A);
Thisfunctiondisablesthe timerforotherinterruptstooccur fromuserinput.
Summary and Conclusions
TimersandSequencesare vital control components whenutilizingthe TivaCSeriesTM4C123GH6PM
microcontroller.The timerandADChave interruptroutines usingthe NVICcontrollertoestablish
periodsforsampling.The samplesare usedinanalog-to-digital conversion.
References
TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide

More Related Content

What's hot

AirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentationAirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentation
Marco Signorini
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V International
 
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to SystemsIEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE Computer Society Computing Now
 
LinuxCNC for Fun & Profit
LinuxCNC for Fun & ProfitLinuxCNC for Fun & Profit
LinuxCNC for Fun & Profit
AlastairDSilva
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
RISC-V International
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
Simen Li
 
Cs 704 d set2
Cs 704 d set2Cs 704 d set2
Cs 704 d set2
Debasis Das
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
Eslam Mohammed
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology
Bharat Biyani
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
anand hd
 
Verilog HDL
Verilog HDLVerilog HDL
Verilog HDL
Mantra VLSI
 
Standard cells library design
Standard cells library designStandard cells library design
Standard cells library design
Bharat Biyani
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
Simen Li
 
Design and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdfDesign and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdf
ChowdappaKv1
 
Q4.11: ARM Architecture
Q4.11: ARM ArchitectureQ4.11: ARM Architecture
Q4.11: ARM Architecture
Linaro
 
I04425457
I04425457I04425457
I04425457
IOSR-JEN
 
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
IJET - International Journal of Engineering and Techniques
 
Micro lec note2
Micro lec note2Micro lec note2
Micro lec note2
Jaimon Jacob
 
Micro lec note2 (1)
Micro lec note2 (1)Micro lec note2 (1)
Micro lec note2 (1)
pooja jaiswal
 
FPGA Implementation of High Speed FIR Filters and less power consumption stru...
FPGA Implementation of High Speed FIR Filters and less power consumption stru...FPGA Implementation of High Speed FIR Filters and less power consumption stru...
FPGA Implementation of High Speed FIR Filters and less power consumption stru...
International Journal of Engineering Inventions www.ijeijournal.com
 

What's hot (20)

AirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentationAirSensEUR: AirQuality monitoring open framework technical presentation
AirSensEUR: AirQuality monitoring open framework technical presentation
 
RISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentorRISC-V 30907 summit 2020 joint picocom_mentor
RISC-V 30907 summit 2020 joint picocom_mentor
 
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to SystemsIEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
IEEE 1149.1-2013 Addresses Challenges in Test Re-Use from IP to IC to Systems
 
LinuxCNC for Fun & Profit
LinuxCNC for Fun & ProfitLinuxCNC for Fun & Profit
LinuxCNC for Fun & Profit
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
[ZigBee 嵌入式系統] ZigBee 應用實作 - 使用 TI Z-Stack Firmware
 
Cs 704 d set2
Cs 704 d set2Cs 704 d set2
Cs 704 d set2
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology32 bit ALU Chip Design using IBM 130nm process technology
32 bit ALU Chip Design using IBM 130nm process technology
 
Modules and ports in Verilog HDL
Modules and ports in Verilog HDLModules and ports in Verilog HDL
Modules and ports in Verilog HDL
 
Verilog HDL
Verilog HDLVerilog HDL
Verilog HDL
 
Standard cells library design
Standard cells library designStandard cells library design
Standard cells library design
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
 
Design and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdfDesign and Implementation of 64 Bit RISC Processor Using System.pdf
Design and Implementation of 64 Bit RISC Processor Using System.pdf
 
Q4.11: ARM Architecture
Q4.11: ARM ArchitectureQ4.11: ARM Architecture
Q4.11: ARM Architecture
 
I04425457
I04425457I04425457
I04425457
 
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
[IJET-V1I3P17] Authors :Prof. U. R. More. S. R. Adhav
 
Micro lec note2
Micro lec note2Micro lec note2
Micro lec note2
 
Micro lec note2 (1)
Micro lec note2 (1)Micro lec note2 (1)
Micro lec note2 (1)
 
FPGA Implementation of High Speed FIR Filters and less power consumption stru...
FPGA Implementation of High Speed FIR Filters and less power consumption stru...FPGA Implementation of High Speed FIR Filters and less power consumption stru...
FPGA Implementation of High Speed FIR Filters and less power consumption stru...
 

Similar to DSP_Assign_3

DSP_Assign_1
DSP_Assign_1DSP_Assign_1
DSP_Assign_1
Joseph Chandler
 
Research Inventy: International Journal of Engineering and Science
Research Inventy: International Journal of Engineering and ScienceResearch Inventy: International Journal of Engineering and Science
Research Inventy: International Journal of Engineering and Science
researchinventy
 
Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...
researchinventy
 
Practical Distributed Control Systems (DCS) for Engineers and Technicians
Practical Distributed Control Systems (DCS) for Engineers and TechniciansPractical Distributed Control Systems (DCS) for Engineers and Technicians
Practical Distributed Control Systems (DCS) for Engineers and Technicians
Living Online
 
SCADA - Wikipedia, the free encyclopedia
SCADA - Wikipedia, the free encyclopediaSCADA - Wikipedia, the free encyclopedia
SCADA - Wikipedia, the free encyclopedia
Raj Bakshi
 
Short.course.introduction.to.vhdl
Short.course.introduction.to.vhdlShort.course.introduction.to.vhdl
Short.course.introduction.to.vhdl
Ravi Sony
 
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
Editor IJCATR
 
Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners
Ravi Sony
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
sean chen
 
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
IJERA Editor
 
Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...
IRJET Journal
 
Rohan Narula_Resume
Rohan Narula_ResumeRohan Narula_Resume
Rohan Narula_Resume
Rohan Narula
 
Plc and scada project ppt
Plc and scada project pptPlc and scada project ppt
Plc and scada project ppt
Priya Hada
 
pdfslide.net_plc-and-scada-project-ppt.pdf
pdfslide.net_plc-and-scada-project-ppt.pdfpdfslide.net_plc-and-scada-project-ppt.pdf
pdfslide.net_plc-and-scada-project-ppt.pdf
PrafulPatel54
 
03 scada.synopsis
03 scada.synopsis03 scada.synopsis
03 scada.synopsis
Praveen Walishetti
 
Ch09
Ch09Ch09
Effisiensi prog atmel
Effisiensi prog atmelEffisiensi prog atmel
Effisiensi prog atmel
rm_dhozooo
 
Design & Simulation of RISC Processor using Hyper Pipelining Technique
Design & Simulation of RISC Processor using Hyper Pipelining TechniqueDesign & Simulation of RISC Processor using Hyper Pipelining Technique
Design & Simulation of RISC Processor using Hyper Pipelining Technique
IOSR Journals
 
Embedded concepts
Embedded conceptsEmbedded concepts
Embedded concepts
sartaj ahmed
 
DEVENDRAPLC .pptx
DEVENDRAPLC .pptxDEVENDRAPLC .pptx
DEVENDRAPLC .pptx
DEVENDRA SHRIVASH
 

Similar to DSP_Assign_3 (20)

DSP_Assign_1
DSP_Assign_1DSP_Assign_1
DSP_Assign_1
 
Research Inventy: International Journal of Engineering and Science
Research Inventy: International Journal of Engineering and ScienceResearch Inventy: International Journal of Engineering and Science
Research Inventy: International Journal of Engineering and Science
 
Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...
 
Practical Distributed Control Systems (DCS) for Engineers and Technicians
Practical Distributed Control Systems (DCS) for Engineers and TechniciansPractical Distributed Control Systems (DCS) for Engineers and Technicians
Practical Distributed Control Systems (DCS) for Engineers and Technicians
 
SCADA - Wikipedia, the free encyclopedia
SCADA - Wikipedia, the free encyclopediaSCADA - Wikipedia, the free encyclopedia
SCADA - Wikipedia, the free encyclopedia
 
Short.course.introduction.to.vhdl
Short.course.introduction.to.vhdlShort.course.introduction.to.vhdl
Short.course.introduction.to.vhdl
 
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
Design and Implementing Novel Independent Real-Time Software Programmable DAQ...
 
Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners Short.course.introduction.to.vhdl for beginners
Short.course.introduction.to.vhdl for beginners
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
Implementation of T-Junction Traffic Light Control System Using Simatic S7-20...
 
Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...Development of Software for Estimation of Structural Dynamic Characteristics ...
Development of Software for Estimation of Structural Dynamic Characteristics ...
 
Rohan Narula_Resume
Rohan Narula_ResumeRohan Narula_Resume
Rohan Narula_Resume
 
Plc and scada project ppt
Plc and scada project pptPlc and scada project ppt
Plc and scada project ppt
 
pdfslide.net_plc-and-scada-project-ppt.pdf
pdfslide.net_plc-and-scada-project-ppt.pdfpdfslide.net_plc-and-scada-project-ppt.pdf
pdfslide.net_plc-and-scada-project-ppt.pdf
 
03 scada.synopsis
03 scada.synopsis03 scada.synopsis
03 scada.synopsis
 
Ch09
Ch09Ch09
Ch09
 
Effisiensi prog atmel
Effisiensi prog atmelEffisiensi prog atmel
Effisiensi prog atmel
 
Design & Simulation of RISC Processor using Hyper Pipelining Technique
Design & Simulation of RISC Processor using Hyper Pipelining TechniqueDesign & Simulation of RISC Processor using Hyper Pipelining Technique
Design & Simulation of RISC Processor using Hyper Pipelining Technique
 
Embedded concepts
Embedded conceptsEmbedded concepts
Embedded concepts
 
DEVENDRAPLC .pptx
DEVENDRAPLC .pptxDEVENDRAPLC .pptx
DEVENDRAPLC .pptx
 

DSP_Assign_3

  • 1. 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
  • 2. Introduction Lab 3 continuesthe studyof the TIVA C SeriesTM4C123G MicrocontrollerandCCSsoftware.The lab introducesmore software driverlibrariesanddifferenttypesof systemcontrols.The analogtodigital converter(ADC) API andsystemcontrols are the mainfocusof the lab. 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 contains the headerfile 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 usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition. #include "driverlib/sysctl.h" Thisline containsthe headerfile forthe System Control APIdefinitionsandmacros.The headerfile isin the directory"driverlib"of the CCSsoftware.The file isconsideredpartof the currentprogram when
  • 3. "#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 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. #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 drivers provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesase tof functionsforusingthe TIVA UART module. #include "driverlib/adc.h" Thisline containsthe header file forADC(Analog-to-Digital)APIdefinitionsandmacros.The header file isin the directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripherals and allowsforquickapplication.The ADCAPIprovidesasetof functionsforusingthe TIVA ADCmodule. #include "utils/uartstdio.h" Thisline containsthe header file forUART.The header file isinthe directory "utils"of the CCS software.The utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication.The file
  • 4. containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added manuallytolinkthe 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 ADC0_SEQ_NUM 0 Createsa constantusedfor the ADCsample sequence number. #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".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. void init_UART(void);
  • 5. Thisline declaresthe functionprototype " init_UART".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe functionandaccessible bythe function. void init_ADC(void); Thisline declaresthe functionprototype " init_ADC".Declarationatthispointgivesthe actual function a global scope.Anyotherfunction,header,or.cfile containedinthissource fileisgivenaccesstothe 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 unsigned8-bitglobal variable forthe redLED. const char *disp_text[NUM_DISP_TEXT_LINE] = { "n", "UART and LED Demon", "H: help, R: red, G: green, B: blue, T: temperature.n", "> " }; Thisline createsa pointer fora systemmessage communicated tothe userviaputtyconsole. uint32_t cur_temp=0, cur_temp_C=0, cur_temp_F=0; Createsan unsigned32-bitglobal variable forthe temperatures. int main(void){ The main processcallsandacts on variables,macros,definitions,andothersystemfunctions. uint32_t i; Createsan unsigned32-bitvariable forloops. unsigned char user_cmd; Createsan unsignedcharactervariable foruserinput.
  • 6. 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 lockedloop at400MHZ. 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_ADC(); InitializesADCconfigurationandenables 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 timermodule. 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();
  • 7. Thisline retrievesthe userinputandstoresitina variable. else user_cmd = 0; Else,the usercommand variable 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 touserviaputty. UARTprintf(disp_text[i]); Thisfunctionprintsthe message onthe puttyconsole. break; Switchcase break. case 'R': Switchcase for redled. case 'r': Switchcase for redled. cur_LED = RED_LED; Storesthe red ledincurrentledvariable.
  • 8. 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 greenled. case 'g': Switchcase for greenled. cur_LED = GREEN_LED; Storesthe greenledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'T': Switchcase for temperature sensor.
  • 9. case 't': Switchcase for temperature sensor. ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionenablesthe processortotriggerthe ADC sequence capture. while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) { Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas long as data exists. ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionclearsthe ADCinterruptfromoccurringagain. ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp); Thisfunctionassignsthe captureddatato a variable. cur_temp_C = (1475 - (2475*cur_temp)/4096)/10; Thisvariable isassignedthe Celsiustemperatureconversion. cur_temp_F = (cur_temp_C*9 + 160)/5; Thisvariable isassignedthe Fahrenheit temperature conversion. UARTprintf("nTemp = %dC = %dFn> ", cur_temp_C, cur_temp_F); Thisfunctionprintsthe temperature conversions onthe puttyconsole. 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-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); The SystemControl APIfunctionenablesTIMER0 peripheral.
  • 10. 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.
  • 11. IntRegister(INT_UART0, UARTStdioIntHandler); The NVICAPIfunctionregistersthe "UARTStdioIntHandler"functiontobe calledwhen the "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 init_ADC(void) User-definedfunctiondefinitionforinitializingADC.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); The SystemControl APIfunctionenablesthe ADC0peripheral. ADCSequenceConfigure(ADC0_BASE, ADC0_SEQ_NUM, ADC_TRIGGER_PROCESSOR, 0); The ADC APIfunctionspecifiesthe base addressforconfiguration,the sequence number,the trigger type,andorder importance. ADCSequenceStepConfigure (ADC0_BASE, ADC0_SEQ_NUM, 0, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END); The ADC APIfunctionspecifiesthe base addressforconfiguration,,the sequence number,order importance,andsequence configurationoptionsfortemperaturesensor,interrupts,andend. ADCSequenceEnable(ADC0_BASE, ADC0_SEQ_NUM); The ADC APIfunctionenablesthe specificsequence numberforthe selectedbase. 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 GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 194. GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); The GPIO APIfunctionwritesa0 to pins1,2, or 3.
  • 12. else { Else the GPIO API function... 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. Figure 1 Putty Display Problem 2 #define TIMER1_FREQ 0.5 I defined anothertimerfrequency constant(global) forthe temperature todisplayevery2seconds. void init_timer1(void); I createda prototype fortimer1'sinitialization. void Timer1_ISR(void); I createda prototype fortimer1'sinterrupt. init_timer1(); I calledthe init_timer1functiontoinitializethe new timer. TimerEnable(TIMER1_BASE, TIMER_A); I enabledthe timermoduleforoperation. while(1) { While loopprovidescontinuousloop. void init_timer1(void) User-definedfunctiondefinitionfor initializingTimer.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); The SystemControl APIfunctionenablesthe timer1peripheral.
  • 13. TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); The TimerAPI functionconfiguresthe timer1asa 32-bit full-widthperiodictimer. TimerLoadSet(TIMER1_BASE, TIMER_A, sys_clock/TIMER1_FREQ ); The TimerAPI functionspecifiesthe base addressforconfiguration,the correctname fora full-width timer,andthe load value specifiedbyuser-definedconstants. IntRegister(INT_TIMER1A, Timer1_ISR); The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER1A); The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction process. TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenablesthe specifictimermodule(TIMER1_Base) forthe timerinterruptsource. The bit maskof the interruptsource tobe enabledis "TIMER_TIMA_TIMEOUT". void Timer1_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionenablesthe processortotriggerthe ADC sequence capture. while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) { Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas longas data exists. ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionclearsthe interruptfromoccurringagain. ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp); Thisfunctionassignsthe captureddatato a variable. cur_temp_C = (1475 - (2475*cur_temp)/4096)/10;
  • 14. Thisvariable isassignedthe Celsiustemperatureconversion. cur_temp_F = (cur_temp_C*9 + 160)/5; Thisvariable isassignedthe Fahrenheittemperatureconversion. UARTprintf("nTemp = %dC = %dFn> ", cur_temp_C, cur_temp_F); Thisfunctionprintsthe temperature conversionsonthe puttyconsole. Figure 2 Putty Display Problem 3 FPU isusedfor higherprecision calculationsandvariablesforstoringthe resultsinmemory.The functionFPULazyStackingEnable allocatesspace onthe stackfor floating-pointstorage.The processor onlysavesthe contextif itisinvolvedinaninstruction.The interrupthandlerdoesnotsave floating- pointdata and takesmore time toconfigure the stackfor itsuse. There isa software driverlibrarythatprovidesFPUAPI.The headerfile isincludedatthe beginningof the source file.A constant isalso definedforthe space allocatedforstorage.The temperature variables are savedas floatingpointastheywill be usedmultiple timestodisplaythe temperature if needed.A variable of type char array isessentiallyusedforthe stringof charactersdisplayingthe temperatures. The functionsnprintf storesthe formattedtemperaturesinabufferstringforformatdeclarationand ease of use withrepetition. Problem 4 #include <stdio.h> The standard input/outputlibrarywasaddedforthe functionsnprintf.
  • 15. #include "driverlib/fpu.h" The FPU driverlibrarywasaddedforthe FPU APIavailability. #define TIMER1_FREQ .5 I definedanothertimerfrequencyconstant(global) forthe temperature todisplayevery2seconds. #define TEMP_STR_LEN 20 The constant wasrepeatedfromLab3_3 forthe lengthof the string. uint32_t cur_temp=0; The constant was repeatedfromLab3_3 for the unsigned32-bitinteger. float cur_temp_C=0, cur_temp_F=0; The constants wasrepeatedfromLab3_3 for the floating-pointtemperatures. char temp_str[TEMP_STR_LEN]; The constant was repeatedfromLab3_3 for the char array. void Timer1_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclears the timerinterruptsources.TIMER1 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bitmaskfor the interruptsource cleared. FPUEnable(); I enabledthe FPUmodule foroperation. FPULazyStackingEnable(); I enabledthe floating-pointlazystackingformemoryaccess. ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionenablesthe processortotriggerthe ADC sequence capture. while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) { Thisfunctionandwhile loopenablesthe ADCinterruptto capture dataas longas data exists. ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionclearsthe interruptfromoccurringagain.
  • 16. ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &cur_temp); Thisfunctionassignsthe captureddatato a variable. cur_temp_C = (1475 - (2475*cur_temp)/4096)/10; Thisvariable isassignedthe Celsiustemperatureconversion. cur_temp_F = (cur_temp_C*9 + 160)/5; Thisvariable isassignedthe Fahrenheittemperatureconversion. snprintf(temp_str, TEMP_STR_LEN, "%.1fC = %.1fF", cur_temp_C, cur_temp_F); Thisfunctionconfiguresandregistersavariable forfrequentuse of printingfloating-point. UARTprintf("nTemp = %sn> ", temp_str); Thisfunctionprintsthe temperature conversionsonthe puttyconsole fromthe configuredvariable. Figure 3 Putty Display Problem 5 #include <stdint.h> Thisline containsthe headerfile forvariabledefinitions.Examplesof the valuesare bitsize,precision, and signedorunsignedintegers. #include <stdbool.h> Thisline containsthe headerfile 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"
  • 17. Thisline containsthe headerfile forthe TivaCSeriesdevice memorymapdefinitions.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.The headerfilecontainsmacros and definitionstosimplifyprogrammingthe peripheral'sregistersandinterruptcontrol.Thisis containedinthe incdirectory.The definitionsare usedbydriverlibrariesand are hiddenfromthe programmer. #include "inc/hw_types.h" Thisline containsthe headerfile forcommontypesandmacros.The headerfile containsmanyof the same definitionsusedfordirectregisteraccess.Thisiscontainedinthe incdirectory.The definitionsare usedbydriverlibrariesandare hiddenfromthe programmer.The valuesare a wide varietyof general use for itemssuchas arithmetic,clocktiming,file recognition,anddevicerecognition. #include "driverlib/sysctl.h" Thisline contains the headerfile forthe SystemControl APIdefinitionsandmacros.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. #include "driverlib/pin_map.h" Thisline containsthe headerfile forpin_mapAPIdefinitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripheralsandallows for quickapplication.The pin_map APIprovidesamapof the peripheral topinconfiguration. #include "driverlib/uart.h" Thisline containsthe headerfile forUART(Universal AsynchronousReceiver/Transmitter) API definitionsandmacros.The headerfile isinthe directory"driverlib"of the CCSsoftware.The drivers
  • 18. provide quickcontrol of the peripheralsandallowsforquickapplication.The UARTAPIprovidesasetof functionsforusingthe TIVA UART module. #include "driverlib/adc.h" Thisline containsthe header file forADC(Analog-to-Digital)APIdefinitionsandmacros.The header file isin the directory"driverlib"of the CCSsoftware.The driversprovidequickcontrol of the peripherals and allowsforquickapplication.The ADCAPIprovidesasetof functionsforusingthe TIVA ADCmodule. #include "utils/uartstdio.h" Thisline containsthe header file forUART.The header file isinthe directory"utils"of the CCS softwareThe utilityprovidesquickcontrol of the peripheralsandallowsforquickapplication.The file containsprototypesforthe UART console functions.Onbuildingthe project,the .cfile hadtobe added manuallytolinkthe filestogether. #define TIMER0_FREQ 2 I definedanothertimerfrequencyconstant(global) for2Hz. #define TIMER1_FREQ 1 I definedanothertimerfrequencyconstant(global) for1Hz. #define ADC_PIN GPIO_PIN_0 Definedconstantforthe pinusedasinput for ADCmodule. #define TIMER_PIN GPIO_PIN_4 Definedconstantforthe pinusedasinput for Timermodule. void init_timer(void); I createda prototype fortimer0'sinitialization. void Timer0_ISR(void); I createda prototype fortimer0'sinterrupt. void init_GPIO(void); I createda prototype fortimer0'sinitialization. void init_timer1(void); I createda prototype fortimer0'sinitialization. void Timer1_ISR(void); I createda prototype fortimer0'sinterrupt.
  • 19. uint8_t cur_LED = RED_LED; Createsan unsigned8-bitglobal variable forthe systemclock. uint32_t sys_clock; Createsan unsigned32-bitglobal variable forthe systemclock. uint32_t analog_input; Createsa 32-bit global variable forthe analogsample. int main(void){ The main processcallsandacts on variables,macros,definitions,andothersystemfunctions. unsigned char user_cmd; Createsan unsignedcharactervariable foruserinput. uint32_t i; Createsan unsigned32-bitvariable forloops. 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_ADC(); InitializesADCconfigurationandenables by calling the function definition. init_UART(); InitializesUARTconfigurationandenables by calling the function definition. init_timer(); InitializesTimerconfigurationandenables by calling the function definition. init_GPIO();
  • 20. InitializesGPIOconfigurationandenables by calling the function definition. init_timer1(); InitializesTimer1configurationand enables by calling the function definition. IntMasterEnable(); ThisNVICAPIfunctionenablesinterruptsfromthe microprocessortointerruptcontroller. TimerEnable(TIMER0_BASE, TIMER_A); Enable timerwithinterruptsforLEDS. 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':
  • 21. 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 touserviaputty. UARTprintf(disp_text[i]); Thisfunctionprintsthe message onthe puttyconsole. 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> ");
  • 22. Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'G': Switchcase for greenled. case 'g': Switchcase for greenled. cur_LED = GREEN_LED; Storesthe greenledincurrentledvariable. UARTprintf("n> "); Thisfunctionprintsa newline witha> on the console. break; Switchcase break. case 'A': Switchcase for analogsensor. case 'a': Switchcase for analogsensor. ADCProcessorTrigger(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionenablesthe processortotriggerthe ADC sequence capture. while(!ADCIntStatus(ADC0_BASE, ADC0_SEQ_NUM, false)) { Thisfunctionandwhile loopenablesthe ADCinterrupttocapture dataas longas data exists. ADCIntClear(ADC0_BASE, ADC0_SEQ_NUM); Thisfunctionclearsthe ADCinterruptfromoccurringagain. ADCSequenceDataGet(ADC0_BASE, ADC0_SEQ_NUM, &analog_input); Thisfunctionassignsthe captureddatato a variable. UARTprintf("nAnalog Input = %dn> ", analog_input);
  • 23. Thisfunctionprintsthe analoginputonthe putty console. case 'D': Switchcase for digital sensor. case 'd': Switchcase for digital sensor TimerEnable(TIMER1_BASE, TIMER_A); Thisfunctionenablesthe processortotriggerthe ADC sequence capture. break; Switchcase break. void init_GPIO(void) User-definedfunctiondefinitionforinitializingGPIO.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); The SystemControl APIfunctionenablesthe GPIODperipheral. GPIOPinTypeADC(GPIO_PORTD_BASE, ADC_PIN); Thisfunctionenablesthe pinof choice tosupportADCtype configurations. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); The SystemControl APIfunctionenablesthe GPIOEperipheral. GPIOPinConfigure(GPIO_PE4_U5RX); The GPIO APIfunctionconfiguresthe alternate functionof aGPIO pin.GPIOPort E's pinmux is configuredforthe UART peripheral.Pin4is configuredforthe receivingbuffer. GPIOPinTypeTimer(GPIO_PORTE_BASE, TIMER_PIN); Thisfunctionenablesthe pinof choice tosupportTimertype configurations. void init_timer1(void) User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0. SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); The SystemControl APIfunctionenablesthe TIMER1 peripheral. TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
  • 24. The TimerAPI functionconfiguresthe timerasa 32-bitfull-widthperiodictimer. TimerLoadSet(TIMER1_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_TIMER1A, Timer1_ISR); The NVICAPIfunctionregistersthe "TIMER1_ISR"functiontobe calledwhenthe "TIMER0A"interruptis enabled. IntEnable(INT_TIMER1A); The NVICAPIfunctionenables"TIMER1A"asa full-widthtimer tobe usedforthe interruptfunction process. TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionenables the specifictimermodule(TIMER1_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_1|GPIO_PIN_2|GPIO_PIN_3)) { If the GPIOAPIfunctionreadspins1,2, or 3 fromport F, readline 209. 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. void init_timer(void) User-definedfunctiondefinitionforinitializingTimer.The functionreturnsavalue of 0.
  • 25. 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 Timer1_ISR(void) User-definedfunctiondefinitionforinterrupthandler.The functionreturnsavalue of 0. TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); The TimerAPI functionclearsthe timerinterruptsources.TIMER1 isthe base specifiedand "TIMER_TIMA_TIMEOUT" isthe bit maskfor the interruptsource cleared. GPIOPinRead(GPIO_PORTE_BASE, TIMER_PIN); ThisGPIO APIfunctionreadspin4 from portE. UARTprintf("nTimer Input = %dn> ", TIMER_PIN); Thisfunctionprintsthe timerdatato the puttyconsole. TimerDisable(TIMER1_BASE, TIMER_A); Thisfunctiondisablesthe timerforotherinterruptstooccur fromuserinput. Summary and Conclusions
  • 26. TimersandSequencesare vital control components whenutilizingthe TivaCSeriesTM4C123GH6PM microcontroller.The timerandADChave interruptroutines usingthe NVICcontrollertoestablish periodsforsampling.The samplesare usedinanalog-to-digital conversion. References TexasInstruments.(2014). TivaWarePeripheral Driver Library: User'sGuide