Pages: [1]   Go Down
Author Topic: Interrupt catching high transition at 2.5V, not 3 V on 328P  (Read 571 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2855
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. ]
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: