|
From: | Rick Altherr |
Subject: | Re: [avr-chat] Getting started |
Date: | Fri, 4 Jan 2008 15:57:26 -0800 |
On Jan 4, 2008, at 3:50 PM, J D Freeman wrote:
On Fri, Jan 04, 2008 at 03:09:07PM -0800, Rick Altherr wrote:If your switch is betwen PD0 and +5V, why do you need the pullups enabled? That would make it always be +5V since when the switch is off, it would bepulled up by the pull-ups.Reading the datasheet, setting PORTD to zero should disable the pullups.To be sure, I tried adding a line to force it: MCUCR = _BV(PUD); This makes no difference.So, either I am not setting the pin's up properly. OR, I am not readingfrom them correctly. Or both.
I was basing my comment on the code comments. They said the pullups were being enabled. They should not be. In fact, you should have a pull-down externally for robustness otherwise the inputs will float and could cause spurious triggering. You could also use the internal pullups and connect the switch between PD0 and GND which would invert the logic, but would avoid an extra external component.
So, every iteration through the loop, PD0 is checked to see if it is 1. Because of the above, it always is. Then, it toggles PC4. Depending on how fast the clock is going, this could easily be toggling at a rate that the naked eye cannot see. For a 1MHz part, it could take 4 cycles to run an iteration of the loop, so the LED would be toggling at 250KHz, or stated another way, would have a 50% duty cycle at 125KHz.That makes sense. Sticking a delay in the loop just makes it sit there and flash. J _______________________________________________ AVR-chat mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/avr-chat
-- Rick Altherr address@hidden"He said he hadn't had a byte in three days. I had a short, so I split it with him."
-- Slashdot signature
smime.p7s
Description: S/MIME cryptographic signature
[Prev in Thread] | Current Thread | [Next in Thread] |