You are on page 1of 13

UNIVERSIDAD TECNOLÓGICA DE QUERÉTARO

CA INGENIERÍA EN TECNOLOGÍAS DE AUTOMATIZACIÓN


MANUAL PARA LA ELABORACIÓN DE PRÁCTICAS

Título de la práctica: Lab4 Interrupts and the Timers


Nombre del alumno: Toribio Montoya Eduardo
Asignatura: Dispositivos Digitales Programables Hoja: 1 de 5
Unidad temática: II. Sistemas digitales embebidos en PLD's Fecha: 23 septiembre 2020
No. de participantes recomendados: Individual Elaboró: José Felipe Aguilar Pereyra
Duración: 2 h Lugar: Laboratorio virtual Revisó: Academia de Dispositivos Digitales Prog.
Aprobó: Coord. Acad. Ing. Tec. Automatización Revisión: 0 1 2 3 4
Fecha: 15 sept 2020 07 feb 2021

Objective of the practice:

The objective of this lab is to set up the timer to generate interrupts, and then write the code that responds to the interrupt …
flashing the LED. We’ll also experiment with generating a system level exception, by attempting to configure a peripheral before it’s
been enabled. (Texas Instruments, 2013)

Theoretical Foundation:
Describe Nested Vectored Interrupt Controller (NVIC)
Describe Interrupt Latency - Tail Chaining

In the above example, two interrupts occur simultaneously. In most processors, interrupt handling is fairly simple and each interrupt
will start a PUSH PROCESSOR STATE – RUN ISR – POP PROCESSOR STATE process. Since IRQ1 was higher priority, the
NVIC causes the CPU to run it first. When the interrupt handler (ISR) for the first interrupt is complete, the NVIC sees a second
interrupt pending, and runs that ISR. This is quite wasteful since the middle POP and PUSH are moving the exact same processor
state back and forth to stack memory. If the interrupt handler could have seen that a second interrupt was pending, it could have
“tail-chained” into the next ISR, saving power and cycles.

The Tiva C Series NVIC does exactly this. It takes only 12 cycles to PUSH and POP the processor state. When the NVIC sees a
pending ISR during the execution of the current one, it will “tail-chain” the execution using just 6 cycles to complete the process.

If you are depending on interrupts to be run quickly, the Tiva C Series devices offer a huge advantage here.

Describe Cortex-M4® Interrupt Handling


Describe Cortex-M4® Exception Types

Describe Cortex-M4® Vector Table

Describe General Purpose Timer Module


Problem Statement

1. Leer el Workbook sección Interrupts and the Timers


2. Crear un nuevo proyecto CCS Laboratory_4
3. Configurar el Timer0
4. Calcular el periodo del temporizador Timer0
5. Habilitar la interrupción del Timer0
6. Configurar la función de manejo de la interrupción del Timer0
7. Construir, cargar y ejecutar el programa.
8. Incorporar la configuración de periféricos en una función: void configuracionPerifericos(void)

Materials

Tiva C Series TM4C123G Evaluation Kit


PC con Code Composer Studio y Tivaware

Customer requirements:

Generar una frecuencia de 1 Hz con activación de led azul por 500 ms y led rojo por 500ms alternada y periódicamente.

Blocks diagram

Terminal Assignment

Terminal Nombre Función Tipo


29 PF1 LED_R GPIO/0
30 PF2 LED_B GPIO/0
31 PF3 LED_G GPIO/0
28 PF0 USR_SW2 GPIO/I
5 PF4 USR_SW1 GPIO/I
electronic diagram
Anexo 1
Flowchart

main function diagram

Start

Declare 32-bit variable ui32Period

Start system clock 40MHz

Peripheral configuration

Enable and set timer0

Calculation of the number of system clock pulses


needed to generate a period/timing of (1/10 Hz)/2

Set the Load value of the timer

enable interrupt

Start the timer operation

no

While (1) end


End

si

Void
function diagram Timer0AInHandler

Start

Clear interrupt flag of


timer0 subtimer A

no

pf2==1 disable p1 enable pf2

si

disable pf2 enable pf1

end
End

developed code
/* Projecto Documentation
@Company
Universidad Tecnológica de Querétaro

@Project Name
ITA56Lap4TME

@File Name
main.c

@version 2

@Toribio Montoya Eduardo

@Summary
This is generated main .c using TivaWare and TM4C123G MCU, Timer 0 and its
interuption.
@Description
This source file initialize the clock system and the GPIO peripheral using
TivaWare.
we’ll set up the timer0 to generate interrupts, and then write the code that
responds to
the interrupt flashing the blue LED PF2.
Generation Information :
Product Revision : TM4C123GXL - 1.168.0
Device : TM4C123GH6PM7
The generated drivers are tested against the following:
Languaje : C ANSI C 89 Mode
Compiler : TIv16.9.6LTS
CCS : CCS v7.4.0.00015
*/

/*
(c) 2020 Toribio Montoya Eduardo. You may use this
software and any derivatives exclusively with Texas Instruments products.

THIS SOFTWARE IS SUPPLIED BY Toribio Montoya Eduardo "AS IS". NO WARRANTIES,


WHETHER
EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
PARTICULAR PURPOSE, OR ITS INTERACTION WITH TEXAS INSTRUMENTS PRODUCTS,
COMBINATION
WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

Toribio Montoya Eduardo PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
OF THESE
TERMS.
*/
#include <stdint.h> //incluye Definiciones de variables para estandar
c99
#include <stdbool.h> //incluye Definiciones de boleanos para estandar
c99
#include "inc/tm4c123gh6pm.h" //Incluir definiciones para las interupciones del
dispositivo tiva c
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h" //incluye Definiciones y macros del sistema de
control
#include "driverlib/interrupt.h" //Incluir definiciones y macros para el
controlador NVIC
#include "driverlib/gpio.h" //incluye Definiciones y macros para GPIO
#include "driverlib/timer.h" //Incluir definiciones y macros para el
Temporizador
/**
* main.c
*/

int main(void)
{

uint32_t ui32Period; // Declara variable 32 bits ui32Period

SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
// establecer el reloj del control del sistema a 40MHz
//Configuracion de perifericos
// GPIO
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//Habilita periferico puerto F
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//Configurar de tipo GPIO salida las terminales PF1, PF2, PF3
//Timer0
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Habilita el timer0
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);// Configura timer0 y en modo
periodo

ui32Period = (SysCtlClockGet() / 1) / 2;// Calculo del numero de pulsos del


reloj del sistema necesarios para generar un periodo/temporizacion de (1/10 Hz)/2
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);// Establecer el valor de
Carga del temporizador (para un periodo de 1/1Hz/2)

//Habilitar interrupcion
IntEnable(INT_TIMER0A); //Habilita la interrupcion del timer0A
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Configurar la habilitacion
por fin de conteo
IntMasterEnable(); //habilitar el control maeStro de las
interupciones

//Iniciar el funcionamiento del temporizador


TimerEnable(TIMER0_BASE, TIMER_A);

while(1)
// Ciclo while
{

}
// Rutina del servicio de rutina a la interrupcion del timer 0 subtimer A
void Timer0AIntHandler(void)
{
// Clear the timer interrupt
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);// Limpiar la bandera de interrupcion
del timer0
// Read the current state of the GPIO pin and
// write back the opposite state
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2)) //Evaluar el
estado de PF2 (si pf2==1)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0); //
desactivar (pf)azul
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2); //
Activar pf1 rojo

}
else // en
caso contrario
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);//
desactivar (pf) rojo
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 4);//
Activar pf2 azul
}
}
Evidence
1 Connect microcontroller.
2 Open the ITA56Lab4TME project.
3 Verify that a 32-bit variable was created.
4. Enable our f-port peripherals
5. Set Timer0
6 Calculate the timer period Timer0
7. Configure Timer0 interrupt handling function
verify that the function void configurationPeripherals(void)
8. Verify that the blue LED lights up for 500ms
9. Verify that the blue LED turns off and immediately the red LED turns on for 500 ms
10. Verify that this sequence continues until we turn off our microcontroller

Results
2 Open the ITA56Lab4TME project.

3 Verify that a 32-bit variable was created.


4. Enable our f-port peripherals

5. Set Timer0

6 Calculate the timer period Timer0

F = 1Hz T
toff ton

tsignal 0.5 s 0.5 s


z

Timer 0
Pulso del sysclk

F sysclk 40MHz 25ns


T timer0 1s
0.5 s

7. Configure Timer0 interrupt handling function

verify that the function void configurationPeripherals(void)


8. Verify that the blue LED lights up for 500ms

9. Verify that the blue LED turns off and immediately the red LED turns on for 500 ms

10. Verify that this sequence continues until we turn off our microcontroller
Bibliografía
Texas Instruments. (2013). Getting Started with the Tiva™ TM4C123G LaunchPad Workshop Student Guide and Lab
Manual. Texas: Texas Instruments.
Annex 1 Electronic diagram

You might also like