1. Introduction to timers to be used in the subsequent lab on interrupts2. Familiarity with the TM4C123 vector table and the ability to modify it3. Application of interrupts4. Writing Interrupt Service Routines5. Emphasizing the ability to extract information from the datasheet to correctly setup registers.Objective of the labAbility to blink a port F LED at a specific rate using a general purpose timer (section A). Then usinginterrupts to control a GPIO and a timer (section B).What you need for the lab1. The EK-TM4C123 Launchpad (http://www.ti.com/tool/EK-TM4C123GXL)2. TM4C123 data sheet (https://canvas.uw.edu/courses/1205180/files/folder/EkTM4C123GXL?preview=49165887)3. IAR workbench or other IDE4. LEDs (https://learn.adafruit.com/all-about-leds/the-led-datasheet)5. Push buttons(https://www.alps.com/prod/info/E/HTML/Tact/SnapIn/SKHH/SKHHAKA010.html)6. Debouncing (https://canvas.uw.edu/courses/1205180/files/folder/labs?preview=49719211)Section A. General-Purpose TimersTimersThe TM4C123GH6PMGeneral-PurposeTimer Module (GPTM) supports programmable timers that can beused to count or to drive events such as I/O, communication, or analog to digital conversions. The GPTMcontains six 16/32-bit GPTM blocks and six 32/64-bit Wide GPTM blocks. Each GPTM block provides twotimers (referred to as Timer A and Timer B) that can be configured to operate independently orconcatenated to operate as one 32-bit or 64-bit timer. There are other timers available on the Tiva CSeries microcontrollers such as the System Timer (SysTick) and the PWM timer which can be used fordifferent application. The focus of this lab is to configure the general-purpose Timer A.Timer Modes:There are different timer modes that are supported by the microcontroller (please refer to section 11.3.2of the datasheet for more information). Our objective in this lab is to set a timer to blink an LEDperiodically every second and therefore we will use the periodic timer mode.
Initialization and Configuration:In order to use a GPTM successfully, you should follow the following steps as described in section 11.4 inthe datasheet1. Enable the appropriate TIMERn bit in the RCGCTIMER register. We will use Timer 0 whichcorresponds to bit 0 of this register.2. Ensure the timer is disabled by assigning 0 to bit 0 of the register GPTMCTL3. Write the GPTMCFG with a value of 0x00000000. This value 0 is to select 32-bit timerconfiguration4. Configure TnMR field in the GPTMTnMR (replace n with A so the register is GPTMTAMR.5. Configure the direction of the counter to count up or countdown. For this exercise, letscountdown. You need to configure GPTMTnMR6. Load the start value into the GPTM Timer n Interval Load Register (GPTMTnILR). We will startthe counter at 16,000,000 which is the speed of the microcontroller 16MHZ oscillator (p.57 of thedatasheet) so we can have a blink every 1 second.7. If interrupts are required, set the appropriate bits in the GPTM Interrupt Mask RegisterGPTMIMR. We will skip this step for now till interrupts are used in subsequent labs. You do notneed to configure any registers for this step.8. Set the TnEN bit in the GPTMCTL register to enable the timer and start counting. Please note thatwe initially disabled this in step 2 and we are enabling it here by assigning 1 to bit 0 of the registerGPTMCTL9. Poll the GPTMRIS register or wait for the interrupt to be generated (if enabled). In both cases, thestatus flags are cleared by writing a 1 to the appropriate bit of the GPTM Interrupt Clear Register(GPTMICR). This step should tell us when the counter counted all the way down so we can use aloop to poll this register so it should be placed in the infinite while loop of the main.Section A Required Task:1. Update the program you used in lab 1 section A such that you blink one of the 3 LEDs everysecond.2. Update the program you used in lab 1 section B such that2.1) Please refer to the lab1 regarding the hardware setup.2.2) When a button is pressed, the system will respond only if the user holds down the buttonat least 2 seconds.2.3) If the user presses the start/stop button (hold for 2 seconds), but not the passengerbutton, the system will start with the stop stage (where the red LED is on, and other LEDs areoff). After 5 seconds, the system will move to go stage. Then wait for another 5 seconds tochange from go stage to stop stage. In other words, the go and stop stage will last for 5seconds and switch to each other.2.4) If the user presses the passenger button (hold for 2 seconds) to indicate a passenger triesto across the street, the system will stop the current stage and move the warn stageimmediately. The warn stage will last 5 seconds, and move to stop stage.
3. Re-structure your program into functions and reduce the coding in the main to a minimum. Asuggestion is to create a function to initialize the GPIO and another function to initialize thetimer and call them both from the main function.Part B. InterruptsThe Vector TableThe vector table of the TM4C123 Launchpad is shown in Figure 1, which contains the addresses andnumbers of the interrupts. On system reset, the vector table is fixed at address 0x0000.0000. Theprivileged software can write to the Vector Table Offset (VTABLE) register to relocate the vector tablestarts address to a different memory location, in the range 0x0000.0400 to 0x3FFF.FC00 but it is notour objective in this lab to relocate the vector table.When you run a program in debugger mode in IAR, you notice that the first block of Disassembly goesfrom addresses 0x0 to 0x3c (see Figure 2) which matches the vector table contents.Figure 1 vector table of the TM4C123 LaunchPad (figure 2-6 of the datasheet)
Figure 2 Vector table occupies the first block of memory addresses as seen in IAR debuggerThe vector table is implemented in the cstartup_M.c file which is located under the IAR directory.The path of the file is:C:Program Files (x86)IAR SystemsEmbedded Workbench 8.0armsrclibthumbIf you open this file you will find the vector table defined as an array as shown in Figure 3. Notice theorder of the array elements that match the data sheet in figure 1 where the Reserved addresses arerepresented as zeros. To force the vector table array into the ROM, the vector table must be declared as aconstant and this is the reason for using the keyword const. The implementation of each of the vectortable handlers is also included in the same file. Figure 4 shows the prototypes of these handlers which iswhat we will refer to as an Interrupt Service Routine (ISR).
Figure 3 Declaration of the Vector table in the cstartup fileFigure 4 Prototypes of the ISRsOur objective is to modify the cstartup_M.c file to add Interrupt requests IRQs to the vector tableand implement the interrupt service routine(s) that corresponds to the added IRQs. However, wedo NOT want to change the original cstartup_M.c file provided by the IAR software so we willmake a copy of it to our IAR project file.
Task B. 1: Opening the cstartup_M.c for Editing1. Make a copy of your lab 2 section A folder and rename it to lab 2 Section B2. Make a copy of cstartup_M.c from its original directory to your lab3 directory. Open theworkspace in IAR and add the file to your project using the add files options.3. Open the cstartup_M.c file for editing. Note that when its first opened itll be locked for editing soright click on file name in the editor tab and choose to save it. This will bring up a message sayingthat saving will remove the read-only status of the file so hit ok. Now the file can be edited.Task B. 2: Modifying the vector tableOur objective is to add an ISR to handle the timer we created in section A. Table 2-9 on page 104 of thedata sheet lists the interrupts on the TM4C123 controller. The timer 0A is interrupt number 19 whichcorresponds to location 35 in the vector table. Therefore, the vector array in the cstartup_M.c should beappended accordingly as shown in Figure 5. Timer_Handler is the name of the ISR that we willimplement. The name of the ISR is user defined so you can choose any other name for it.Figure 5 Appended vector tableAdditionally you should a prototype and function implementation to Timer_Handler like the originalfunctions included in the cstartup_M.c file. You can use the following prototypeand write it after the other prototypes at the top of the file and use the function definition as
And write it in the same location as other pragmas below the vector arrayNow compile the project and open the debugger. You should see the vector table has been extended in theDisassembly window as shown in Figure 6.Figure 6 Modified vector tableTask B. 3: Implementing an ISR for the Timer 0AThe objective is to use interrupts to check that the timer 0A has timed out. In section A, we used polling inthe while (1) loop to check for the flag and in this lab we want to move this part to an ISR.
4. In section A, we ignore the step that set up the interrupts, you need to enable that by setting theappropriate bits in the GPTMIMR register. The Timer 0A is interrupt number 19 so you shouldconfigure the EN0 register accordingly as explained in the lecture slides.5. Implement the ISR Timer_Handler in the main.c file the same way you would implement anyfunction. Note that whenever the interrupt 19 is enabled, the function Timer_Handler will beexecuted without the programmer calling it. This means that there is no need to check theGPTMRIS register anymore as we did in section A.6. Compile and run the program and you should have the same output as obtained in section A butthis time you are using interrupts.Task B. 4: Controlling the Timer from a user switchImplement an ISR that allows switch PF0 and PF4 to interrupt the circuit. The PF0 switch when pressedshould mask the timers interrupt i.e. the timer should stop working and instead the red LED should beturned on. If switch PF4 is pressed, the timer should turn on and blinks the blue LED every 1 second
Reviews
There are no reviews yet.