[sdiy] understanding direct AVR ADC...multiple channels

dan snazelle subjectivity at hotmail.com
Tue Mar 6 04:16:15 CET 2012



On Mar 5, 2012, at 9:07 PM, Ove Ridé wrote:

> On 6 March 2012 01:29, dan snazelle <subjectivity at hotmail.com> wrote:
>> however, I have never been able to find any good articles that show how to sample with the ADC directly WHEN YOU HAVE FOUR INPUTS.
>> 
>> In other words, lets say I have two audio sources, two CV potentiometers.
>> 
>> I have never understood if I am supposed to take the ADC code and quadruple it? and if so, doesnt that mean that every step will have to wait for every other step?
> 
> The chip only has a single ADC, which is shared between all channels
> via a multiplexer. So yes, you can only read one channel at a time.
> You may want to switch between the two audio ADC channels every loop
> cycle, and read the pot data only every xth cycle of the loop.
> 
> REPEAT 16 TIMES{
>  Read audio 1
>  Read audio 2
> }
> 
> Read potentiometer 1
> 
> REPEAT 16 TIMES{
>  Read audio 1
>  Read audio 2
> }
> 
> Read potentiometer 2
> 
> Choose a good value for how often you want to read the potsdepending
> on desired time resolution. This will give you some very small (one
> sample) hiccups in the sound at that regular interval, but better than
> not being able to read the potentiometer at all, right?,
> 
>> Will this STILL be quicker?
> 
> If I understand your question correctly, the answer is that the
> conversion will take the same time, but I believe you can use the CPU
> for other things while the conversion is being performed. The Arduino
> analogRead fucntion on the other hand will stay in a loop polling for
> the conversion to be finished. So, rolling your own code will more
> efficient for that reason. (This is how I believe things are, anyway.
> I'm reading the datasheet and making gueses how the Arduino coed works
> internally. I may be somewhat off.)
> 
>> Also...advice...should I just ditch the upper 2 bits and deal directly with the 8 bit register of the ADC?
> 
> Almost. Ditch the lower 2 bits. Ditching the top 2 bits would create a
> four repetitions of 0-255 over full voltage range.
> Tip: There's a flag called ADLAR (bit 5 of the ADMUX reigster) which
> controls the distribution of bits between ADCH and ADCL.
> ADLR = 0 pushes the bits to the bottom, so ADCL contains the lowest 8
> bits and ADCH the highest 2.
> ADLR = 1 pushes the bits to the top so ADCH contains the highest 8
> bits and ADCL contains the lowest two.
> If you want to read everything as a 16 bit value, use mode 0. If you
> want to use only 8 bits, use mode 1 and only read ADCH to get your 8
> bits.
> 
>> and should I use free running? or triggered?
> 
> Good question. I would probably personally at least begin by
> triggering the ADC manually from your code so you have control over
> things until you learn how things work.
> 
>> There are only a few pages I can find that tread on this territory and none of them are SDIY oriented.
>> 
>> ANY HELP, links, code, etc book recommendations, etc would be much appreciated!
>> 
>> I have gotten ONE CHANNEL working
> 
> Ah! Use the lower 4 (or really 3) bits of the ADMUX register to select
> the input. I think the Arduino pretty much puts the ADC channel
> selection here. This is also where you have the aformentioned ADLAR
> bit, as well as voltage reference selection bits.
> 
> I don't know if you need this advice, but another thing you need to
> consider for audio use is biasing and levels. The ADC will read values
> between 0 and 5V whereas audio signals might be bipolar, and perhaps
> stronger than 5V peak to peak. Simple fix: Connect the ADC pin to
> ground and +5V through a resistor 4.7k or 10k resistor to each place.
> This is to center voltage level. Then connected the audio source to
> that point through a 4.7 uF capacitor. This should make the bipolar
> audio signal at the input swing around 2.5 V rather than 0 V, so you
> can reda the full range with the ADC. There are mroe elaborate things
> you can do I suppose, but that's better than clipping away the
> negative half of the waveform.
> 
> Potentiometers can just be conected straight to the ADC, with the
> clockwise terminal to the positive voltage used by the Atmega and the
> CCW terminal to Gnd. (I.e. no special treament/biasing needed.)
> 
> Above all, read the datasheet!
> 
> -- 
> /Ove
> 
> 

yes i have read the datasheet many times but I guess its a bit dry in places


i have been offsetting my input audio (if it needs to be)

and I have also been adjusting Voltage ref, and prescalers, etc


my main fear has been 

1. where to put the code 
2. how to set up the interuppts


i am going to DIVE back into the books and datahseets tonight..your comments help quite a bit


thanks


More information about the Synth-diy mailing list