Simplest square wave envelope generator

Thread Starter

Green Bean

Joined Mar 31, 2017
126
I want to build a very simple circuit that will sound a tone with the press of a button and once the button is released, have the tone decay gradually instead of instantly switching off. If I use a square waveform, this could be as simple as feeding the signal into the collector of an NPN BJT, connecting the emitter to a speaker thru a current limiting resistor, and connecting the base (thru a resistor of course) to a voltage source that decays when the button is released.

As it happens I built such a circuit to test this idea and i am not satisfied with the result. For the decaying voltage part i just connected a button (supplying 5v when depressed) to the base of the BJT thru a 1k resistor with a 100 uf capacitor going to ground (in a low pass filter type configuration ya know). That way as the cap discharged the voltage would decay.

Heres the problem. At first, i had it set up so when the button wasnt being pressed, the the transistor base was basically floating (except that it was connected to ground thru the cap). The result was that because the discharging of the cap isnt linear, when the button was released the sound didnt just gradually fade to nothing, it went from full loudness to somewhat quiet very quickly and then verrrry slowly died away (seemingly never quite reaching the point where you couldnt hear it). This basically made it so you could always hear the beep very quietly, even when the button wasnt being pressed. So i tried using a pull down resistor on the output of the button, which made the beep quieter when the button wasnt being pressed (although it was still audible which i absolutely do not want) and also made the sound fade much too quickly.

Is there an easy way of accomplishing this with the parts i am already using? Or should i use an op amp or something like that. To be honest i dont like using op amps because i only have a single ended power supply and the single supply opamps i have used so far have been very unreliable.
 

danadak

Joined Mar 10, 2018
4,057
How many channels of this do you need ?

How do you want to decay, linear, exponential, log....?

Approximate decay time(s) ?

Tone, sinewave ? Or.....


Regards, Dana.
 

crutschow

Joined Mar 14, 2008
34,472
How about something like this.
The 555 is connected as an astable to generate a square-wave signal of about 1.5kHz (adjustable by pot U4).
Capacitor C1 provides a decaying voltage to the collector load of Q1 after S1 opens (blue trace), causing its output voltage to follow the decay (yellow trace).
The value of C1 can be varied to adjust the decay time, as desired.

That gives an exponential decrease of amplitude with time, but that should give a sort of linear drop-off in sound with time, since the ears sensitivity to loudness is logarithmic.

upload_2019-5-29_20-4-58.png
 
Last edited:

danadak

Joined Mar 10, 2018
4,057
One possibility -

PSOC, 4 channels, wavdac produces sin, tri, square, saw, arbitrary....Each wavedac has dual
waveform output and select via a control register. So 4 waveforms active at any one
time, but 8 total to select from.

Then use external to PSOC a quad I2C digital pot, controlled by PSOC, feeding it decay
waveshape, again arbitrary waveform. This could be done using onchip DMA. Or just
polling. Buffer digital pots with a quad OpAmp if necessary.

Trigger for decay and tones could be complex, a combination of digital and analog
conditions, by using onchip A/D and other digital resources.

Note the wavedacs, I2C, DMA all onchip. Right hand window shows resources onchip
used, and remaining (quite a lot actually).

Wavedacs configed as shown with internal OpAmp buffers. Could config them as
current source and mix them all to 1 pin, so four tones summed at one pin and
enveloped by I2C pot, 1 channel, or a combination of configurations, you choose.
If wavedacs all configed as current then opamps (4) could be used to buffer digital
pots.

Also if using buttons PSOC has onboard button debouncer so no false triggers
generated by mechanical buttons passed onto system.


upload_2019-5-30_7-4-52.png

The config and setup of Wavedacs trivial, but the application of DMA and I2c interface
for decay modulation more involved. Not a beginner project. But example shows you
what can be done with modern devices as you become more experienced.


Regards, Dana.
 
Last edited:
Top