Simplest high quality beep

Paul Young
Posts: 3
Joined: Tue Jul 25, 2017 5:32 pm

Simplest high quality beep

Postby Paul Young » Tue Aug 22, 2017 1:11 am

I need to generate a beep, that is a sine wave in the 300-1200 Hz range. I also need to control the amplitude. This will feed an audio amplifier. I know I could do it using the DAC and a timer but that's 8 bits and I'd prefer higher quality. My goal is to use the minimum number of components so I don't want to use an external DAC.

Does anyone have a good hack using PWM or the I2S unit or anything else in the chip?

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Simplest high quality beep

Postby ESP_Sprite » Tue Aug 22, 2017 2:28 am

Can it be hackish? If so, something thay may work is taking the two 8-bit DACs and using a resistor network to hook them together in an 1:256 ratio? If you do this, you effectively have an 16-bit DAC (although the exact precision depends on the tolerance of the resistors, as well as the load on the DACs... I'd recommend using pretty high-value Rs and a voltage buffer.)

Also, the PWM channels in the chip can theoretically run at 80MHz. An 12-bit PWM channel would give you a 39KHz sample rate. (You may need a lowpass filter afterwards, but at 1200Hz, that shouldn't be too hard.)

More practical and boring would be to just grab an I2S DAC anyway. An ES9023 doesn't need very many external components and can beep in 24-bit precision at you.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Simplest high quality beep

Postby loboris » Tue Aug 22, 2017 6:38 am

Maybe this could help...
Conclusion

ESP32 has on board cosine waveform generator with adjustable frequency, scale and offset. The waveform has 8-bit resolution and can be output to GPIO25 (channel 1) and / or GPIO26 (channel 2) pins. Scale and offset can be set individually per channel. Frequency setting is common to both channels and ranges from 130 Hz to about 100 kHz, where conversion artifacts became visible. It is possible to lower bottom frequency to 16 Hz with setting non default clk_8m_div divider. The waveforms are generated by ESP32's hardware without any overhead on CPUs.

Paul Young
Posts: 3
Joined: Tue Jul 25, 2017 5:32 pm

Re: Simplest high quality beep

Postby Paul Young » Tue Aug 22, 2017 2:47 pm

It can be extremely hackish. This is a one-off project.

I thought about using two 8 bit DACs and resistors. Just getting two good bits from the second DAC would require better than .1% divider accuracy. Unless I'm missing something that would be tough to do.

The PWM output might be the best way to go. 80 MHz / 4096 counts for 12 bits is 19.5 KHz. A simple resistor and capacitor should be enough to clean it sufficiently.

The built-in cosine generator doesn't allow fine enough amplitude control. The processor doesn't have much to do in this project (it is way overkill) so there's no real advantage to using the hardware generator.

This needs to fit in a small space. I can fly a few passive components between the ESP32 board and the amplifier board. But anything active would require another board and that might be a problem.

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: Simplest high quality beep

Postby tele_player » Wed Aug 23, 2017 5:05 pm

I'm not convinced there is any benefit to using more than 8 bits. What dynamic range do you need?

Paul Young
Posts: 3
Joined: Tue Jul 25, 2017 5:32 pm

Re: Simplest high quality beep

Postby Paul Young » Wed Aug 23, 2017 9:38 pm

I don't really know how much dynamic range I'll need. I'm putting the ESP32 board into an existing enclosure with an amplifier and speaker. 8 bits will probably suffice but I'm curious as to whether I can find a better way given all of the nice hardware on the chip.

Who is online

Users browsing this forum: pcouderc and 101 guests