Solved–Become familiar with the use of interrupts to service the timer overflow — LAB #10 –Solution

$30.00 $19.00

Objective: 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. Starting with the code from your Lab #07 make two changes: a. Use your own serial…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)

Objective:

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. Starting with the code from your Lab #07 make two changes:

a. Use your own serial I/O routines sinit(), kbhit(), getchar(), and putchar() instead of the Arduino library serial functions.

b. Use interrupts and write an ISR function for TIMER1 OVF which will: stop the timer, reload the timer counter, toggle PortB.6, and restart the timer.

write a C program for the Arduino Mega SBC which will monitor the keyboard for inputs of A, B, C, D, E, F, and G. Depending upon which key was pressed use the timer in NORMAL MODE to generate a square wave on PortB.6 of the ATmega2560 (Arduino Digital pin 12) of the appropriate frequency for the middle octave of that musical note (see Table). The note should last until another key is pressed, at which time the new note will be played. If the escape key is pressed the note will be turned off.

2. Connect the lab speakers to PortB.6 and ground to actually 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

middle 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. For example, you might define regular notes as upper or lower case and sharps as the opposite. 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.