Electronic – arduino – How to generate tones of different amplitude with Arduino

amplifierarduinoaudio

For a new project with Arduino I need to generate an alarm tone that needs to increase in amplitude over time if the user doesn't take action. The output would be via a small speaker.

So when the alarm condition triggers I would generate a low volume beep in the audible range, give the user some time to react, then increase the volume, wait, increase again until the user reacts. This way I don't generate a loud alarm tone from the start, which can be disturbing in a quiet environment.

Generating pulses and using a transistor or IC amplifier to drive the spaker is no trouble.

–> The issue is: how to modulate the amplitude of the speaker sound?

My limitation is that while sounding the alarm, the Arduino still needs to to other stuff, so I can't stall it in a complicated routine to generate tones for example by doing some fancy PWM that then gets filtered to deliver a signal with different amplitudes.

I could use one pin to generate the base frequency signal, and have 3 pins available to steer some external circuit to modify the amplitude, like this:
enter image description here

Do you guys have some ideas to share?

Tks!

ADDENDUM:
This is the solution I had tried out already, but the volume levels are not repeatable from one unit to the next, so I would like to avoid adding a trimmer pot.
D13 generates a square wave with the audio tone. The other outputs pipe this tone through the resistor ladder via the AND gates.

enter image description here

Best Answer

Your question shows a PWM unit, followed by an adjustable gain stage. This isn't a very obvious form to use, but it might work.

Traditionally, you might use multiple PWM units with different output drive strengths (using resistors), in effect building a DAC.

What you have built should work if you combine the PWM (for switching) with a programmable current source (for amplitude). For the current source, you can use 3 current mirror circuits in paralell, switched by your 3 amplitude controls. Typically you might choose a log-scale for each switching step.

You PWM output can be used to sink current, the 3 current mirror stages source current (and control the amplitude).