Friday, January 3, 2014

sampling multiple analog signals asynchronously with Arduino

So while I was assembling a fellow #arduino denizen's synth project on a breadboard, he commented that Arduino's analogRead hadn't been fast enough to read the pots. After poring over the AVR ATmega328 datasheet for a while I was able to get an interrupt-driven analog-to-digital conversion happening. This is documented in many folks' blogs but most of the pages I've seen only demonstrate one, and I needed four. His acidmatic synth is now rather a lot of fun to twiddle, and I will keep hacking on it, and build a permanent version in an enclosure.

Stripped-down demo code follows. Note that this requires an analog reference signal to be wired up to the AVR. This can actually be done in software if you just want it to be set at Vcc or some other voltage visible to the microcontroller, but I was getting very tired and that part of the datasheet was not making any sense. On my 16Mhz ATmega328, the below code yielded somewhere north of 2000 samples per second per pot. Easily enough for this application.

No comments:

Post a Comment