CPE301 Lab # 09- Interrupts to service the timer overflow flag Solved

40.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (1 vote)

To become familiar with the use of interrupts to service the timer overflow flag in computer applications. Specifically, to implement a piano like keyboard program using the ATmega2560 timer1 in Normal mode and an external speaker.

Procedure:

  1. Write a C program for the Arduino Mega which will:
    1. Monitor incoming characters from the Mega’s UART, for A, B, C, D, E, F, G, and Q, using the serial functions you wrote in the UART lab (U0Init(), kbhit(), getchar(), and putchar()).
    2. Generate a square wave on Port B.6 of the appropriate frequency depending on the key pressed, as indicated in the table below.
    3. Output logical 0 when the program first starts, and after the UART receives a ‘Q’ character
    4. Generating the square wave will not take place in the main loop of the program, but instead in the overflow Interrupt Service Routine of Timer #1.

 

Hint: Start with the code you wrote in the Timer Lab, and make two changes:

  1. Implement your own serial I/O routines U0Init(), kbhit(), getchar(), and putchar() instead of the Arduino library serial functions to read the note to be played from the UART. 
  2. Implement an ISR function for the Overflow Interrupt on Timer #1 (TIMER1 OVF) which will: a. Stop the timer
    1. Reload the timer counter
    2. Toggle PortB.6
    3. Restart the timer

 

  1. Connect PB6 to an oscilloscope and measure the output frequency. Note any error between the actual output frequency and the desired output frequency.
  2. Connect the lab speakers to PortB.6 with a current limiting resistor in series to play the notes so you can hear them.

 

BE SURE TO ALWAYS TURN OFF THE SBC POWER BEFORE CONNECTING OR DISCONNECTING ANYTHING TO IT.

 

  1. Connect a sine wave signal generator to one of the lab speakers, set it to one of the musical note frequencies, and listen to it. Compare the sound of this note with the same frequency note generated from the SBC speaker. Explain why they sound different.
NOTE FREQUENCY
A 440 Hz
A# 466 Hz
B 494 Hz
C 523 Hz
C# 554 Hz
D 587 Hz
D# 624 Hz
E 659 Hz
F 698 Hz
F# 740 Hz
G 784 Hz
G# 831 Hz

 

*The Sharp notes are included in the Table for completeness. If you choose to implement all of the notes including sharps you will need to decide on an interface protocol which will distinguish between regular and sharp notes. If you choose to implement all of the notes you will receive up to 50 points (on a scale of 100) extra credit on this lab.

 

Important Data Sheet Resources: a)  2560 Interrupt Table (page 101)

  1. b) 2560 Timer Interrupt Mask Register (page 161)
  • Lab-9-cqsiqe.zip