Lab 4: Variable Tone Generator



Lab 4: Variable Tone Generator

1. Goals

• To learn about cross assembly

• To learn about downloading

• To learn about using tables

• To learn about simple I/O control

• To learn about loops

2. Given Problem

Write a program that generates eight different tones along with eight light patterns assigned for each tone. The eight light patterns are stored in the following memory locations:

Address Binary Bit Pattern

$0000: 11000000

$0001: 01100000

$0002: 00110000

$0003: 00011000

$0004: 00001100

$0005: 00000110

$0006: 00000011

$0007: 10000001

The bit patterns given above are simply an example. You may create your own bit patterns. Per each tone you generate, a bit pattern should be loaded into the LEDs using the above or your own data table. The program runs in an infinitive loop where eight tones and bit patterns are repeated.

3. Background information

From this lab you will be using the Unix system to edit, cross-assemble your code, and down load your executable code. Please refer to the handout for this process.

First, you need to understand how to generate sounds using the expansion board. The principle is relatively simple. The speaker is connected to the bit-6 of Port-A. Port-A is at the memory address $1000. A sound is generated by sending a train of pulses to the speaker as shown below.

The pulse height (amplitude) is 5-volt which is generated by sending logic “1” to the speaker (bit 6 of Port A), i.e. ldaa #40, staa 1000. The 0-volt is generated by sending logic “0” to the speaker, i.e., ldaa #00, staa 1000. The length of pulse is controlled by dummy software delays. Often students misunderstand that sending “1” turns on the sound and sending “0” turns off the sound. That is not correct. “1” simply generates the high portion of the pulse and “0” the low portion of the pulse. Sound has two components: amplitude and frequency. Since we can only generate 5-volt amplitude, we can only control frequency in this case. How do we control the frequency (= pitch)? You can use simple delays to control the pulse width. The longer the pulse width generates the higher the frequency sound. The following list demonstrates how to generate a train of pulses with equal pulse width.

org c000

ldx #1ff

Sound: ldaa #40

staa 1000 ; send 5V to the speaker

ldab #c0 ; a delay to control the pulse width

Delay1: decb

bne Delay1

ldaa #00 ; send 0V to the speaker

staa 1000

ldab #c0 ; a delay to control the pulse width

Delay0: decb

bne Delay0

dex ; generate a pulse train by repeating

bne Tone1

swi

In the above program, X register is used to control the number of pulses, while Acc-B is used to control the pulse width. Now, edit, assemble, download, and run the above program (G c000). You should hear the sound.

With simple modification of pulse widths, the above program can be written to generate eight different tones. Next, you need to add the light routine. The LED port is controlled by two memory locations, $1007 and $1003. $1007 is called a data direction register and must be set to ff before you send data to the data port $1003. Data direction only needs to be set once, since its content remains until you change it again. Therefore, the data direction register is usually set at the top of the program. Next, lights are controlled by sending the desired data to the LED port. Bit “1” turns on the light and bit “0” turns of the light. If light patterns change too fast, you will not be able to see them. So the light routine also needs delays. In this lab, you can use the sound routine as the delay for the light routine.

4. Report

• Cover page

• Problem description using your own words

• Description of your methodology

• Conclusion

• Program listing with comment

Check off : Thursday afternoon.

For check-off, be ready to demonstrate your program. After you pass the demonstration, the instructor or TA will sign on your program listing. So please prepare your commented program listing before you request check off.

Report Due: Friday Class

-----------------------

0V

5V

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download