What's the problem of connect a comparator (eg. LM311) to digital pins (PORTD)

Hi all,

probably I'm ignoring some basic problem but could anyone please help :D with this?:

I have a comparator with no histeresys (LM311) connected to Atmega328's Pin 4 (ARDUINO digital pin 2). This pin is also indicated as PCINT18/INT0 or PD2.

The comparator has to compare a very weak digital signal that varies between -0,3V and -0,9V and output must be TTL (so then I can drive it to attack AtMega's digital pins) - this function is doing well, I tested.

Ok, so the output of the comparator is TTL (0 to 5V - I checked that) and gives me the right values, but when I connect to Pin 4 the signal drops to a level that is no more recognized as TTL, because ATMega reads 0 from that pin all the time.

The drop is normal but I expected that it was a very short one. So...is the pin consuming more current than normal? Does it present a low impedance? (I programmed the Arduino digital pin 2 to INPUT).

Any one can give me any suggestion about the error I'm doing here? I have no clues, but I'm not an expert on ATMega either :roll_eyes:...

Is there anything special about this PORT (I tested every pins of the D port) that can't be used as a TTL input?

Thanks for your help.

Did you enable the pullup resistor on pin 4 (digital pin 2)? The LM311 can only drive a low output, it needs a pullup resistor to signal a high output.

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

Hi RuggedCircuits :),

thanks for your quick answer.

I thought the internal pull-up was automatically enabled when we define the pin as INPUT? Or is there a specific instruction to be given?

Or is there a specific instruction to be given?

Yes once the pin is set to input do a digitalWrite(pin, HIGH); to enable the internal pull up resistor.