Electronics > Beginners

Ran out of DACs - need ideas producing audio output from MCU

(1/3) > >>

bitman:
I have a small ESP32 project which is connected to a HUB75 LED display and that takes care of about every interesting pin at least from a DAC/ADC perspective. Problem is, I would like to generate a bit of sound (for a kids game). The "old" obvious way is to use the build in DACs which the ESP32 has two of, but they're both taken by the default HUB75 connectors. I have a bit of a task to figure out if they're taken because they're DACs or because they're pins, but beside that - I am looking for a way to generate audio sound waves in the 1-5kHz range.

I'm looking for ideas to do this. I tried an external DAC that uses i2c but boy, that's slow and not even close to fun (at 9 bit resolution I don't even get 10Hz!). And for some reason it looks like my MCP4725 "turns off" the output when new data is sent - perhaps my "off the shelf" converter just isn't up to this task.  I was thinking of using PWM to generate a sound wave but that seems to require yet another MCU and that sorta kills the idea. So I need ideas.

My next experiment is setting up a timer and use a digital pin out, even though that's a square wave that may be "good enough for 4 years old".  But in the mean time I was thinking I may be overlooking the obvious here, so I wanted to ask.

At this point I may simply go with 555 and a fixed frequency I can turn on and off :D  But it would really be nice if I could have a small tune or speech from a WAV played.

james_s:
Seems a bit silly to use a 555 if you've got a microcontroller. A digital pin on the micro can do pretty much anything a 555 can. On FPGAs I typically use a delta-sigma DAC but I don't know if that's feasible on a microcontroller.

ve7xen:
ESP32 has hardware PWM? I would use that.

HUB75 also seems to be a purely digital device so it likely wouldn't be hard to move it to other pins.

langwadt:

--- Quote from: ve7xen on October 18, 2021, 10:49:04 pm ---ESP32 has hardware PWM? I would use that.

HUB75 also seems to be a purely digital device so it likely wouldn't be hard to move it to other pins.

--- End quote ---

google to the rescue: https://deepbluembedded.com/esp32-pwm-tutorial-examples-analogwrite-arduino/

brucehoult:
A few years ago now I did an experiment using a single GPIO to output sound. I even used the awful Arduino digitalWrite() to do it rather than manipulating the port directly.

It worked pretty well right off, and could probably be improved with a bit of work.



That's using the CPU to turn the GPIO on and off every single time, but if you have a PWM you'd only have to change the PWM setting at 22 kHz i.e. every 45 us.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version