cd4052 switching speed

Thread Starter

Sumit Aich

Joined Dec 3, 2016
100
My project needs to read 4 analog inputs. I went through some threads of the forum and learnt that I cant use this code since Atmega 328 ADC multiplexer needs time to switch channels to the ADC.
Code:
void loop(){
a=analogRead(0);
b=analogRead(1);
c=analogRead(2);
d=analogRead(3);
}
Ill have to use delay() for the above code to work. But I cant compromise on analog sampling frequency for my project. So i decided to use the 4052 analog multiplexer.
I'm using grey code to change analog channels serially one after the other.(00,01,11,10)
Code:
void loop(){
digitalWrite(2,0);
digitalWrite(3,0);
a=analogRead(0);
digitalWrite(2,1);
b=analogRead(0);
digitalWrite(3,1);
c=analogRead(0);
digitalWrite(2,0);
d=analogRead(0);
}
Will the latter approach give correct ADC readings and a greater ADC sampling frequency?
 

ScottWang

Joined Aug 23, 2012
7,501
How is the operating voltage of Atmega 328?
– 3.3V or 5V?

‧ Speed Grade:
– 0 - 4MHz @ 1.8V
– 0 - 10MHz @ 2.7V
– 0 - 20MHz @ 4.5V

CD4052 Vdd supply:

5V : 30~60 nS
10V: 15~30 nS
15V: 10~20 nS
 

ScottWang

Joined Aug 23, 2012
7,501
operating voltage is 5V
So you can see the Vdd of CD4052 is 5V and the delay time is 30~60 nS, if you want to get higher frequency then you can use 74HC4052.

74HC4052 -- page 6, VCC = 4.5 V, 1.67~139 ns/V

If you insist to use cd4052 then you can increasing Vcc to get the frequency more higher shown in #3 as 10V or 15V and add a voltage divider as 1/2 for 10V or 1/3 or 15V to get a 5V output.
 

BobTPH

Joined Jun 5, 2013
11,515
Usung an external multiplexer will not help. The reason you must delay when changing channels is so the sample capacitor inside the ADC will settle to the right voltage. You will need the same delay if you change the signal externally.

Bon
 

philba

Joined Aug 17, 2017
959
Usung an external multiplexer will not help. The reason you must delay when changing channels is so the sample capacitor inside the ADC will settle to the right voltage. You will need the same delay if you change the signal externally.

Bon
Exactly! The delay between successive samples is indeed due to sample/hold settling time. The underlying 328 is limited to an adc clock of 125KHz with 13 or 14 clocks (depending on type of sampling) per sample which means about 9.6K per second is your absolute maximum rate.

What sample rate do you need? If you have to be higher, you have several choices - external ADC or a different microcontroller. I suggest looking at the Teensy 3.2. It has 2 ADCs that can operate in parallel. Though I wasn't able to see anything that definitively stated max sample rate. For what it's worth, most microcontrollers won't have super fast ADC. You'll need to go to specialized (external) ADC chips for that.
 

BobTPH

Joined Jun 5, 2013
11,515
With dsPIC you can get 10-bit 1MHz sampling with 4 separate sample and hold circuits so you can sample 4 signals at 250K samples per second.

The garden variety PICs sample at 200KHz, but like your Arduino, need time when changing channels.

Bob
 

ebeowulf17

Joined Aug 12, 2014
3,307
Usung an external multiplexer will not help. The reason you must delay when changing channels is so the sample capacitor inside the ADC will settle to the right voltage. You will need the same delay if you change the signal externally.

Bon
I thought that might be the case, but didn't have the confidence to suggest it. Glad my instincts weren't too far off!
 
Top