theremin keyboard -...

20
Theremin Keyboard Logan Stafford Samuel Schendel May 17, 2018 6.101 Final Project Report

Upload: others

Post on 01-Nov-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Theremin Keyboard Logan Stafford

Samuel Schendel

May 17, 2018 6.101 Final Project Report

Page 2: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Table of Contents

Table of Contents

Abstract

Introduction

Block Diagram

Tone Generation (Logan Stafford) IR Distance Sensor Voltage Discretization and LED Indicator Tunable Voltage Dividers Voltage Controlled Oscillator Voltage Scaler and Shifter

Keyboard Input Amplitude Control (Samuel) Envelope Background Variable Volume Background Envelope/Variable Volume Circuit Overview Voltage Controlled Amplifier Switch Debounce Speed Detection Minimum Volume Envelope Creation

Keyboard Audio Mixing and Biasing (Samuel)

Audio Amplifier (Samuel) Sawtooth Wave and PWM Signal Gate Driver Configuration H-Bridge and Low Pass Filter

Testing and Results

Conclusion

Bibliography

Page 3: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Abstract The creation of an electronic instrument presents some interesting challenges. As the use of the instrument is primarily an auditory experience, special attention must be paid to the tuning of the frequencies corresponding to different notes as well as to other more subjective qualities of the notes. The instrument must also not create unnecessary noise. While the sound of the instrument is of critical importance, the ease and enjoyment of playing the instrument are critical factors as well. The “theremin keyboard” is an instrument designed to fulfill all of these requirements. The distance-based octave switching, responsive keyboard, and reliable tuning mechanism create an instrument that is fun to play and pleasant to listen to.

Introduction The Theremin Keyboard is an instrument that takes inspiration from both a Theremin and a keyboard. A Theremin is an instrument that has two capacitive antenna on it, one of which controls volume and the other that controls pitch. It is played by moving one’s hand closer or farther away from each of the antenna to generate tones. The inspiration came from that style of play so the design needed a touchless way to switch the octave that is being played. Instead of using capacitance, the instrument uses an infrared distance sensor for better accuracy and ease of use. The distance away from the sensor would change which octave was on the keyboard at that time. The keyboard is made of five keys to allow for a pentatonic scale as well as allowing the player to not move the playing hand. The keyboard is also able to change the volume of the note being played based on how quickly the key is pressed. Logan was responsible for the distance sensor and the tone generation and Samuel was responsible for the keyboard and amplification.

Block Diagram The entire system is powered by ±15 V as well as +5 V for the IR sensor and part of the class D amplifier. The flow of the signal starts at the bottom of the diagram with the user inputs and flows up and to the right. Each of the blocks is described in more detail in the following sections.

Figure 1. A block diagram showing the flow of the signal through the system.

Page 4: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Tone Generation (Logan Stafford) The goal of the tone generation portion is to create five different signals at the correct frequencies that correspond to the notes that can be played. This portion is also responsible for the changing of octaves when the player moves their hand closer or further away from the sensor. The output of this portion is a small and positive signal, which can either be a square wave or a triangle wave, which will be passed to the keyboard and amplifier.

IR Distance Sensor

Figure 2. Filter for the noise of the IR Distance sensor, with an op-amp buffer and a low pass filter on the

output.

One of the goals of the project was to be able to simulate the pitch control method that is used in a theremin. This being that one can change the pitch lower by lower one’s hand closer to a sensor and raise the pitch by moving one’s hand farther away. To accomplish this behavior, an infrared distance sensor, the Sharp GP2Y0A21YK0F, was implemented to determine the position of the player’s hand. The device is powered by 5 volts and outputs a voltage between .15 V and 3 V and operates at distances from about 10cm to about 80cm. The closer the hand is to the device the higher the output voltage will be. The relationship between distance and voltage is also not linear which can be seen when testing. To get from .15 V to 1 V it takes almost half of the usable distance, but the increase from 2 V to 3 V is only a few inches.

Page 5: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

One issue with the sensor was that the IR sensor added a very large amount of noise to the 5 V power rail, which caused problems as some of the amplifier utilized 5 V. This noise added a noticeable buzz to the output sound, so a filter needed to be added to remove this noise. The distance sensor can only output a small current, so to ensure that this is not exceeded a buffer was added to the output of the sensor. The output signal still had a large amount of high frequency noise as well as some voltage spikes after each sample of the distance, which was removed using a low pass filter.

Voltage Discretization and LED Indicator

Figure 3. Comparators that turn on when the output from the IR sensor reaches the set voltage, as well

as LED indicators to show the current octave. To allow for the switching of octaves through the distance sensor, the values output from the IR sensor need to be split into ranges for each octave. This is accomplished through the use of 4 comparators, one for each octave, with the non-inverting input set to the desired voltage to get the correct range while the inverting input is connected to the output from the IR distance sensor. The voltages are set using a voltage divider, and each comparator will have a different value.

Page 6: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

To only have one of the outputs on at a time, there needs to be a way to turn the output off after the next comparator turns on because a comparator will always output when the set voltage is exceeded. To accomplish this, a N-channel MOSFET, the 2N7000, is used to tie the output to ground when the next comparator is turned on. The 10 Meg resistor is used to allow for the current to flow somewhere other than the gate of the MOSFET. The diodes are used to ensure that the feedback turns on the correct MOSFETs without impacting the other ones. To visualize what octave the player is in, there is an indicator made up of 4 LEDs. To turn the LEDs on the output from the comparator is fed into the gate of an N-channel MOSFET, the 2N7000, which when turned on allows current to flow through the resistor and LED.

Tunable Voltage Dividers

Figure 4. Buffered input and output surrounding a tunable voltage divider constructed with a

potentiometer. To turn the 4 outputs from the previous stage into usable values to generate the correct frequencies, the outputs turn on voltage dividers that correspond to a specific note. Each key will have 4 voltage dividers, corresponding to the 4 octaves of the note. This makes a total of 20 voltage dividers, as there are 5 keys with 4 octaves each. The circuit diagram for one of the keys is shown, and because they are tunable, there is no need to change the resistor values between keys.

Page 7: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Each of the outputs is first put into a buffer to ensure that this stage does not affect the previous. This is then put over a voltage divider consisting of various valued resistors and a 100k potentiometer. This value is then put into another buffer and then all of the outputs tied together as all 4 of these correspond to one key. The usage of the input and output buffer is to ensure that the voltage supplied is not changed due to connecting the other stages. To ensure no feedback is introduced into the buffers and the voltage dividers, each of the outputs is first put through a diode. The output of this stage is a voltage that will generate the 4 octaves of a certain note through the voltage controlled oscillator. Because each note is tuned by its own potentiometer, tuning the keys is easy and can be done quickly. This means that if any note drift occurs, the note can easily be tuned. Another feature that benefits from the tunable nature of the keys is that it is easy to switch either notes or entire scales that are playable on the keyboard.

Voltage Controlled Oscillator

Figure 5. Both of the versions of the voltage controlled oscillators used in the circuit, which are made up

of a schmitt trigger, an integrator and a mosfet as a reset.

The voltage controlled oscillators (VCO) are responsible for the actual tone generation for each of the keys. There is one voltage controlled oscillator per key, and the design of each of the voltage controlled oscillators in the same except for the capacitor value as shown in figure 5. There are three oscillators with the 33 uF capacitor and two oscillators with the 22 uF capacitor.

Page 8: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

A voltage controlled oscillator is made up of an integrator, a schmitt trigger, and an N-channel MOSFET as a reset to allow for the oscillation. The VCO has has two different outputs, one being a square wave and one being a triangle wave. To switch between the two outputs, there are two switches to allow for one of them to be on and one of them off. Because the square wave has a magnitude that is about double that of the triangle wave, the amplitude needs to be halved which is accomplished by a voltage divider. The output of this stage is a 30-volt peak to peak signal that is centered around ground.

Voltage Scaler and Shifter

Figure 6. Inverting amplifier with low gain and an adder circuit.

The output of the VCOs 30-volt peak to peak square or triangle wave centered around ground. The input of the next stage requires a signal that is about 50 mV peak to peak and entirely positive. To accomplish this, the signal is first put through an inverting amplifier with a gain of –0.0024. This reduces the signal to the correct size and inverts it. Then to get the signal all positive it is put into an adder circuit. The output of the adder circuit is –(V1+V2) so to shift the output up, a negative value need to be added to the signal. To get the correct shift, a potentiometer is used to get the correct offset voltage for each signal. The output of this stage is a signal that is all positive and around 50 mV peak to peak for the next stage.

Page 9: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Keyboard Input Amplitude Control (Samuel) The tone corresponding to each key on the keyboard is constantly generated, but that tone should only be audible if the key is pressed. In order to make the sound of the instrument somewhat more natural, these tones are modified with the addition of an envelope over them as they are played and with the adjustment of the amplitude of the tone based on the speed of the key press.

Envelope Background A piano or typical electronic keyboard will not simply turn on and off a tone when a key is pressed. Instead, when the key is pressed the volume of the note will quickly ramp up, and when the key is released the volume will quickly decay. This modification of the volume of the tone is an envelope. An approximation of the envelope created by an actual piano that is used by most keyboards is known as the Attack Decay Sustain Release envelope.

Figure 7 The amplitude variations in an Attack Decay Sustain Release envelope.

https://commons.wikimedia.org/wiki/File:ADSR_parameter.svg When the key is pressed, the volume of the tone rises to a peak in the attack phase. The volume decreases slightly from this peak in the decay phase. As the key is held down, the tone is kept at the same volume in the sustain phase. When the key is released, the volume decreases in the decay phase. An implementation of an envelope like this was the initial goal of this project, but a slightly simplified implementation that still made the instrument sound noticeably more natural was ultimately used instead. This envelope consists of the attack, sustain, and release portions of the ADSR envelope.

Page 10: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Variable Volume Background An actual piano or sophisticated keyboard will not have only one sustain-phase volume for every key press. The speed or force of the key press will determine the volume of the note played. In order to further improve the natural quality of the instrument, as well as to make it generally more satisfying and enjoyable to play, this variable volume was implemented as a function of key press speed. In order to measure key press speed, the keyboard was constructed so that each key contained two switches activated at the bottom of the key stroke. Due to the lever nature of the key, one key would be pressed before the other, and the time between the two keys being pressed would be determined by the speed of the key press. With a carefully tuned circuit, this time difference can be measured and turned into a tone volume difference. The general mechanical design required for this behavior can be seen in this side view of a single key and its associated switches:

Figure 8 A side view of the mechanical design of a switch.

With this design, switch 2 is pressed first in the key stroke, and switch 1 is pressed second.

Envelope/Variable Volume Circuit Overview This is the complete circuit, replicated for each of the five keys, that creates the envelope for the note and translates key press speed to note volume:

Page 11: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 9 The complete keyboard tone amplitude control circuit.

Page 12: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Each section of this circuit will be examined individually.

Voltage Controlled Amplifier

Figure 10 A simple voltage controlled amplifier.

The tone signal generated from the voltage controlled oscillators is able to be adjusted with a voltage controlled amplifier. A very simple implementation of a voltage controlled amplifier that uses an n-channel MOSFET with an op amp in an inverting gain configuration is used. When the control voltage is zero, the mosfet is off and the tone signal does not pass through this amplifier. When the control voltage is around the MOSFET’s threshold voltage, the MOSFET is completely on and the signal passes through the amplifier with a 10x gain. Given that the incoming tone signal is very small (50mV peak to peak in this case), the MOSFET can be operated in the linear region with gate voltages above zero but below the threshold voltage with minimal distortion to the output signal. Varying the control voltage between 0 volts and 2.5 volts allows control of the amplitude of the output signal, with a higher control voltage meaning a larger output amplitude. With this voltage controlled amplifier an envelope can be created over the tones, and the variable volume described above can be implemented as long as the appropriate control voltages are generated.

Switch Debounce Switches 1 and 2 have this circuit for each key:

Page 13: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 11 Design of a debounce circuit and signal inversion.

This circuit is connected to the two ends of each switch and provides an output that is high (15V) when the switch is pressed and low (0V) otherwise, as well as another output that is the inverse. Adding an RC debounce circuit removed some small occasional noise that was audible when keys were pressed or released. This circuit was ultimately designed so that the charging path RC constant was smaller than the discharging path RC constant. This design allows the key to be more responsive when it is pressed, but keeps the switch output signals held slightly longer after it is released.

Speed Detection In order to vary the volume of a note based on the speed of the key press, the key press speed needs to be translated into a voltage. This voltage should be higher for faster key pressed. Given the two switches for each key, the time between pressing them can be translated into a voltage with this circuit:

Page 14: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 12 Keypress speed detection using an RC circuit.

The voltage across the capacitor is the output voltage and the voltage divider between 15V and ground is chosen to select the maximum voltage the capacitor will be charged to. When neither switch is pressed (the key is up), the capacitor is completely charged. As the key is pressed, switch 2 is the first to be pressed. While switch 2 is pressed and switch 1 is not, the capacitor is allowed to discharge through the 39 ohm resistor. When the key is completely pressed, both switch 1 and switch 2 are closed. At this point, discharging stops and the voltage at the capacitor is held. When the key is released, the capacitor is charged again. Given this design, the shorter the time between pressing switch 2 and switch 1, the higher the voltage on the capacitor. Given that the user will expect that notes will be sustained as long as they hold the key down, it was important to ensure that the capacitor would maintain its voltage sufficiently long. With the above configuration and having the output buffered with an op amp, it was observed that the capacitor would not lose more than 0.1V in 10 seconds.

Minimum Volume The speed detection circuit will allow the capacitor to discharge to nearly 0V for very slow key presses. When such low voltages are presented to the voltage controlled amplifier, the note is inaudibly quiet. It was necessary to implement a minimum volume for very slow key presses. To accomplish this, the output of the speed detection circuit has a constant voltage added to it and the result is inverted as the adding configuration itself is inverting.

Page 15: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 13 Addition of a constant voltage to provide a minimum volume.

Envelope Creation Given that the key press speed can be turned into a voltage corresponding to maximum tone volume, an RC circuit can be used to create a simple envelope for the tone.

Figure 14 Envelope creation using an RC circuit.

The output of this stage will charge up to half of the incoming max amplitude voltage, which is why the voltages from the previous stages have been doubled from the 0V - 2.5V range that the voltage controlled amplifier will work with.

Keyboard Audio Mixing and Biasing (Samuel) In order to allow the user to play multiple keys at once, the output signals from each of the five keys’ amplitude control circuits must be combined. Additionally, the amplifier will expect an audio signal that is centered around 2.5V.

Page 16: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 15 A circuit to combine the audio from the five keys and center it around 2.5V.

In order to meet these requirements, a circuit was created that adds together the signals from the five keys, removes any bias with a high pass filter, provides volume control with a gain circuit with a potentiometer, and finally adds a 2.5V bias.

Audio Amplifier (Samuel) A Class D amplifier was chosen to play the music of the instrument over a speaker. This type of amplifier was picked specifically because it is very efficient and is not a type of amplifier that had previously been constructed in a 6.101 lab. At a high level, a Class D amplifier works by driving an H-bridge with a high frequency PWM signal that has the amplitude of the audio signal as its duty cycle. The PWM signal is created by taking a high frequency triangle wave (at least 100 kHz, but often higher) and feeding it into a comparator alongside the audio signal. The output of the H bridge is fed through a low pass filter to reduce the amplitude of the high frequency switching signal, and the lower frequency audio signal is allowed to pass through to the speaker. It is essential that the high and low MOSFETs for either side of the H-bridge are not on at the same time, or the high rail would be shorted to ground. This phenomenon is known as shoot-through. To prevent this, an H-bridge gate driving IC, the LT1162, was used which ensures that only one MOSFET on a given side of the H-bridge is ever on.

Page 17: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

The design of this amplifier is considered in three sections: the creation of the high frequency triangle wave and PWM signal, the configuration of the gate driving IC, and the H-bridge with its low pass filter.

Sawtooth Wave and PWM Signal

Figure 16 Generation of a 100 kHz sawtooth wave and the PWM signal for the amp gate driver.

A current source similar to the one created in lab 6 is used to charge a capacitor connected to a 555. With this configuration, at the capacitor a sawtooth wave is created at 10 kHz. The potentiometers in the adder and gain op amp circuits allow careful manual tuning to ensure that the sawtooth wave is as close as possible to being between 0 and 5 volts for the comparator. While a high frequency triangle wave is generally used for the creation of the PWM signal, it is also acceptable to use a high frequency sawtooth wave instead. For a given audio level, both produce the same duty cycle in the PWM signal. The MAX 942, a high speed comparator, is used to generate the PWM signal from the high frequency sawtooth wave and the audio signal.

Page 18: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Gate Driver Configuration

Figure 17 Configuration of the LT1162 for driving a full H-Bridge.

The full H-bridge configuration for the LT1162 suggested on page 13 of its datasheet was used [5]. The LT1162 requires both the PWM signal and its inverse, so the PWM signal is run through an inverter.

H-Bridge and Low Pass Filter

Page 19: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

Figure 18 H-Bridge configuration with a low pass filter to reduce switching frequency signal. The full H-Bridge was built with n-channel MOSFETs that could accommodate much more current than the power supplies could output. A low pass filter was added between the H-Bridge output and the speaker so that the 100 kHz, 15V signal was not unnecessarily driving the speaker. The filter being second order allowed a relatively high cutoff frequency (near 10kHz), allowing most audible frequencies through while substantially reducing the 100 kHz signal. In order to compare the different LC low pass filter topologies commonly used for class-D amplifiers, a filter calculation tool released by TI was used [6].

Testing and Results When the project was planned, several standards were set to measure its success. The instrument needs to be reliably in tune, not produce any significant audible noise, and allow the playing of five distinct notes across four octaves. In order to test the tuning of the project, a smartphone app designed for tuning instruments was held up to the speaker while each note was played. This app verified that each note in each octave was set to the appropriate frequency. An oscilloscope could also be used to view the frequency that was output from the VCO’s to verify the smartphone app. In testing it was found that all 20 notes that the instrument could play would stay in tune within a few hertz across multiple days, which is not an audible difference. The lack of noise as well as the functionality of the five keys and octave switching by playing the instrument and listening closely. While initially audible noises were discovered that were created by the IR distance sensor, the addition of capacitors and a small inductor to the 5V rail eliminated the noise. Ultimately all of the functionality of the instrument was verified and it did not produce excessive audible noise while on.

Conclusion The theremin keyboard instrument ultimately ended up working better than was anticipated when it was proposed. It is satisfying to play and sounds pleasant when played correctly. The theremin keyboard’s touchless, distance-based octave switching mechanism works exactly as intended. The dynamic note volume based on key press speed provides a surprising amount of variation of sound. This project demonstrated difficulty in noise reduction as the signals were very small at some points in the signal flow, and then amplified up. This process will amplify any small amount of noise in the signal, which is why reducing that noise as much as possible is important. Communicating specifications was also a large challenge in this project. With two people designing and building portions, the specification of the inputs and outputs of each stage are

Page 20: Theremin Keyboard - web.mit.eduweb.mit.edu/6.101/www/s2018/projects/lstaf_Project_Final_Report.pdf · V o l t a g e C o n t ro l l e d A mp l i f i e r S w i t ch D e b o u n ce S

important. This was seen in the output of the VCO’s and the input of the envelope generator circuit, as the VCO outputs 30 V peak to peak while the envelope generator circuit input is only around 50 mV peak to peak. Despite all of the design and communication challenges, the project ultimately was a great success, sounded amazing, and was a ton of fun to play.

Bibliography

1) https://www.mouser.com/ds/2/321/gp2y0a21yk_e-3493.pdf Datasheet for the IR Distance Sensor (Sharp GP2Y0A21YK0F)

2) http://www.ti.com/lit/ds/symlink/lm158-n.pdf Inspiration for the design of the voltage controlled oscillator.

3) https://www.britannica.com/science/envelope-sound Information on the Attack Decay Sustain Release envelope.

4) http://www.irf.com/product-info/audio/classdtutorial.pdf Background on Class-D amplifiers and advice for implementing them.

5) http://www.analog.com/media/en/technical-documentation/data-sheets/11602fb.pdf Datasheet for the LT1162 H-Bridge gate driver.

6) http://www.ti.com/tool/LCFILTER-CALC-TOOL TI Class-D amplifier LC filter design tool.