NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » Adding output connections seems to reset (or something) the MCU

December 27, 2009
by promethean
promethean's Avatar

Hey folks,

So I added some code to the LCD version of the sound_meter program to flash an LED when the sound hits a certain point. In this case, a difference of 20. Everything runs as normal while the sound stays below that level, but once it hits that level and the LED flashes, the system seems to go into an infinite loop of flashing with the LCD flaking out too. Here's the code I added to the do_sound_meter() function:

DDRC |= (1<<PC4); //set pc4 of ddrc as outpout
PORTC &= ~(1<<PC4); //make sure PC4 is off for the first run

if (diff > 20){

// turn on motor
PORTC |= (1<<PC4);

//delay for 500 ms to let motor stay on
delay_ms(100);
PORTC &= ~(1<<PC4);
diff = 0;
}

I tried on PORTB PB1 also, just in case there was a conflicting alternate use for the PC4 pin, with no luck. Any ideas?

December 27, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi promethean,

I think the problem here might be that the LED is drawing too much current and causing your MCU to reset. Although running an LED without a current limiting resistor works, it uses alot of current in this situation without pulse width modulation. An easy way to test this is to take out the LED and see if your code still behaves oddly when the level goes above 20. If that is the problem putting a 100ohm resistor in series with the LED should limit the current enough to not make it reset. Using 330ohms should give you a bright enough LED and still not burn a lot of current. There are several discussions about this on our our forums, here is a particularly good one. Let us know if that fixes it.

Humberto

December 28, 2009
by promethean
promethean's Avatar

Hmm, still some problems, but progress too-- I put a 330Ohm res in, and things are steadier now. The LCD dims a little, but nothing seems to reset, although this still puts the circuit into an endless loop, since after the first ADC reading over the programmed diff threshold (20, in my test code) the value of diff never drops below 60 again. This doesn't happen when the LED is removed. Is this noise in the circuit generated by the LED lighting? A still-significant current drop in the rest of the circuit, such that the Mic & transistor amp are behaving differently when there's a fluctuation?

December 31, 2009
by promethean
promethean's Avatar

So.... any ideas from support on why a blinking LED w/ 330 resistor would artificially cause the noise level read by the ADC to rise to 60?

December 31, 2009
by Rick_S
Rick_S's Avatar

What are you using as a power source for your project? Are you using the 9V battery through the regulator or are you using another power source?

The reason I am asking is that I could see this circuit drawing enough power to pull the battery down quickly especially if you are using the backlight of the LCD.

Rick

December 31, 2009
by promethean
promethean's Avatar

Yep, just the 9V through the regulator. No back-light on the LCD though.

Post a Reply

Please log in to post a reply.

Did you know that you can make a spooky Halloween Jack-O-Lantern with a microcontroller? Learn more...