In lab assignment 1 we saw how to accept keyboard input


Design with Microcontrollers

Lab: Interrupt Processing

Lab a: Interrupt-Driven General Purpose IO (GPIO)

Let us start with an example of how to handle an interrupt generated by a device connected to a GPIO pin-in our case, a switch which is onboard the PSoC board. We will develop a simple interrupt service routine (ISR) to service the interrupt as follows: when the switch is pressed, toggle the red onboard LED. Note the following important points:

• The LED is connected to P1[6] with a copper trace on the board, that is to the 6th pin belonging to I/O port 1. The switch is similarly connected to P0[7]. External connections are unnecessary.

• The LED is active low; that is, driving the pin low will turn it on.

• The switch is grounded when pressed.

As a first step, your must configure an input pin-let's call it SW-under the "My Design" tab in the .cysch file, as part of your top-level design within PSoC Creator. Note the following points:

• The input-pin parameters must be chosen as follows: digital input, a resistive pull up drive mode, and the initial drive state set to high.

Also, set the pin input to generate an interrupt- called SW Int-on the falling edge of the pulse and to trigger an ISR.

• Map the pin component to P0[7] in the .cydwr file under the "Pins" tab.

• Map the LED output pin component to P1[6] in the .cydwr file.

Once you build the code, the system will generate low-level code including the following stub for the ISR called SW Int Interrupt within the file SW Int.c. (The file may be called differently in your case depending on how you name your interrupt.)

Lab b: Handling UART Interrupts

In lab assignment 1, we saw how to accept keyboard input from the terminal by contin- uously polling the UART component, say named UART 1, for input data within the main program. The polling-based method can be written as follows.

This assignment asks you to operate the UART in an interrupt-driven fashion, accept input from the keyboard, and dynamically control the blinking rate of the LED.

Configure the UART component in your top-level design as follows:

• Set the baud rate on the UART to 9,600 bps. Match this baud rate on the terminal running on the host PC.

• Under the "UART Advanced" tab, have the UART generate an external interrupt when the receive FIFO buffer is not empty and associate an interrupt component with this event. In- terrupt components are listed in the component catalog under "System." Say, we name this interrupt as Uart Int.

• Designate pin P0[4] as the receive (rx) pin and P0[5] as the transmit (tx) pin in the .cydwr file under the "Pins" tab.

• External jumper wires are required: connect P0[4] to P12[7] and P0[5] to P12[6] on the board. This effectively transfers the bit stream between the UART component and the USB connector.

Lab c: Implementation of a Wall Clock

In this assignment you will use the timer and UART components in interrupt-driven fashion to implement a running wall clock and display it on the terminal in hh:mm:ss format, where hh stands for hours, mm for minutes, and ss for seconds. The wall-clock program must also have the following additional functionality:

• It must allow the user to set the hh, mm, and ss fields prior to starting the clock.

• It must allow the user to reset the various fields during operation. When the user presses the character ‘c' on the keyboard, the clock must be stopped, new values for hh, mm, and ss, accepted as inputs from the user, and the clock restarted with these new values.

The timer is available under the Digital/Functions menu in the component catalog. Use the Timer component, not the Timer Counter component. You can configure the timer, call it TIMER 1, in your high-level design as follows:

• The internal counter within the timer counts down; starting with an initial value n-which can be chosen to be an 8-bit or 16-bit value, as appropriate-and a clock signal of frequency f , the counter counts down at each rising edge of the incoming clock-pulse train until the counter value reaches 0; upon which the value is reset to n, and the process repeats itself. So, the period, p, of the timer can be calculated as p = n × 1/f seconds.

• At the end of each period, the timer asserts the line associated with terminal count, shown as the ‘tc' line in the timer block. Associate an interrupt with this line such that the cor- responding ISR, called timerISR in the code snippet below, is triggered at periodic time intervals.

Lab d: Measuring Elapsed Time

This assignment asks you to develop functions that use the timer component to measure elapsed time between events-in this case, to measure the execution time of a given function. Consider the following function that multiplies two N × N matrices:

You are asked to write two functions, tic and toc, that work in concert to measure the execution time incurred by matrixMult in milliseconds. The skeleton of the main program is as follows where the UART and timer components are named UART 1 and TIMER 1, respectively

Attachment:- Interrupt_Processing.pdf

Request for Solution File

Ask an Expert for Answer!!
Other Engineering: In lab assignment 1 we saw how to accept keyboard input
Reference No:- TGS01532048

Expected delivery within 24 Hours