Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

IO Output during Reset/Boot


  • Please log in to reply
4 replies to this topic

#1 Carsten Dressler

Carsten Dressler

    Member

  • Members
  • PipPip
  • 20 posts

Posted 24 August 2012 - 11:33 PM

I've connected 6 LED's to the Netduino and loop through them each turning them on and then back off. It works great, however, I noticed when I hit the reset button ALL my led's stay on briefly before my loop starts again. How can I prevent this from happening? I need them to stay off until I do led.Write(true). Thanks for the help. Here is the code: public static void Main() { OutputPort led0 = new OutputPort(Pins.GPIO_PIN_D0, false); OutputPort led1 = new OutputPort(Pins.GPIO_PIN_D1, false); OutputPort led2 = new OutputPort(Pins.GPIO_PIN_D2, false); OutputPort led3 = new OutputPort(Pins.GPIO_PIN_D3, false); OutputPort led4 = new OutputPort(Pins.GPIO_PIN_D4, false); OutputPort led5 = new OutputPort(Pins.GPIO_PIN_D5, false); OutputPort led6 = new OutputPort(Pins.GPIO_PIN_D6, false); OutputPort led7 = new OutputPort(Pins.GPIO_PIN_D7, false); int delay = 25; // write your code here while (true) { led0.Write(true); Thread.Sleep(delay); led0.Write(false); Thread.Sleep(delay); led1.Write(true); Thread.Sleep(delay); led1.Write(false); Thread.Sleep(delay); led2.Write(true); Thread.Sleep(delay); led2.Write(false); Thread.Sleep(delay); led3.Write(true); Thread.Sleep(delay); led3.Write(false); Thread.Sleep(delay); led4.Write(true); Thread.Sleep(delay); led4.Write(false); Thread.Sleep(delay); led5.Write(true); Thread.Sleep(delay); led5.Write(false); Thread.Sleep(delay); led6.Write(true); Thread.Sleep(delay); led6.Write(false); Thread.Sleep(delay); led7.Write(true); Thread.Sleep(delay); led7.Write(false); Thread.Sleep(delay); } }

#2 ErikN

ErikN

    Advanced Member

  • Members
  • PipPipPip
  • 119 posts
  • LocationNew York, NY

Posted 25 August 2012 - 02:27 AM

The pins are pulled high during reset. This is done before your code starts executing so there's no way to prevent this from happening.

Most people will tell you the same thing - don't drive the LEDs directly from your board! You should power the LED directly and control its state with an NPN transistor to ground. This would keep your LEDs off during boot-up, wouldn't power them from your board directly but still give you control to turn them on and off. The downside is the extra hardware required (1 transistor per output port you're controlling.)


Seems I'm rarely correct about the right transistors to use.

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 25 August 2012 - 04:40 AM

Carsten, this is one of the most FAQ. During the bootstrap, an I/O has not still any user initialization (I mean your code), so it can't know whether it's actually an input or an output. Well, this decision must be chosen by the MCU (microcontroller unit) manufacturers (Atmel). Now, if they chosen for the pin to be an output, that might collide with an external hardware. You know, an output can be either low or high, and that might not match the actual driving. For instance, suppose having some logic gate driving that pin: if the gate's output is different than the MCU's output level, then it yields to a collision with a lot of current flowing through the pins. So, they correctly chosen for the I/O to be an input, but...how they could be guaranteed about the pin not left floating? You know, an input should *never* left floating: either you drive it explicitly via some logic gate, or you pull-up/down weakly via a resistor. The problem is that the Atmel's engineers couldn't rely on extra tasks performed by the users, because they may forget them. So, the very best solution is place any of the I/O as an input, and enabling an internal pull-up resistor to guarantee a stable and certain logic level during the bootstrap. Now, your problem. Erik correctly pointed out to avoid directly driving leds with the board, but it's rather a current limitation problem. You can do it, until you keep the current flowing below the max recommended, which is 8mA if I remember well. Modern leds light brightly with as low as 8 mA, and just to keep the thing safe, you could get the current up to 5 mA. How to solve the startup problem? Simply thinking "different"! Connect each led from the I/O pin to the +3.3V, or -better- to the +5V supply, respecting the polarity of course. Then use an inverted logic for the activation: when the output goes low, the led will lit because there is voltage drop across it. Instead, when the output is high the led can't lit because there's no drop. In this way, during the startup the leds will not lit because there's no drop across them. Each led will take up to 5 mA, and you have 8 leds in total. If you connect the led to +3.3V, then you load a max of 40 mA the supply, over the natural consumption. It's not too much: maybe you'll feel the regulator a little warmer, but of sure won't damage it. Also consider that in the code above you get lit one led at once, so the actual current is just 5 mA: safety all all. How to limit the current? You must insert a resistor in series to each led: you really can't connect the leds without resistor. That will damage (or better will stress a lot) the board, as long the regulators. So, let's apply the Ohm's law: - a red led drops about 1.5V when is lit; - the total voltage drop is 3.3V, that is the power supply minus the voltage at the output when it's pulled low; - you want a current of 5 mA flowing; R = (3.3 - 1.5) / 5m = 360 Ohms Well, you can use standard 330 Ohms resistor without any worry. The above is an approximate computation, yielding a rough idea about how to run the board within safety bounds. Finally, if you'd like to get the led bright much more, the transistor-way is one of the possible solutions. Again, my suggestion is keeping the reversed logic described above, then use a PNP transistor for each led as current amplifier. The NPN suggested by Erik is not a good choice because won't solve the startup problem. Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#4 Carsten Dressler

Carsten Dressler

    Member

  • Members
  • PipPip
  • 20 posts

Posted 26 August 2012 - 05:00 PM

Thanks for the replies. Especially the very detailed answer from Mario. I will actually be controlling Optoisolator that controls another circuit (ceiling fan controller). The LED's is just for a test to see if all the IO's are working. Then I discovered when I boot the device that all the LED's are on which would cause the Optoisolator to be triggered as well. Thanks for the feedback guys! Carsten

#5 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 26 August 2012 - 05:55 PM

Hi Carsten,

I actually use opto-isolators to overcome the problem of the outputs being pulled high.
I made a wiki page detailing what I found.

Hopefully it will be useful. - Paul




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.