HOME     STORE     BLOG     SCHEMATICS     TUTORIALS     DOWNLOADS     CONTACT

Sine Wave Synthesizer
 
Sine Wave Synthesizer


 

Sine Wave Synthesizer

 


Every group wants their final project to be something that will be remembered long after they're gone. Some do highly sophisticated and complex projects that entail upwards of a hundred hours to complete. Yet others go out of their way to develop something 'cool' and 'fun'. Luke and I decided that we wanted to be in this second category, because developing something that's 'cool' would also be fun to do. So in deciding what to design we tried to think of something that would catch the attention of the people in the lab. The easiest way of doing this is to create something that would make noise or play music so everyone in the lab could enjoy it. Realizing this would be the best way to go, we decided to create a synthesizer that could record and playback notes, 'teach' the user how to play a simple melody, and also play some prerecorded tunes. After all, don't you think being remembered as the group that played back the Imperial March theme from Star Wars is cooler than a paper tape reader? (no offense to those groups doing paper tape readers)


Sine Wave Synthesizer

High Level Design

Seeing the synthesizer not just as a keyboard for playback but something with multiple options, we opted to use a simple state machine to section off each option. In other words, there would be states for the different options (one for single note play, record play, etc...) Since the main program would be this state machine, it was wise to have the generation of the sine wave output to be interrupt driven. This gives a lot of freedom to the main program functions because the state machine for the main program doesn't have to worry about creating these tones.

Program/Hardware Design

State Machine Design

Since our design involved the user being able to choose from several different playback option, it was obvious that the program would entail the use of a simple state machine. Each option of the synthesizer (Default or waiting, Single Note Play, Record Play, Mem Playback, LCD play, and Recorded Tunes) would correspond with one of these states. The buttons on the proto-board would be used to change from one state to another.

Proto-board button layout:

Button 0: Single Note Play
Button 1: Record Play
Button 2: Memory Playback
Button 3: LCD Play
Button 4: End Single Note Play
Button 5: End LCD Play
Button 6: Recorded Tunes

Since the synthesizer defaults to the 'default state', pushing button's 0-3 or 6 will transfer the user to that option. Pushing button 4 and 5 are only valid if the user is already in the single note play or lcd play option respectively.

Default State

The program spins through the instructions of how to use the synthesizer. At even intervals, the LCD displays text on how to select different options. The following can be seen by the user on the LCD:

0 Single Note Play
1 Record Play
2 Mem Playback
3 LCD play
6 Recorded Tunes

When button's 0-3 or 6 are pressed on the proto-board, the synthesizer changes to the state of the option selected.

Single Note Play

Once the user hits the button on the proto-board corresponding with the single note play option, the state machine enters to this 'Single Note Play' state. A tone is then generated for each button pushed on the keypad. This state can be exited once button 4 on the proto-board is pushed. The synthesizer then resets back to the default state.

Record Play

The user can play and record up to 100 notes into memory and then play them back in .25 second intervals. When a button is pushed on the keypad, the number corresponding to the button is stored in RAM. If the user enters 100 notes, the synthesizer will output a 'Recording Done' message to the LCD and return to the default state to await input. The recorded notes can then be played by selecting the memory playback option. But if the user doesn't want to enter 100 notes, they can hit the button for mem playback and the recording will cease and memory playback will start.

Mem Playback

Once the user records a certain number of notes, they can be played back in sequence. If no notes were recorded, then nothing is played.

LCD play (aka Keyboard Karaoke)

In this state, a welcome message is flashed on the LCD letting the user that they have entered the 'LCD Play' option. After a small delay, a series of characters is displayed one at a time on the LCD. These characters represent the buttons that the user should hit in order to play the notes of a song. Once the 'karaoke' lines are finished, the program will jump back to the default state and await input. At any time during the karaoke playback, the user can hit button 5 to stop LCD play and go back to the default state.

Recorded Tunes

A fun not but very useful feature, once the user enters this option, they have the opportunity to playback some of the pre-recorded songs in the program. For this project, only the Imperial March from Star Wars was hard-coded into the program and available for user playback.

Sine wave generation

In this design, we used the National Semiconductor's DAC0808 to convert 8-bit PCM data into an analog, sinusoidal signal. We calculated samples of the notes of the scale from C4-G#5 (262 Hz - 523 Hz) including the black keys and stored them in flash memory. The synthesizer can only play the first 15 notes (C4-D#5), but the microcontroller can output the full range of PCM data. The sampling rate we used was 20 kHz, which is approximately 20 times the Nyquist frequency for the highest frequency note. We used an op-amp on the output of the signal to generate a voltage from the output current and to amplify the signal. We had problems with our original op-amp (LM358) chopping of the top of the sine wave output. However, then we switched over to an audio op-amp, the LF353. This op-amp was much better because it only chopped off the very top of the signal. We corrected the problem by lowering the gain resistor on the op-amp. This method provided reasonable sine waves. In order to output the data at 20kHz, we used Timer 1 with compare match A and B. We set up the timer so that it would call the compare match B interrupt when the Timer 1 is 25. We also have the timer reset on a compare match with A, which is 26. In this way, Timer 1 counts to 25, resets, and counts to 25 in an endless loop. In the compare match B ISR, the program outputs the current sample to PORTC. At button push time, the program finds the starting address of the samples for one period of a sine wave. Several registers store the beginning address of the sine wave and the pointer to the current sample. At each interrupt, the pointer to the current sample gets incremented, and the next sample is sent to the DAC. Once the pointer reaches the end of the samples, it resets to the start of the samples for that particular note. Since sine waves are periodic, we need only to store the samples for one period.

N.B. The DAC is connected to Port C rather than Port D

Click on the above image to get a larger version
Results of the Design

Given the time allotted, we were able to generate a reasonable approximation for a sine wave and allow the user to play these tones, record and playback these tones, and learn a simple song. Having a little more time, we could have added the ability to play multiple tones at the same time. All that is needed is to add more entries into the keypad lookup table to cover multiple keypresses and add code that would sum the two sets of samples from each waveform. Also, another improvement in the tone generation would be to filter the output analog signal to remove unwanted frequencies.

Looking back in retrospect, we tried to encompass a lot of features in the project and didn't focus exclusively on one area (if we had concentrated our efforts on the sine wave generation and didn't do the memory playback etc.., we could have done the multiple tone output.) Also, we would probably have used a different LCD, one with a larger display and more expanded features, since the LCD we used limited us to write 16 characters at a time. Finally, with some financial support, we could have used a keypad that actually resembled a piano keyboard and had more keys, rather than a telephone keypad.

Keypad buttons | Note Value

1 C4
2 C#4
3 D4
A D#4
4 E4
5 E#4
6 F4
B G4
7 G#4
8 A4
9 A#4
C B4
* C5
0 C#5
# D5
D D#5


Sine Wave Synthesizer


Sine Wave Synthesizer






Accurate LC Meter Capacitance Inductance Meter with 16F628 and LCD
Volt Ampere Meter with 16F876 Microcontroller and LCD display
 
Accurate LC Meter

Build your own Accurate LC Meter (Capacitance Inductance Meter) and start making your own coils and inductors. This LC Meter allows to measure incredibly small inductances making it perfect tool for making all types of RF coils and inductors. LC Meter can measure inductances starting from 10nH - 1000nH, 1uH - 1000uH, 1mH - 100mH and capacitances from 0.1pF up to 900nF. The circuit includes an auto ranging as well as reset switch and produces very accurate and stable readings.
PIC Volt Ampere Meter

Volt Ampere Meter measures voltage of 0-70V or 0-500V with 100mV resolution and current consumption 0-10A or more with 10mA resolution. The meter is a perfect addition to any power supply, battery chargers and other electronic projects where voltage and current must be monitored. The meter uses PIC16F876A microcontroller with 16x2 backlighted LCD.

50MHz 60MHz Frequency Meter / Counter with 16F628 & LCD
1Hz - 2MHz XR2206 Function Generator
60MHz Frequency Meter / Counter

Frequency Meter / Counter measures frequency from 10Hz to 60MHz with 10Hz resolution. It is a very useful bench test equipment for testing and finding out the frequency of various devices with unknown frequency such as oscillators, radio receivers, transmitters, function generators, crystals, etc.
1Hz - 2MHz XR2206 Function Generator

1Hz - 2MHz XR2206 Function Generator produces high quality sine, square and triangle waveforms of high-stability and accuracy. The output waveforms can be both amplitude and frequency modulated. Output of 1Hz - 2MHz XR2206 Function Generator can be connected directly to 60MHz Counter for setting precise frequency output.

BA1404 HI-FI Stereo FM Transmitter
USB IO Board PIC18F2455 / PIC18F2550
BA1404 HI-FI Stereo FM Transmitter

Be "On Air" with your own radio station! BA1404 HI-FI Stereo FM Transmitter broadcasts high quality stereo signal in 88MHz - 108MHz FM band. It can be connected to any type of stereo audio source such as iPod, Computer, Laptop, CD Player, Walkman, Television, Satellite Receiver, Tape Deck or other stereo system to transmit stereo sound with excellent clarity throughout your home, office, yard or camp ground.
USB IO Board

USB IO Board is a tiny spectacular little development board / parallel port replacement featuring PIC18F2455/PIC18F2550 microcontroller. USB IO Board is compatible with Windows / Mac OSX / Linux computers. When attached to Windows IO board will show up as RS232 COM port. You can control 16 individual microcontroller I/O pins by sending simple serial commands. USB IO Board is self-powered by USB port and can provide up to 500mA for electronic projects. USB IO Board is breadboard compatible.

ESR Meter / Transistor Tester Kit
Audiophile Headphone Amplifier Kit
 
ESR Meter / Capacitance / Inductance / Transistor Tester Kit

ESR Meter kit is an amazing multimeter that measures ESR values, capacitance (100pF - 20,000uF), inductance, resistance (0.1 Ohm - 20 MOhm), tests many different types of transistors such as NPN, PNP, FETs, MOSFETs, Thyristors, SCRs, Triacs and many types of diodes. It also analyzes transistor's characteristics such as voltage and gain. It is an irreplaceable tool for troubleshooting and repairing electronic equipment by determining performance and health of electrolytic capacitors. Unlike other ESR Meters that only measure ESR value this one measures capacitor's ESR value as well as its capacitance all at the same time.
Audiophile Headphone Amplifier Kit

Audiophile headphone amplifier kit includes high quality audio grade components such as Burr Brown OPA2134 opamp, ALPS volume control potentiometer, Ti TLE2426 rail splitter, Ultra-Low ESR 220uF/25V Panasonic FM filtering capacitors, High quality WIMA input and decoupling capacitors and Vishay Dale resistors. 8-DIP machined IC socket allows to swap OPA2134 with many other dual opamp chips such as OPA2132, OPA2227, OPA2228, dual OPA132, OPA627, etc. Headphone amplifier is small enough to fit in Altoids tin box, and thanks to low power consumption may be supplied from a single 9V battery.
 

Arduino Prototype Kit
RF Remote Control 433MHz Four Channel
 
Arduino Prototype Kit

Arduino Prototype is a spectacular development board fully compatible with Arduino Pro. It's breadboard compatible so it can be plugged into a breadboard for quick prototyping, and it has VCC & GND power pins available on both sides of PCB. It's small, power efficient, yet customizable through onboard 2 x 7 perfboard that can be used for connecting various sensors and connectors. Arduino Prototype uses all standard through-hole components for easy construction, two of which are hidden underneath IC socket. Board features 28-PIN DIP IC socket, user replaceable ATmega328 microcontroller flashed with Arduino bootloader, 16MHz crystal resonator and a reset switch. It has 14 digital input/output pins (0-13) of which 6 can be used as PWM outputs and 6 analog inputs (A0-A5). Arduino sketches are uploaded through any USB-Serial adapter connected to 6-PIN ICSP female header. Board is supplied by 2-5V voltage and may be powered by a battery such as Lithium Ion cell, two AA cells, external power supply or USB power adapter.
200m 4-Channel 433MHz Wireless RF Remote Control

Having the ability to control various appliances inside or outside of your house wirelessly is a huge convenience, and can make your life much easier and fun. RF remote control provides long range of up to 200m / 650ft and can find many uses for controlling different devices, and it works even through the walls. You can control lights, fans, AC system, computer, printer, amplifier, robots, garage door, security systems, motor-driven curtains, motorized window blinds, door locks, sprinklers, motorized projection screens and anything else you can think of.
 

Electronics-DIY.com © 2002-2024. All Rights Reserved.