DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: nexekho on September 01, 2011, 05:54:53 PM

Title: Low pass a PWM?
Post by: nexekho on September 01, 2011, 05:54:53 PM
I've been looking into getting an Arduino Nano to experiment with some DSP ideas without the latency problems I have with using PortAudio on my desktop.  They have great analogue input features, but outputs are sorely lacking.  It's possible to hook up a DAC/resistor ladder, but each bit costs another digital IO pin and you only have 14 bits even if you leave nothing for control/etc.  I notice that some of the digital pins can pulse width modulate a square wave to approximate analogue outputs, often used with LEDs, etc. so if I included a low-pass filter, could this be used for an analogue output?

(I have several years' programming experience including a decent amount of work homebrewing for GBA + NDS)

Thanks.

EDIT: Could I use two pins, both low passed, one with a low volume, to get 16-bit out?
Title: Re: Low pass a PWM?
Post by: potul on September 01, 2011, 06:32:25 PM
You can use PWM for audio with some filtering, and yes, you can use 2 8 bit outputs to get 16 bits. Take a look at this project, it explains quite well how to get 16 bits resolution out of 2 8 bits pwm outputs:

(damn... the site seems to be down.... hunt for a project called TRAXMOD, it had a nice explanation on how to get those 16 bits combining 2 8 bits pwm outputs. Maybe you can use waybackmachine to get the page back)
Title: Re: Low pass a PWM?
Post by: potul on September 01, 2011, 06:34:09 PM
here you have a cached copy:

http://web.archive.org/web/20110713131212/http://www.k9spud.com/traxmod/pwmdac.php (http://web.archive.org/web/20110713131212/http://www.k9spud.com/traxmod/pwmdac.php)

mat
Title: Re: Low pass a PWM?
Post by: .Mike on September 01, 2011, 06:44:53 PM
See the datasheet for the VCLFO9D or the TAPLFO2. They both output PWM, and they both include example filters for smoothing the PWM, and swinging it +/-.

They do not, however, use the PWM for audio, just for LFOs.

Likewise, there is some filtering shown in my working draft (http://imageshack.us/photo/my-images/32/ttphaser.jpg/) of a tap tempo phaser that was working pretty good.

Mike
Title: Re: Low pass a PWM?
Post by: nexekho on September 01, 2011, 06:46:01 PM
Ah, thanks, I suspected as much.  I note that he uses straight-up resistors instead of resistor dividers; is there an advantage to this?
Title: Re: Low pass a PWM?
Post by: nexekho on September 01, 2011, 07:00:50 PM
Found someone else had done the research and built something pretty decent:
http://www.instructables.com/id/Lo-fi-Arduino-Guitar-Pedal/step4/Normalize-the-Input-and-Output/ (http://www.instructables.com/id/Lo-fi-Arduino-Guitar-Pedal/step4/Normalize-the-Input-and-Output/)
Title: Re: Low pass a PWM?
Post by: nexekho on September 15, 2011, 09:20:55 PM
I have built the Arduino Nano DSP and though it's not very powerful in mono you can get some seriously decent effects.  My chorus:
http://soundcloud.com/nexekho/much-much-smoother (http://soundcloud.com/nexekho/much-much-smoother)
http://pastebin.com/2ed16VD0 (http://pastebin.com/2ed16VD0)
(note: designed for above circuit)