Pages: [1]   Go Down
Author Topic: Will an LED blink if noone is looking?  (Read 983 times)
0 Members and 1 Guest are viewing this topic.
Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a baffling conundrum.  I've set up a breadboard with an ATtiny13A on it and successfully sent a .hex file to it through AVRdude and an Arduino-as-ISP.  The C program does nothing but set pin 5 (PORTB0) as output, set it high, wait two seconds, set it low, wait two seconds, and loop.  A long blink, basically.  To make it interesting, I'm using a bi-color LED of the 2-lead inverse parallel variety.  I set up a voltage divider between +5v and Gnd using a pair of 1K resistors.  One lead of the LED goes there, the other to pin 5 on the ATt13.  The idea, of course, is that when pin 5 is high, the LED will glow green, and when it's low, it'll glow red.

Here's the problem...  left on its own, the LED is mostly off.  It may blink erratically, or flicker as if on PWM with a very, very low duty cycle.  Mostly it just looks like it's not lit at all.  BUT, when I stick the black probe of my DMM on ground, and the red probe on pin 5, suddenly I get my green/red blinking just as expected.  Interestingly, when I remove the probes, it turns off again.  Probing again starts the cycle over, but appears to reset the AVR.  It's like the probes are allowing the AVR to come out of BOD, or serving as a reset pull-up.

Of course, there's a 10K resistor from pin 1 to +5 (reset high), Vcc to +5, Gnd to Gnd, pin 5 to the LED, LED to the center of the voltage divider.  The breadboard is being fed by an Uno attached via USB to my laptop.  I haven't tried with a wall-wart directly, so I guess that's the next step.

Anyone see anything like this before?
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1015
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post a photo of it, the schematics and the source code and a link to the led ?

At first glance it seems that the input is open. With the probes, you have a high impedance from the measured pin to ground or you introduce noise. In that case the led lights up.
At second thought, a voltage divider of 5V makes 2.5V. That voltage could be too low for the led.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1257
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Heisenberg's uncertainty principle in action?
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

whats the point of the voltage divider, and whats keeping the led's from sucking whatever they want in terms of current?
Logged


Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The voltage divider is there to provide 2.5v for the LED bias.  When pin 5 is high, the LED sees +2.5v on the AVR side, forward biasing the green LED.  When pin 5 is low, it sees -2.5v, forward biasing the red LED.  The LED is supposed to work at 2.0-2.1v typical, so that should be OK.  Here's the Digikey sales page for it:

http://www.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&lang=en&keywords=160-1037-ND&x=0&y=0&cur=USD

Here's the code.  Note, this is AVR C for use in Atmel Studio.  The intended application is simplistic enough that bringing in the whole Arduino kit doesn't make much sense for this project.  64 bytes of SRAM and all...

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <util/delay.h>

void delay_s(uint16_t seconds);
#define wdt_reset() __asm__ __volatile__ ("wdr")

int main(void)
{
// Disable interrupts and reset the WDT
cli();
wdt_reset();

// If the AVR was reset due to WDT expiration, the WDRF flag will be set.
// This must be cleared before the WDT configuration can be changed.
MCUSR &= ~(1<<WDRF);

// Enter timed WDT configuration sequence
WDTCR = ( (1<<WDCE) | (1<<WDE) );

// Enable WDT to reset the AVR after an 8-second timeout
WDTCR = 0x00;

// Turn off ADC modules to save power (they're not used)
PRR = (1<<PRADC);

// Enable global interrupts
sei();

// Turn off all internal pull-ups and enable outputs
PORTB = 0x00;
DDRB = 0x01;

    while(1)
    {
        delay_s(2);
        PORTB = 0x01;
        delay_s(2);
        PORTB = 0x00;
    }
}

// Delay for a specific number of seconds
void delay_s(uint16_t seconds) {
while (seconds > 0) {
_delay_ms(1000);
seconds--;
}
}

Here's a Fritzing snap of the breadboard layout.  Powered from the 5v/Gnd pins on an Arduino.


* schem.png (116.18 KB, 680x662 - viewed 17 times.)
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've since noticed two things:

1) Probing Gnd and pin 5 shows 0v, 4.88v in time with the 2-sec delays.  Probing pin 5 to the center tap of the divider shows -0.02v at all times... which is to say, probably near the error threshold of the meter.  No idea why that is.

2) Moving the Tiny off this breadboard (set up as an incubator solely for use with AVRdude) to the breadboard with the intended project, it behaves as expected.  Of course, its final job is not to just blink red and green.  The project board has an audio input that fires a transistor when the signal is over a threshold, pulling the INT0 pin low, triggering an interrupt, turning the LED green, and turning on a power amp.  This is naturally a much longer program.  At any rate, on a board with a half dozen op-amps, a few transistors, and a bunch of other parts, it seems to behave.  Maybe because of the multi-output transformer (-12, +12, +5) that is running that board?  Not entirely sure.

So, this is more or less solved in the immediate sense, but I still can't explain what happened.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5335
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) Probing Gnd and pin 5 shows 0v, 4.88v in time with the 2-sec delays.  Probing pin 5 to the center tap of the divider shows -0.02v at all times... which is to say, probably near the error threshold of the meter.  No idea why that is.

Maybe it would be a good idea to find out....
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds to me like a bad bread board connection that you were making good by the pushing of the probes onto it. Nothing to do with the electrical effect of the meter.
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so theres nothing from keeping the led from sucking current, possiblally (doubtfull though) resetting your IC
Logged


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A pin on an arduino will equally source or sink current. As long as you keep it to the limits of the pin then it has no untoward effect.
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, the only thing limiting the current to the LED would be the 1K resistors to the +5 and Gnd rails.  The divider creates a 2.5v tap with 1K of resistance either direction.  That sounds current-limited to me.  :-)

I'm still at a loss for why the probing caused things to change.  For that matter, even on the "actual" project breadboard where things otherwise seemed to work just fine, sometimes just touching (only) the black probe to Gnd would cause the uC to reset.  Not always, just sometimes.

I'm honestly not sure how "clean" the power is from my little 3-voltage wall-wart supply.  It appears to have its own capacitance because all the LEDs on my project fade out when it's unplugged, but for no reason in particular, I didn't put any large electrolytics on this project board like I usually do.  There are ceramic caps on the supply pins though.  I don't suspect loose connections per se, since it doesn't appear to mind being jiggled or touched.

Thanks for the brainstorming, everyone.  This one might remain a mystery though.  Well, just for fun, here's a pic of the project board.  Everybody loves gratuitous breadboard pics, right?  The Tiny is the top right IC next to the single green LED.


* bb.jpg (188.3 KB, 640x478 - viewed 28 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
sometimes just touching (only) the black probe to Gnd would cause the uC to reset.  Not always, just sometimes.
That suggest it is a mechanical problem rather than an electrical one.

Whilest I hate bread board that one is quite neat, well done.
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5335
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so theres nothing from keeping the led from sucking current, possiblally (doubtfull though) resetting your IC

Nothing ... apart from the 1K resistors.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One thing I noticed in calculating the voltage you use 5v, then you say it is powered by a 3v wallwort. What voltage are you getting on the board with the circuit set up?
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not 3V; 3 voltage outputs:  +12, -12, +5.  It used to terminate on a mini-DIN connector.  Some shears and banana plugs later, it's a breadboard supply.
Logged

Pages: [1]   Go Up
Jump to: