Go Down

Topic: Interrupt catching high transition at 2.5V, not 3 V on 328P (Read 612 times) previous topic - next topic


I am monitoring a voltage on digital pin 2 for a value in excess of a preset limit.
I can set that limit, but it depends on what Arduino thinks is a HIGH. I thought
that was supposed to be 3V or is that not quite accurate.


That is not quite accurate. The Arduino *guarantees* that 3V or higher will be recognized as high, but it reserves the right to have the actual threshhold be lower. So one device thinks high is 2.8V, another thinks it is 2.0V, another thinks it is 2.4V, etc. and yet they all meet the guarantee that if you drive a pin with 3V or higher, it will be considered "high".

The Rugged Audio Shield: Line In, Mic In, Headphone Out, microSD socket, potentiometer, play/record WAV files


In general you cannot use a digital input to measure voltage - there are several reasons for this:

The ATmega inputs are actually schmidt-triggers, which means the transition voltage is different for rising voltages and falling voltages.

The actual transition voltage(s) will vary from device to device, will vary with supply voltage, possibly with temperature too - its not specified.

If you were using a CMOS chip that didn't have schmidt trigger inputs then you shouldn't be putting any slowly varying voltage into an input pin at all - this causes the input gate to dissipate large currents when both n-channel and p-channel devices are on simultaneously.  You can also get oscillation within the input circuitry due to the high gain of CMOS inverters in the linear (forbidden) region.  For this reason you usually always connect all unused inputs to GND or Vdd.

The ATmega microcontrollers do a lot to help us out and let us leave usused inputs unconnected.  They also disconnect the pins from the input circuitry when in sleep mode using built-in bilateral CMOS switches.

For detecting a voltage level you should choose either an analog input and analogRead(), or do some research about the analog comparator that's on the ATmega (try searching these forums, otherwise you'll have to delve into the datasheet for the ATmega328 family).

[ I've used another microcontroller (Parallax Propeller) where the input circuits are specifically designed to work with both digital and analog input voltages and switch very close to mid-rail.  They also have a slight amount of hysterysis to prevent oscillation - that device would do what you want quite nicely I suspect. ]
[ I won't respond to messages, use the forum please ]


Thank you Mark - more or less what I figured, but you confirmed it. I will use them that way, only because I need a VERY fast way to detect a rapidly rising voltage (e.g. short-circuit detection.) Your confirmation will now guide my design.


The usual method is a comparator, which are designed to switch very fast (faster than your interrupt routine can respond, certainly).  You get to set the trigger voltage accurately with a resistor-divider, you can determine how much hysteresis to use, and most comparators will work from 5V upto 30V or so and drive any logic load (but need a pull-up resistor since the outputs are usually open-collector).  For example I've recently used an LM339 (quad comparator in 14 pin DIL package, all of 12 pence (20c))

At a pinch an op-amp can be used as a comparator, but its not ideal.
[ I won't respond to messages, use the forum please ]

Go Up