JarkkoL
Well-known member
I ported my 8-bit resistor DAC mod player from Arduino Uno to Teensy3 and the quality of the output is pretty poor in comparison. I suspect this has something to do with how voltage levels vary when different pins are enabled, and that the current flows into other pins when they are set to low (sorry for my newbie explanation). In my test where I outputted 10KHz square wave to pin-0 of the DAC (all the other 7 pins were set to low) and had only the pin-0 connected to DAC, I heard notable decrease in amplitude when I connected pin-1 (which was low) to Teensy. This amplitude drop doesn't happen on Arduino Uno. Below is a video of the quality I get with Arduino, but it's very noisy and barely recognizable on Teensy
The source code is in attachment with the piece of music in it as played in the video. Teensy specific code is in pmf_player_teensy.cpp. I originally used PORTD to output the data on Teensy, but changed it to directly use GPIOD_PSOR & GPIOD_PCOR registers instead for faster pin state update, though I'm not 100% sure I did it right. However this didn't improve the quality. Here's the picture of the DAC and how it's connected to Teensy:
Just to clarify if it's not clear from the image, there's 2 resistors parallel in the DAC for each pin (MSB on leftLSB on right) and resistances for each pin are power-of-two (10467Ohm, 5194Ohm, 2597Ohm, 1304Ohm, 650Ohm, 326Ohm, 163Ohm, 82Ohm for bits 0-7 respectively). The DAC pins 0-7 are connected to Teensy3 pins 2, 14, 7, 8, 6, 20, 21, 5 respectively, which are controlled by GPIOD_PSOR/PCOR bits 0-7 as far as I know.
I tried to add diodes to each pin to avoid current in-flow into pins, but that didn't help. It could be because the diodes I used had quite high resistance and probably a lot of variance.
So, any suggestions how to fix this? I'm not 100% sure if this is software or hardware issue, but I suspect hardware is the culprit.
Ps. Paul, you might be interested to check out the audio mixing routine and envelope handling for your audio shield project. I'll write the mixer and interrupt routines in asm later for Teensy, but I should get the playback fixed first so I can test that my code works.
Thanks, Jarkko
The source code is in attachment with the piece of music in it as played in the video. Teensy specific code is in pmf_player_teensy.cpp. I originally used PORTD to output the data on Teensy, but changed it to directly use GPIOD_PSOR & GPIOD_PCOR registers instead for faster pin state update, though I'm not 100% sure I did it right. However this didn't improve the quality. Here's the picture of the DAC and how it's connected to Teensy:
Just to clarify if it's not clear from the image, there's 2 resistors parallel in the DAC for each pin (MSB on leftLSB on right) and resistances for each pin are power-of-two (10467Ohm, 5194Ohm, 2597Ohm, 1304Ohm, 650Ohm, 326Ohm, 163Ohm, 82Ohm for bits 0-7 respectively). The DAC pins 0-7 are connected to Teensy3 pins 2, 14, 7, 8, 6, 20, 21, 5 respectively, which are controlled by GPIOD_PSOR/PCOR bits 0-7 as far as I know.
I tried to add diodes to each pin to avoid current in-flow into pins, but that didn't help. It could be because the diodes I used had quite high resistance and probably a lot of variance.
So, any suggestions how to fix this? I'm not 100% sure if this is software or hardware issue, but I suspect hardware is the culprit.
Ps. Paul, you might be interested to check out the audio mixing routine and envelope handling for your audio shield project. I'll write the mixer and interrupt routines in asm later for Teensy, but I should get the playback fixed first so I can test that my code works.
Thanks, Jarkko