Playing back audio from a PWM output to a piezo transducer

Hi all,

Has anyone played back voice prompts via any of the PWM outputs to a piezo sounder before?

I have a sound that can play audio tones via the PWM output.

I need to add a single short voice prompt to a design that does not have an MP3 circuit. It doesn’t have to be high quality as long as it doesn’t sound like a robot.

@ Dave McLaughlin - not sure how you can do voice with a PWM. i thought an analog output would be used?

https://www.ghielectronics.com/community/codeshare/entry/511

Basically what you are describing is a class D amplifier. PWM in and analog out. Its a very efficient system.

The downside is that you need to modulate the PWM much faster than the upper frequency of the audio. For your case you might get away with around 5khz bandwidth. So modulating at maybe 15khz would do it.

Probably definately possible with RLP and maybe just with blocking managed code.

Interestingly there is a hack for the raspberry Pi that turns one of the GPIO pins into a radio transmitter at about 100MHz. The quality is surprisingly good.

I’ve spotted some code in Codeshare from Gus and another from WouterH that does this. I was hoping the PWM output could do this and save on additional components but looks like I might have to do some rework on the design to add a small audio amplifier. Downside is finding something that works on 3.3V as the power supply has been designed to meet CISPR25 standards and adding any other regulators may affect this. :frowning:

basic LM386 works from 2v
http://www.ti.com/lit/ds/symlink/lm386.pdf

Works from 2.5V to 5.5V
https://datasheets.maximintegrated.com/en/ds/MAX98357A-MAX98357B.pdf

I would try analog into a piezo to see if it works.

Datasheet says 4V to 12V. I’ve found that the LM386 on 5V is not as good as 12V.

I’ve gone for an LM4871 from TI as easy to get here and it can drive 1W into 8hm which should be loud enough for this application.

The MAXIM part they don’t have.

@ Dave McLaughlin - You know that WAV file playback is bakeed into the GHI premium libraries right? https://www.ghielectronics.com/docs/342/wav-audio-playback

If an amp is needed then this should do the trick https://www.sparkfun.com/tutorials/392

Or you could use an I2S based class D amp such as this one. https://www.coolcomponents.co.uk/i2s-3w-class-d-amplifier-breakout-max98357a.html?gclid=CLXWq563wM0CFesV0wodvP4Eqw I believe it’s possible to make SPI emulate I2S.

1 Like

No, but I do now. I’ve already reworked the design to add an audio amp.

This works really well except when not producing sound there is an output that causes noise on the output. The input wave is clean and 8 bit PCM.

I have to use an analog output with 0 to stop the noise after the command is spoken.

1 Like