Unique behavior on input pin - atmega16

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
I have an atmega 16 with 8 inputs on PORTB. On all 8 pins, I have the input tied to ground through a 10k resistor. And I have a switch tied from 5V to each pin. So if the switch is closed, the pin sees 5V. If the switch is open, the pin is wired to ground through a 5V resistor.

On pins 0 through 6, this works fine. On pin 7 it won't work. On that pin I have to short the pin directly to ground in order to make it change state. The pin seems to float high, and tying it to gnd through the 10k resistor is not enough to drive it low.

The port is configured as PORTB=0x00 and DDRB=0x00.

Can someone explain why the difference in pin behavior? And how to fix it?

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have anything else connected to those pins (such as your ISP programmer)?

And why not connect the switches to GND, remove the resistors, and use the internal pull-ups (PORTB = 0xff)?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
On pins 0 through 6, this works fine. On pin 7 it won't work.
?? There is no pin 0. Do you mean PB0 and PB7?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The pin seems to float high,

What does a logic probe tell you on this input and how does that correlate with measurements with a digital multimeter.

You are not inadvertently writing a 1 to PORT B7 somewhere are you?

The preferred method of dealing with switches is to have the switches between the inputs & ground and use the internal pull-ups to pull the inputs to Vcc when the switches are open. Ie. inverse logic.

This has a technical advantage that you don't have a current unlimited supply line running around you front panel where it can be shorted to ground more easily and you save 8 resistors & the associated real estate.

Not bad...triple cross post!

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?

Last Edited: Mon. Jul 5, 2010 - 01:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The pin has been isolated, and it is not being used for ISP. So,LDEVRIES, are you suggesting that I use no resistors, and wire straight to ground through a switch? I guess I could reverse all my logic and this would work fine. Please verify that this is how you would wire it.

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, you might check the alternate uses of PB7, then look at what SCK is used for.

Then, you might look at the Fuse Bit High table (Table 105 in my spec sheet) and note what the default value of SPIEN is.

If you NEED to use that pin for your switch input, I would make sure that serial programming is disabled.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bearing in mind Jim's comment above, yes, I would change the logic and use the internal pull-ups with the SPST switch grounding the input.
To enable the pull ups

DDRB=0x00;
PORTB=0xff; 

This is not a guaranteed fix, but it is the more common way of doing it.
With no switches operated, check the voltage (or logic condition)
on each of the pins. They should be the same & greater then 70% of Vcc..ie +3.5V for a Vcc of +5V
PS. I did have a minor error in my earlier post, which I have corrected.

Charles Darwin, Lord Kelvin & Murphy are always lurking about!
Lee -.-
Riddle me this...How did the serpent move around before the fall?