Hi again @Bakisha , Thank you for the very detailed reply!Bakisha wrote: Sun Jun 28, 2020 1:04 pm @GVisser
After some experiment on my diy-dev board for audio experiments, here is my conclusions:
- Depending on what device you are connected, distortions are present when you are plugged in some equipment with AUDIO-IN. Most probably because it expect 1Vp-p, and you are feeding it with 3.3Vp-p.
Here is recommended audio setup:Also, distortions may come from a way how author decided to create sound. Base PWM frequency of 31250Hz is, IMHO, just too low for 1-bit DAC.Code: Select all
// .-------------------------------------. // | | // | STM32FxxxXXxx | // .---------------------------------|---. // |G P| // |N B| // |D 0-----|R1|------|C2|----------| // | | -- // | C || P1 // | 1 ||<----------------| OUDIO OUT // | | -- // .--------------------------------------------|-----------------|------------------| GND // R1 = 100-500 Ohm // C1 = 100-500 nF // C2 = 10 uF // P1 = 10KOhm potentiometer
maybe it's ok for 1 channel, but for four channels (used in sketch), it is noticeably full of "eeeeeks"
Maybe try with higher capacitor in low-pass filter (500nF+), or higher resistor (500 Ohm+).
In my audio project, i used 250KHz base PWM frequency, that's 4uS period, meaning it is 4*72= 288 (bluepill) or 4*84=336 (STM32F401CC) values for width of that pulse. Enough for 3 channels (each channel is 1/3 of maximum of pulse width).
I think author just ported code for STM32, with all the limitation original code have (for arduino uno).
Also, i don't think it doesn't matter is it PWM1 or PWM2 mode. Beside visually in analyzer. Sound is difference in audio signal, it sound the same when you are altering between 99% HIGH - 1% LOW and 100% HIGH - 0% LOW, and 1% HIGH - 99% LOW and 100% LOW - 0% HIGH. It's the difference of 1% that is creating analog AC voltage.
Personally, i'm more into digital electronics then into analog. With digital, i'm dealing only with ones and zeroes![]()
Anyway,will set correct prescaler and overflow for you, no matter on what speed CPU is (and that's why i like this core: same code, no matter is it STM32F103C or STM32F401CC).Code: Select all
setOverflow(31250, HERTZ_FORMAT);
I have done as you suggested and built the low pass filter. This has worked to limit some of the distortions but I think you are right in saying that the base pwm frequency is just too low to get decent quality audio output. I'll keep working at at, although I suspect that it is possible that the low audio quality output could also be from how the midi file is converted with the smf2seq script.
LOL Yes you are absolutely right about the PWM1 and PWM2 issue, with reference to connecting the output to a speaker, as it would make no difference. My end goal however is to use the signal to drive the interrupt of my solid state tesla coil, and in this configuration, a constant high output (PWM1) would mean death for my coil which requires pulses of less than 10% duty cycle
