[CART360] Arduino Hardware timer + Multichannel synthesis code

Morgan Sutherland morgan at morgansutherland.net
Sat Nov 28 21:29:52 EST 2009


I used this code for sine wave synthesis for my exquisite corpse:

http://blog.wingedvictorydesign.com/2009/05/29/generate-real-time-audio-on-the-arduino-using-pulse-code-modulation/all/1/

This is the key:

Analog output: The Arduino isn’ t capable of outputting a true analog 0-5V
> signal.  So we’re going to use Pulse Width Modulation, which was intended
> for dimming LEDs.  Now, the default Arduino PWM frequency is 500Hz, which is
> useless for audio output because it’s much slower than most of the
> frequencies we want to generate.  However, if we monkey with the control
> registers, we can speed it up to 62,500Hz, which is significantly faster
> than the audio range of 20-20,000Hz.  Here’s what that looks like in code
> (I’m using timer2):


On Sat, Nov 28, 2009 at 7:54 PM, joN <jonnygexter at gmail.com> wrote:

> Hi.
>
> I remember a few people mentioning sound in their projects... if someone is
> interested, I rewrote the code our group used for design brief 2 to be more
> user-friendly. You can use it to output multiple frequencies to different
> channels at the same time, with one bit of resolution (square wave). The
> output is not perfect, but it is a very simple way of synthesizing
> multi-channel output with the Arduino. It's posted here: _arduino
> polyphony code<http://wilansky.com/jon/cart360/other/ArduinoPolyphony.zip>
>
> Also, I am researching implementing a version that uses the low level
> hardware timers on the Arduino. I'm told it would improve the accuracy of
> the output (though I don't understand why). I'm having trouble and seeking
> help.
>
> This seems like the simplest example:
> http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208192843
> but I need some help on identifying those weird variables/functions and
> calculating the real time value from timer ticks. Anyone know of good
> examples or explanations? I looked in the Atmel datasheet, but I find it
> hard to understand.
>
> And Vincent went over this last week:
> http://www.arduino.cc/playground/Main/MsTimer2
> - Is this just an abstraction/higher-level way to use the hardware timers (
> Timer2)? Will it work for audio synthesis?
>
> Jonathan
>
>
>
> _______________________________________________
> CART360 mailing list
> CART360 at uttermatter.com
> http://uttermatter.com/mailman/listinfo/cart360_uttermatter.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://uttermatter.com/pipermail/cart360_uttermatter.com/attachments/20091128/f0c83490/attachment.html>


More information about the CART360 mailing list