Pianola

The DSP

 

Board and development environment

Texas Instruments C6713 DSP Development Board with DSP TMS320C6713 is the board we used for our project. The DSP Texas Instruments TMS320C6713 operates at a maximum frequency of 225 MHz and can compute up to 1800 MIPS e 1350 MFLOPS. The board has 512 kwords of Flash memory and 16 MB of SDRAM memory, four 3.5 mm audio jacks for microphone, line in, loudspeaker and line out and a 24-bit stereo codec. Communication with the board is via USB through JTAG interface on the board itself.

DSP board photo

Texas Instruments C6713 DSK Code Composer Studio is the development environment provided with the board. Includes software for compling, linking and debugging the source code of the project. There are also a diagnostic tool to verify the proper functioning of the board and several options for displaying signals (in time and frequency).

The program for the DSP

The algorithm we implemented in the DSP is very simple. The DSP receives two inputs: the impulse from the transmitter, which indicates the frequency change of the transmitted signal (int04), and the signal from the receiver (int05).

Interrupts number 04 e 05 are triggered at the rising edge of the signal. So when interrupt 04 is triggered, there was frequency change at the transmitter and the count must be started to measure the time of flight. The values of the period read at the receiver start to be accumulated in a variable. When interrupt 05 is triggered, a period of the received signal is started: the first time, Timer1 count is started from zero; the following, Timer1 value is read and assigned to a variable that contains the current period, after that the value previously contained in that variable has been assigned to the variable that contains the previous period. If there has been the change in frequency (from the lower frequency to the higher) at the receiver, that is, if the previous period is greater than a certain threshold and the current period is less, rather than adding the value of the period to the variable corresponding to the time of flight, the accumulation of periods is stopped. Then the value contained in the variable corresponds to the temporal distance between transmitter and receiver.

An adjustment is necessary in interrupt 04, which is triggered on the rising edge of the transmitter: when the impulse from the transmitter is sensed, it is necessary to read in Timer1 the value of the time lag between the arrival of the impulse and the latest rising edge that has been sensed at the receiver. This is necessary to eliminate the uncertainty (of one period) in the value of the first period: this uncertainty depends on when the impulse came from the transmitter with respect to the scansion of the periods at 38.2 / 41.5 kHz. In fact, since the transmitter impulse is sensed, the values of the period at the receiver start to be accumulated starting from the rising edge that follows the arrival of the impulse. Yet in this way it would be lost the time elapsed between the arrival of the impulse and the first rising edge that starts the accumulation of the periods. To avoid this, to the variable corresponding to the time of flight you must add the value of one period minus the value read in Timer1 at the arrival of the impulse, which is precisely the amount that would be lost otherwise.

Since the spatial difference can be obtained by multiplying the time difference by the speed of sound, the value of the time of flight obtained permits to determine immediately which is the key that the user wants to select and then the corresponding note that must be played. Of course, to get the distance of the emitter from the beginning of the keyboard, you must take into account an offset, equal to the distance between the receiver and the beginning of the keyboard.

Now left and right samples are created: they are discrete values of a sine wave with the appropriate frequency, which are emitted from the DSP, via interrupt 11, at the chosen sampling frequency (8 kHz).

In the alternative version of the program, which contemplates the presence of a button that must be pushed to get the sound (it is equivalent to pressing the key on a piano), there is the additional presence of interrupt 06, which enables the emission of a note of predetermined duration only after pressing the button.