Anda di halaman 1dari 4

Search for questions, people, and topics Ask New Question Sign In

Quora uses cookies to improve your experience. Read more

Arduino (company) Electronics Related Questions

Why is a little delay needed after analogRead in How does an Arduino's analogRead work?
Arduino? What is minimum delay in Arduino Uno?

Ad by Tipalti What are some techniques to get rid of delays in


my Arduino code?
Automate global mass payments to 150 countries in 120 currencies.
Tipalti helps businesses make mass payouts. Get started with global integration! Why we take a delay in milliseconds in Arduino
instead of seconds?
Learn more at tipalti.com
How do I can control more than 19 LEDs each
individualy, with the help of Arduino?
2 Answers
Which one is better for a development in robotics,
OXullo Intersecans Arduino or Raspberry Pi?
Answered Feb 27 2015
Which is the best for beginners: Arduino Uno or
Short answer for a fairly reliable (not minimal) delay:
Arduino Nano?

What is an Arduino board?


T=5 * (R+100kOhm) * 14pF
How can I learn what every part of the "Raspberry
Pi", "Arduino", etc. do? What are some books that
where T is the delay in seconds, R the impedance of your analog source to can help me?
measure in Ohm.
What is an Arduino used for?

Example for 10kOhm: 42µs Ask New Question

With most AVR boards, invoking twice an analogRead() discarding the first
result is enough:

1 analogRead(A0); // discard
2 uint16_t adcValue = analogRead(A0);

Verbosity warning if you continue!

Let's consider the premises that we're talking about AVR architecture
(eventually considering a popular Uno board w/ ATmega328p @16MHz
http://www.atmel.com/images/Atme... ) and arduino core libraries 1.0.5.

Arduino initializes the ADC prescaler to the slowest speed (128x). This is set by
the init() function defined in wiring.c:

https://github.com/arduino/Ardui...

You can also see that the ADC is enabled at this moment (line 314), but since no
conversion is requested by arduino's initialization routines, the ADC is not
initialized until you call the first analogRead().
So, as Peter Hand already pointed out, you need at least 13 ADC clock cycles (or
1664 µC clock cycles). At 16MHz µC clock, this means 104µs. During your very
first analogRead() you need 25 ADC clock cycles (or 3200 µC clock cycles or
200µs).

This is anyway what is needed for a full *conversion* (plus a bit of time for the
S/H), that is the time needed for the ADC to set the values of ADCL and ADCH
registers (the places where the µC store the numeral data representing the
voltage level of your input) via successive approximation (if you're interested:
http://en.wikipedia.org/wiki/Suc... ).
Search for questions, people, and topics Ask New Question Sign In

Arduino uses a single conversion mode and waits synchronously for the ADC to
terminate the conversion. This means that you don't have to explicitly wait
104µs (or 200µs for the first time), because the analogRead() function will block
until the conversion is done.

Check the actual code:

https://github.com/arduino/Ardui...

(note also line 73 and its comment above).

The reason why it's common use to delay between analogReads is usually due to
input channel selection and input impedance.

Arduino's analogRead() function, as you can see on the code above, sets the
MUX and starts the conversion immediately after. It's not an issue if you
constantly read from the same channel,  but if you were sampling another
channel before, this might impact the reliability of the conversion.

(snapshot from page 244 of the ATmega328p datasheet)

The impedance of the input signal is relevant for calculating the time needed for
the internal S/H capacitor to load up and level to the signal you're measuring.
This is basically your target: when you trigger the conversion, you want the
capacitor to be equipotential to the selected channel input. If you're too fast,
relatively to the input impedance, you might end up in reading garbage.

Atmel suggests to keep the input impedance below 10kOhm (read paragraph
24.6.1 of page 243 of the 328p datasheet), which means that the time needed to
charge the S/H capacitor is negligible (7.7us, as the 5*RC time constant of the
worst case 110kOhm and 14pF) and handled by the 1.5 ADC clock cycles (or 12µs)
the µC waits before starting the actual conversion (table 24-1 page 242 and
timings above, in particular 24-5, page 241).

But what if you have a 1M+ impedance input?


5*RC = 77µs. The 12µs delay time granted by the ATmega µC then is not enough
for let the capacitor to charge or discharge (we're still considering the worst
condition, such as S/H capacitor at 0V and input signal at 5V or viceversa).

Hence the workaround at the beginning of this answer. With the previous
premises, an analogRead() takes 104µs in total to return and this is enough for
properly charging the S/H capacitor:

1 analogRead(A0); // switch the channel to A0 and hold for 104µs


2 uint16_t adcValue = analogRead(A0); // proper readout
Search for questions, people, and topics Ask New Question Sign In

Words of wisdom: never exceed 10kOhm impedance on the input side. If your
sensor has higher impedance, use a buffer ( http://en.wikipedia.org/wiki/Buf...
)

What is 5*RC ?
tau=RC is a capacitor time constant, or the time needed for a capacitor of
capacitance C (Farad) to charge to ~63% or discharge to ~37% through a resistor
R (Ohm) ( http://en.wikipedia.org/wiki/RC_... ). As you see and probably
studied from physics lesson, this process is independent from ∆V.
The 5x factor serves to ensure a close approximation of the complete charge,
being the time 5*RC called "transient response" ( http://www.electronics-
tutorials... ).

Small step back and I try to explain the input impedance concept as best as I
can.

An ATmega µC has generally one single ADC. Multiple input channels are
routed to the ADC via a multiplexer (MUX), which simply connects the wanted
channel to the ADC.
As soon as the MUX is instructed to route the channel, the 14pF capacitor starts
to charge (or discharge!).
But when the conversion starts, the channel is disconnected and the ADC uses
the charge contained in the capacitor to define the resulting sample value.

Consider this analogy:

Suppose we have three

sensors connected to A0, A1, A2, represented by three water tanks (suppose of
infinite diameter but having a variable water height).
The ADC S/H, or the 14pF capacitor, is another tank (but with finite diameter)
which sits on the same level of the other three.
The water level is the voltage level of either sensors or ADC capacitor in respect
to a common ground.
The pipes have different sections and that is the impedance of each sensor.
The boxes called MUX are valves. Only one can be open at given time.

So when we want to "sample" a sensor, we open the relative MUX valve and the
water starts to flow. It flows towards the S/H if the level of the sensor tank is
higher or the other way round if it's lower.
This process takes a while and depends on the pipe diameter. Water flowing is
analogous to charge transfer.

So if you were to start the conversion in the moment depicted by the snapshot,
you'd ended up in reading the wrong level.
14.1k Views · View 11 Upvoters
Search
Your feedback for questions, people, and topics
is private. Ask New Question Sign In

Is this answer still relevant and up to date? Yes No

Sponsored by Highbrow
Learn something new in just 5 minutes a day.
Get smarter with 5-minute lessons delivered to your inbox every morning. Get
started for free!

Learn more at gohighbrow.com

Related Questions More Answers Below

How does an Arduino's analogRead work?

What is minimum delay in Arduino Uno?

What are some techniques to get rid of delays in my Arduino code?

Why we take a delay in milliseconds in Arduino instead of seconds?

How do I can control more than 19 LEDs each individualy, with the help of Arduino?
Ask New Question

Peter Hand
Answered Feb 26 2015 · Author has 7.1k answers and 13.8m answer views

It depends on the settings for the ADC, for which you'll have to examine the
code. analogRead starts a conversion, which takes a certain number of clock
cycles. A normal conversion takes 13 ADC clock cycles (except the first one after
the ADC is enabled, which takes 25). An ADC clock cycle takes a certain number
of 8MHz processor clocks, depending on the setting of the ADC prescaler, which
is one of the parameters you have to look up. A prescale of 128 is typical for
maximum accuracy, which means every ADC cycle takes 16 microseconds,
which means a conversion takes 208 microseconds. Read the AT Mega 328 data
sheet, section 24, for details.

You don't have to hang about waiting for the ADC if you monitor the ADC
interrupt flag, ADIF, bit 4 of register ADCSRA. If you take that route you have to
clear ADIF manually by writing a '1' to it to clear it for the next conversion. If you
enable the ADC interrupt, the interrupt service routine clears it for you.
5.6k Views · View 5 Upvoters

Related Questions

Which one is better for a development in robotics, Arduino or Raspberry Pi?

Which is the best for beginners: Arduino Uno or Arduino Nano?

What is an Arduino board?

How can I learn what every part of the "Raspberry Pi", "Arduino", etc. do? What are some
books that can help me?

What is an Arduino used for?

Where do I buy Arduino and its related electronic components in Chennai?

Does the Arduino Uno work after using it with the Arduino Yun Shield?

Why is Arduino used?

In Arduino, why is there an extra client after WifiClient()?

Is Arduino related to C?

Can I directly connect microcontroller after uploading sketch on Arduino?

What exactly is an Arduino code?

Why is Arduino open source?

How do I take samples from analogRead value for a particular time in Arduino?

What is Arduino coded in?


Ask New Question

Anda mungkin juga menyukai