Timing

Purpose

Part 1

To familiarize you with numerical output via a digital-to-analog (D/A) converter:

Part 2

To synthesize a tone using a counter/timer:

Due dates

You must hand in your answers to the design questions at the beginning of your laboratory session on Thursday, October 29. This part of the assignment is worth 27 points.

You must be prepared to demonstrate Part 1 of your work during your laboratory session on Tuesday, November 3, and Part 2 of your work during your laboratory session on Thursday, November 5. This part of the assignment is worth 35 points.

Background (Part 1)

Morse code is simply a vehicle for exploring the use of the computer in signal synthesis, and you are not responsible for knowing anything about it. In order to design the appropriate synthesis algorithms, however, you need to understand some of its properties and how it is taught.

Morse code is a representation of the letters, digits and punctuation characters by sequences of short and long bursts of tone. It was originally developed for transmission over telegraph lines, and was later used for radio transmission. Although its use has diminished with time, proficiency is still a requirement for most amateur radio operator's licenses. An interesting sidelight is that Morse code identification is transmitted by radio navigation aids used by aircraft, and until recently Morse code proficiency was required for instrument-rated pilots in Australia.

The basic timing element of Morse code is called a unit, and is the length of the short burst of tone. The long burst of tone has a length of three units, and the silence between tone bursts has a length of one unit. A minimum of three units of silence separates characters, and a minimum of seven units of silence separates words.

Morse code transmission rates are measured in words per minute, with the ``standard'' word being ``Paris''. In other words, a speed of 20 words per minute involves transmitting ``Paris'' 20 times in one minute. In the table below, a short burst of tone is represented by a dot and a long burst of tone is represented by a dash. If we count the units making up the word ``Paris'', including all of the silences, we find that there are 52. Thus a code speed of 20 words per minute involves transmission of 1040 units per minute.

When one is learning Morse code, it is extremely important to realize that it is an audible, not a written form of communication. You cannot achieve any reasonable proficiency by learning the patterns of dots and dashes given in the table below. Instead, you must learn the sound of the character, just as you learn the sound of a song. When learning code, the standard audible presentation of each character is the sound that character would have if the message were being transmitted at 20 words per minute. This standard requires that the length of a unit be about 58 milliseconds (1040 units per minute). The period of silence between characters is adjusted to produce a transmission rate compatible with the student's proficiency.

The frequency of the tone used for the short and long bursts is somewhere in the 800-1000 Hz (cycles per second) range. If the tone were exactly 1000 Hz, then each cycle would require 1 millisecond and a short burst of tone for code practice would consist of 58 cycles.

Morse Code
A: .- J: .--- S: ...
B: -... K: -.- T: -
C: -.-. L: .-.. U: ..-
D: -.. M: -- V: ...-
E: . N: -. W: .--
F: ..-. O: --- X: -..-
G: --. P: .--. Y: -.--
H: .... Q: --.- Z: --..
I: .. R: .-.

Equipment

Each group will need access to a pair of headphones of the type used with portable CD players or MP3 players. The headphones plug into the socket mounted on the MB5.

Task (Part 1)

Design and implement a program that reads a sequence of typed characters from the MB5 UART 2, and outputs them as Morse code to the MB5 D/A converter. Use the comint.src module you developed in an earlier assignment to read from the UART. (You may obtain a comint.src module from another group if you wish.) Click here for the C file containing the 800-sample sine wave discussed in the reading. You can use this data to synthesize appropriate tones.

Your program must accumulate a complete line of text (which might, of course, be only a single character) before doing any translation. It should then output the Morse code for the entire line. You may place a 136-character limit on input line length, and it is up to you whether you allow editing by means of backspace characters.

The Morse code output for a line should conform to the specifications given above with respect to tone frequency and character timing. It must provide the appropriate separation between characters and between words. Remember that the lengths of the silences are tied to length of a unit, which is the time it takes to output a short tone burst. One easy way to create a silence of the appropriate length is to design the output routine to take the D/A converter address as a parameter. When you want to hear a tone, supply the correct D/A converter address as the argument; when you want to hear silence, supply an address that isn't connected to anything.

This part of the assignment requires you to make several important design decisions:

These decisions are not arbitrary; when you give your demonstration, you must be prepared to explain not only what you did, but why you did it. You should plan to spend some time discussing possible approaches with your group and with other groups. Collaborative approaches to problems like this generally lead to solutions more quickly than individual approaches, and the solutions are better.

Background (Part 2)

So far, you have used a specific code sequence to space the samples of a sinusoid. This strategy requires that all of the computer's attention be devoted to the single task of creating that sinusoid. For example, it is not possible for the computer to read one line of text while it is transmitting another -- the UART interrupts would disrupt the timing of the samples and thus corrupt the tone.

A different approach is to use a counter/timer device to specify when a new sample is to be written to the D/A converter. A counter/timer can be set to periodically interrupt the processor. The counter/timer interrupt handler can then write the next sample to the D/A converter. With this approach, the only constraint is that there be sufficient time between interrupts to execute the handler code.

When you use an interrupt to indicate that a sample should be written to the D/A converter, a relatively large number of instructions must be executed between successive samples: Not only must the interrupt, the handler, and the return be executed, but also there must be some time for the computer to do other work. If the frequency of the output tone is to be preserved, the number of samples making up the sinusoid must be reduced. In fact, we want to minimize the number of samples in order to maximize the time that the computer can spend on other tasks. As noted in the previous assignment, we should be able to reduce the number of samples in a single cycle of the sinusoid to 20 without seriously degrading the quality of the tone.

Detailed information about the behavior and programming of the MB5's counter/timers can be found by following this link. The counter.ah file defines symbols that reference the counters and the counter command register. Counter 0 is referenced by the symbol CT0, counter 1 by CT1, and counter 2 by CT2. The counter command register is reference by the symbol CTCMD.

Task (Part 2)

Change the output module of your Morse code translator to use a counter/timer interrupt to control output of samples to the D/A converter; the specifications for the program's behavior remain unchanged. Click here for a zip file containing file counter.ah.

You will have to write code to enable and disable interrupts and install an interrupt handler for whichever counter/timer you choose to use. Operations that enable and disable interrupts have similar implementations, regardless of the particular interrupts involved. Thus the routines used to enable and disable UART interrupts can serve as guidelines for the corresponding routines in this module. In addition to enabling and disabling interrupts, you must write code to initialize the counter with a value to obtain the proper spacing between samples and set the counter's mode of operation.

Questions

None of these questions depends on details of the final code; you do not have to complete the assignment to answer them.
  1. For Part 1, write a loop in assembly language to output samples from a memory array to the D/A converter.
    1. (5 points) Use the information in Appendix IV-D of the text to determine the number of clock cycles that your loop will execute between beginning to write one sample and beginning to write the next sample.
    2. (2 points) What will the frequency of the sound output by your loop be if the memory array contains some number of 800-sample sine waves?
  2. (5 points) For Part 2, which counter/timer mode do you think would be appropriate for this application, in which we need to interupt the CPU periodically? Briefly explain your reasoning.
  3. (5 points) From the documentation, recall that the basic clock frequency of the counter/timers is 8MHz. What value would you set as the count in order to output the samples for this application? Show your computation.
  4. (5 points) To output the dash, dot and silence components of Morse code, the interrupt handler must be passed information. However, since an interrupt is not called like a subroutine, how do you propose to pass the interrupt handler the information it needs to output the proper sound (or silence)? (Hint: Think about how the UART interrupt handler communicates with the program.)
  5. (5 points) When there is no Morse code to produce, the counter/timer may continue to interrupt the CPU and the interrupt handler could output silence. Another, and perhaps better, approach is to prevent the counter/timer from causing an interrupt. Describe how this might be done. (This is not the same as the disable routine you would write, since that routine would restore the original interrupt handler.)
Hand in your answers to these questions on the due date, and keep a copy for reference.

Demonstration

You must demonstrate your program to your TA on one of the machines in the Microlab. Be prepared to discuss your final design in relation to your answers to the design questions handed in earlier.
Instructor Revision $Revision: 1.34 $ ($Date: 2007/08/27 00:15:44 $)