Go Down

Topic: Delay in analogRead after switching pin (Read 2 times) previous topic - next topic

dc42

Crossroads,

Yes, reading the pin twice and discarding the first reading does usually solve the problem. But many users facing this situation don't know they need to do that.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

dc42

I've just seen YET ANOTHER post relating to this problem, see http://arduino.cc/forum/index.php/topic,69742.0.html. That's the 4th post I've seen by a user experiencing this problem, and I only joined the forum about 2 weeks ago. Anything that's causing this much trouble for Arduino users needs to be addressed, preferably in the software, or failing that in the documentation.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

CrossRoads

Sure, but then how would we run up our post counts ;)

= vs == also comes a lot.

Very many posters just dive in & ask questions without browsing the playground first; if they did that first (or were even aware that it exists it seems) that would resolve a lot of things.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

retrolefty


I've just seen YET ANOTHER post relating to this problem, see http://arduino.cc/forum/index.php/topic,69742.0.html. That's the 4th post I've seen by a user experiencing this problem, and I only joined the forum about 2 weeks ago. Anything that's causing this much trouble for Arduino users needs to be addressed, preferably in the software, or failing that in the documentation.


Well it is certainly a balancing act. We see many inexperienced people having trouble reading even simple push button switches using digitalRead() because they don't yet understand the concept of a 'floating input pin'. Does that mean the digitMode command should automatically enable the internal pull-up resistor when set to input mode?  I would think that trying to make the analogRead function fool proof for all possible problems would either be not effective or hamper the basic performance of the function.

Still a very interesting topic. I recall a year or so ago where Coding Badly was helping me work out a method such that an arduino sketch could actually measure the voltage value of it's Vcc pin without any external wiring or components. Very useful function if you wish to have 'dynamic' calibration/correction capabilities, where you might be running on battery voltage which decreases voltage over time.

Lefty

dc42

Crossroads, my aim is indeed to reduce your post counts! :D (that wouldn't be such a bad thing, because I find the forum to be rather slow in responding compared to other sites). The = vs == issue is a defect in the C language, which we can't do much about (although good C/C++ programmers generally turn on enough compiler warnings to pick up accidental use of = where == was intended).

Lefty, not enabling pullups when they are needed is an issue of understanding basic electronics, not a limitation of the chip. But the need for a delay between switching pins and reading the ADC is a feature of the microcontroller. That is why I think it deserves to have a workaround built in to the Arduino software.

I'm going to experiment with various analogue signal source resistances to see what delay is needed.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up