Project 4 - Two Tone Audio Generator

What the PC Program Does:
These programs generate waveform tables that are related to specific frequencies. The tables need to be included in the source code, for project 4, before the project is compiled.
Executables will run under DOS or in a Command Prompt window. The source code was written in 'C' and compiled using the Borland C++ Development Suite Version 5.
Complete Program:
Click on the disk icon to download a file:

Executable Program TONE.EXE This program creates a single frequency.
Executable Program TWOTONE.EXE This program creates a two-tone frequency.
Source Code Files:
Click on the disk icon to download the appropriate source code file:

Source Code TONE.C This program creates a single frequency.
Source Code TWOTONE.C This program creates a two-tone frequency.
PIC Files:
PIC Programs Click on the disk icon to go to the PIC Files page.
Waveform Design:
The frequency must be switchable at 12KHz. Divide 12KHz by the desired frequency. If the result is not a whole number, multiply it by a whole number (integer) until it is. If the result is less than 252 then the waveform can be generated. Otherwise it cannot. For example:
  • 2.7KHz is not directly divisible into 12KHz (12/2.7=4.4) but 4.4 times 27 is 100
So, to generate 2.7KHz will require the PIC to generate 100 steps and in doing so, it will generate 27 cycles.
Start the program (tone.exe) and enter the number of steps (100). Press return and enter the number of cycles (27). The program will generate the required table and put it onto the screen.
Now, cut the table from this screen and paste it into the PIC (.asm) program.
Make sure that you use the program for the PIC compiler that you have (TASM or MPASM).
Choose the switch position that will produce your chosen frequency (0 to 7) and find the secion that is labeled as TAx. For example, if you want your frequency to appear in switch position 2, find the section labeled TA2.
Paste in your new code, replacing the existing "retlw" instructions in that section.
You will also need to tell the program how many steps there are in your new code. Find the section labeled Tx. For example, if you have put your new code into TA2 then you are looking for T2. If you put your code into TA5 then you need T5. The third line of this section should say "MOVLW" followed by a number. Change the number to the number of steps in your code. However, please remember that the number in the program is in hexadecimal. You can use the Windows calculator to convert the number if you need to. Also, remember that TASM needs the number to be preceeded by a dollar sign but MPASM needs 0x (zero ex).

For a two-tone waveform, use the program twotone.exe and make sure that the number of steps is available at both frequencies. You may need to find the lowest common multiple of the two frequencies. For example, an 800Hz waveform can be generated in 15 steps (12000/800=15). A 1.5KHz waveform can be generated in 8 steps (12/1.5=8). To generate a waveform with both 800Hz and 1.5KHz components needs 120 steps as 120 is divisible by both 8 and 15.
Other Information:
Other information will be added here as it becomes available.
Errors, Ommissions and Updates:
Information will be added here as it becomes available.


Click here to return to the PIC Basics Main Page