I'm going to try to implement a timer which is going to be used to control the playback at 8kHz. The timer ISR will send data to the I2C every 125 micro second to keep the 8kHz playback rate.
I'm going to use a global buffer that can be set and you start and stop the timer to play it back. I should probably have some functionality to reset the playback to the start of the buffer as well.
I used ChatGPT to make a python2 script to generate the DTMF tones using the lesser common multiple of each pair. This time, time was actually saved! The largest DTMF tone is the 1 button with 84 samples at 8kHz.
I've made the buffer it can hold 1024 samples, I should probably make it smaller later if I don't need that size.
It sounds horrible!
Bring out the oscilloscope!

The signal looks okay.

It seems like the delay is at 210 micro seconds instead of 125. 210 - 125 = 85 micro seconds. The overhead of the code is 85 micro seconds, I would need to remove that from the delay. 125 - 85 = 40 micro seconds. I'll set it to 40 micro seconds.

Spot on! Sounds a bit better.
I guess I'm into the limitations of the sample rate at 8kHz and the filter at this point. Some of the tones only have a few samples. A higher sample rate is possible if I use PIO to send the DATA to the DAC using high-speed mode at 3.4 MHz. It's tempting to just learn how to use the PIO, perhaps for another project.
Well that concludes my I2C DAC adventure. I've learned about various things in both hardware and software. It's time to move to PWM audio instead.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.