[Lui's homepage] [DSP homepage]
ELC 152, 1st Semester, 2004-2005
Lab Exercise 3
A Digital Sinusoidal Oscillator on the 'C542
This exercise requires use of the 'C542 kits, the dskplasm assembler, and the associated C54x Code Explorer software in the DSP Lab.In this exercise you will implement digital sinusoidal oscillators on the 'C542. More information on these oscillators is provided [here]. Implementing the digital sinusoidal oscillator on the 'C542 also requires the ability to handle numbers in a fixed point format such as Q15.
1. First, familiarize yourself with the representation of numbers in the range (-1,1) in Q15 format:
Q15 is a signed binary format where the rightmost 15 bits are considered as being to the right of the binary point. That is, if the binary numbers are 16 bit, then each 16-bit number is of the form
b15b14b13...b2b1b0
where each bj ( j = 0 .. 15) is either 0 or 1. The binary point is between b15 and b14. The 16-bit number represents a number in the range [-1,1) given by
-b15 + b14*2-1 + b13*2-2 + ... + b2*2-13 + b1 * 2-14 + b0* 2-15 .
b15 is the "sign bit". When b15 is 0, the bit pattern represents a nonnegative number; otherwise the bit pattern represents a negative number.
Thus, 0000 0000 0000 0000 represents 0;
0000 0000 0000 0001 represents 2-15;
0100 0000 0000 0000 represents 0.5;
1000 0000 0000 0000 represents -1;
1100 0000 0000 0000 represents -0.5;
1110 0000 0000 0000 represents -0.25;
1111 1111 1111 1111 represents -2-15.
Note that if the 16-bit pattern were being used to represent signed integers, then the integer being represented is given by
-b15*215+ b14*214 + b13*213 + ... + b2*22 + b1 * 21 + b0* 20 .
The number being represented in Q15 format is simply 2-15 as much as the corresponding signed integer being represented. This means that the same instructions used for multiplying integers could be used to multiply numbers in Q15 format, except that the results may have to be adjusted by multiplication by a suitable power of 2. This is accomplished by simply shifting the result appropriately.
Represent a few numbers in the range (-1,1) and represent them in Q15 format. Note that the range is closed under multiplication. The product of two numbers in the range (-1,1) is another number in the same range.
Multiply two numbers chosen from the range (-1,1). Determine the (binary) Q15 representations of the factors and the result. Now treat the Q15 representations of the factors as ordinary signed integers, and compute the product. Compare the bit pattern of the signed integer product with what the Q15 product should be. Repeat this for various pairs of numbers in the range (-1,1) of various magnitudes and various combinations of positive and negative numbers.
From this you should be able to determine how to obtain the Q15 product from the ordinary product of two signed integers.
Include your findings in your lab report.
2. Write code in the 'C542 assembly language implementing a digital sinusoidal oscillator generating samples of
0.95 sin( 2 pi f1 t)
where f1 is the frequency assigned to you. [frequency assignments] Use 8000 Hz as operating frequency. You will need to know how to represent constants in a fixed-point format, and how to multiply them properly.
Note that while each memory location in the memory space is 16 bits, the accumulators are actually 40 bits wide and can accomodate the product of two 16-bit integers.
Design your code such that it writes 200 or more samples of 0.95 sin( 2 pi f1 t) into an array of memory locations starting at 0x2000.
Set a breakpoint after the samples are written to memory. (Help on how to set breakpoints is available from the Code Explorer Menu.) Once the breakpoint is reached use View>>Graph from the Code Explorer Menu in order to produce a graph of exactly 200 samples generated by your oscillator. The horizontal axis should have the proper units of time. Be sure to set all graph parameters appropriately. Be sure that the graph generated is indeed that of a sinusoid having the right amplitude and period.
Use alt-PrintScreen to capture the graph generated. Be able to show this graph during evaluation of this lab exercise.
In your lab report include the filename, size and timestamp of the image file containing the generated graph. Also include details regarding all graph parameters used in producing the graph in Code Explorer.
3. Next, write code to implement a digital sinusoidal oscillator that actually outputs a continuous tone of frequency f1 using the 'C542 kits in the lab. Set the analog interface (the DAC in particular) to operate at 8000 Hz.
Note that the DAC is a 14-bit DAC and that the 2 least significant bits of a 16-bit value sent to the DAC must be zeroed out. Read the TLC320AC01C Data Manual for details.In your lab report include the filenames, sizes and timestamps of the final source and object files. You may have separate source files for parts 2 and 3. You may also have a single source file for both parts.
Also include in your lab report a list of all constants used and their significance in relation to the lab exercise.
Be able to answer all questions related to this exercise. During evaluation of this exercise, you must have with you on files or on paper any and all forms of documentation that you would need to show and/or discuss how you went about doing this exercise.
[Lui's homepage] [DSP homepage]
This page has been accessed
times since July 29, 2004.