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

Digital I/Os during power up


  • Please log in to reply
27 replies to this topic

#1 Andrei

Andrei

    New Member

  • Members
  • Pip
  • 6 posts

Posted 29 May 2011 - 08:37 PM

Hi, I am a complete beginner and new to this forum. I have purchased a Netduino together with a relay board (not a relay shield). I have connected the GND and 5V pins on the Netduino board to the GND and VCC input of the relay board. Have connected a couple of the Digital I/Os to the input of the relays. My problem is that when I power the Netduino board, the relays get triggered immediately. It seems that as soon as the Netduino board is powered, the connected Digital I/Os signal a true. I do manage to control the relays correctly according to the C# sample app after the power up of the Netduino board. Do you have and advice how I can avoid the problem? Any help appreciated.

#2 Pete Brown

Pete Brown

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationAnne Arundel County, MD

Posted 30 May 2011 - 05:42 AM

Hi,
My problem is that when I power the Netduino board, the relays get triggered immediately.
It seems that as soon as the Netduino board is powered, the connected Digital I/Os signal a true.



I'm running into this now with a motor controller controlled via PWM. As soon as I turn the Netduino on, the motors start spinning full-speed. It takes a few seconds for them to stop. Not great for a robot :(

Chris, is there a firmware config option or something to handle this? It happens before our code gets to run.


Pete
Pete Brown - http://10rem.net (NETMF, C++, Windows, C64, and general geekery) Twitter: @pete_brown
I work for Microsoft. Opinions expressed here are my own and do not necessarily reflect those of my employer,our partners or customers.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 30 May 2011 - 05:55 AM

My problem is that when I power the Netduino board, the relays get triggered immediately.

You'd need to connect so called 'pull-down' resistor between the Netduino pin and ground, which holds the signal at logic zero during the startup. 10 kΩ works fine.

#4 Pete Brown

Pete Brown

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationAnne Arundel County, MD

Posted 30 May 2011 - 06:26 AM

You'd need to connect so called 'pull-down' resistor between the Netduino pin and ground, which holds the signal at logic zero during the startup. 10 kΩ works fine.



Thanks Chris. Looks like I'm going to have to put a small board on this guy no matter what :P

Pete
Pete Brown - http://10rem.net (NETMF, C++, Windows, C64, and general geekery) Twitter: @pete_brown
I work for Microsoft. Opinions expressed here are my own and do not necessarily reflect those of my employer,our partners or customers.

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 30 May 2011 - 06:56 AM

Every MCU powers up with all their I/Os configured as inputs, because it would be dangerous to set them as outputs for defaults. Consider a circuit where an I/O must be an input and a switch might be closed to the ground. If the pin starts as an output (high), the MCU could be damaged (or at least stressed a lot). I agree with CW2 about the pull-up or -down. Cheers
Biggest fault of Netduino? It runs by electricity.

#6 Andrei

Andrei

    New Member

  • Members
  • Pip
  • 6 posts

Posted 30 May 2011 - 07:49 AM

Thanks a lot for the information. Very helpful indeed. Regarding the solution given by CW2, can this solution form part of the relay board? i.e. are there any relay boards which handle this situation without having myself to add the resistor? As a possible solution, what do you think of a software solution: the cpu power change event is trapped and the IOs are set to off. Possible?

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 May 2011 - 07:51 AM

I have this one myself: http://wiki.netduino...ay-Shields.ashx I'll check if it powers up tonight, but I haven't noticed a power up at boot with it, so I think it handles the situation properly. But I'll test it tonight, just to be sure.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 30 May 2011 - 08:50 AM

As a possible solution, what do you think of a software solution: the cpu power change event is trapped and the IOs are set to off. Possible?

Unfortunately, it cannot be done in software - as Mario pointed out, the I/O pins are high (configured as inputs) at reset and there will be always some delay before the software starts running. For example, it takes some time for the oscillator to stabilize, hardware modules need to be initialized etc. Additionally, in case of Netduino there is (2s ?) timeout in the bootloader after which it hands over the control to TinyCLR that actually runs the user application, where you can manipulate I/O pin state.

It is possible to modify the firmware to change pin state during the startup (i.e. set it to logic low), but as Mario already mentioned, there are reasons why not to do that and there will still be a significant delay before such code is run on .NET Micro Framework device (even on 'bare-metal' microcontroller we are talking about hundreds of microseconds initialization time, which is probably long enough for the external board to perform some action, like switching the relay/motor on). The pull-down (resp. pull-up) resistor is the easiest solution - they are used pretty often, so grab a dozen of these (10kΩ, 4k7), they will surely come in handy for other projects...

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 30 May 2011 - 11:55 AM

To complete the very well explained description of CW2, I'd add that at NO time, for NO reason an input should be left open (i.e. floating). It means that your relay shield SHOULD provide a "safe" pull-up/down to avoid any trouble. I cannot understand manufacturers who are not providing 1 cent (maybe less) resistor, where could be a great benefit for the final user. But...money are money. Just for your info, consider that the original CMOS ICs (late '70) SHOULD NOT have any floating input, otherwise the internal circuit should turn in a instable (and dangerous) state of oscillation and overheating. Now the ICs are much better, but bear in mind anyway. Cheers
Biggest fault of Netduino? It runs by electricity.

#10 Andrei

Andrei

    New Member

  • Members
  • Pip
  • 6 posts

Posted 30 May 2011 - 02:30 PM

This is the relay board which I purchased:
http://cgi.ebay.com/...V-/400209006822

What do you think?
Was it a bad purchase?

Thank you all for the info. Really appreciate it.

#11 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 May 2011 - 02:42 PM

It's a very nice board! But you should indeed use pulldowns on the Netduinos I/O-ports, just to be sure. You could place them on the relay board if you like, as long as the ports are connected to the ground with a 10k resistor.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#12 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 30 May 2011 - 03:02 PM

Andrei, the circuit is OK. The pull-down resistors are *already* present on the relay board, so don't add any further resistor. I think it's a good board, no problem at all. According to the specs, the MCU starts by settings any I/O as an input, and enabling the internal pull-up resistor. That is a very good move from the MCU viewpoint, because it grants a pull-up on an inputs even the external circuit forget to add it. However that is a bad point for you <_< The MCU's internal pull-up is strong enough to drive the relay transistor, thus the relay will turn on. Assuming there's no way to switch an I/O to act as output within a reasonable short time (millisecs), this behavior is very hard to surround. Please, let me think a bit on the problem. Cheers
Biggest fault of Netduino? It runs by electricity.

#13 Pete Brown

Pete Brown

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationAnne Arundel County, MD

Posted 31 May 2011 - 03:38 AM

So, I checked out the schematic of my motor controllers: they already have 100k pull-down resistors on all the digital inputs. (sorry to thread-hijack, but it's the same issue) I'm fairly new to electronics, but I fail to see how adding a 10k pull-down to each digital output on the netduino side is going to fix this problem. As I understand it, the Arduino doesn't run into this with these motor controllers. Any idea what about the Arduino makes that possible? Pete
Pete Brown - http://10rem.net (NETMF, C++, Windows, C64, and general geekery) Twitter: @pete_brown
I work for Microsoft. Opinions expressed here are my own and do not necessarily reflect those of my employer,our partners or customers.

#14 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 May 2011 - 04:16 AM

@Andrei:
I didn't find anything about the value of the internal MCU pull-ups. I guess their value should be around 10-20K Ohms.
To solve a similar problem I'd see three possibilities:
  • (the WORST) add a "stronger" pull-down to any output, so that the internal pull-up won't be enough to feed a decent voltage for the transistor. Let's say a 1K Ohms pull-down, it should keep the power-up output voltage below 0.5V, i.e. less that the transistor threshold (over 1.5V). IMHO this is the worst solution, because makes flowing a lot of useless current (from +3.3V to ground).
  • Add an inverter (e.g. 74HC04) to any Netduino output, then drive the transistor using a negative logic.
  • The most elegant solution, from my viewpoint, is to use one or two shift registers (74HC595) as Stefan does. It has no problem at power-up, it saves a lot of I/Os and it is much faster than a direct I/O driving.
@Pete:
I didn't check, but Arduino could have two advantages over the Netduino.
Firstly, the Arduino MCU could not have the same behavior of the Netduino's one. Maybe on power-up there's no pull-up enabled, so the problem is completely inexistent.
Secondly, the Arduino firmware could take a lot less than the Netduino's. So, even having the same behavior, the transition time would be too short for making any relay active (e.g. some millisecs).

Cheers
Biggest fault of Netduino? It runs by electricity.

#15 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 31 May 2011 - 04:50 AM

Hi Pete,

As I understand it, the Arduino doesn't run into this with these motor controllers. Any idea what about the Arduino makes that possible?

The Arduino Uno uses an ATMEGA328 (8-bit AVR) microcontroller. This microcontroller tri-states all GPIOs at startup, with no internal pull-ups. [Tri-state/Hi-Z = "open circuit, disconnected pin"]

http://www.atmel.com...nts/doc8161.pdf

Section 13.2.1 Configuring the Pin (p.76)
"The port pins are tri-stated when reset condition becomes active, even if no clocks are running."

Section 13.2.6 (p.80)
"In this case, the pull-up will be disabled during reset."

The Netduino uses a SAM7X512 (32-bit ARM) microcontroller. This microcontroller configures all GPIOs as inputs with pull-ups enabled at startup. These weak pull-ups may register as "positive voltage" to external components.

http://www.atmel.com...nts/doc6120.pdf

Section 27.4.1 Pull-up Resistor Control (p.233)
"After reset, all of the pull-ups are enabled"

Table 27-2 PIO Register Mapping (p.238)
Output Status Register at Reset = 0x00000000 (all pins in pure input mode)

We could set the PIO_PUDR registers to 0x00000000 immediately at boot, to disable all pull-up resistors. But that would still turn them on very briefly--and would afterwards leave the inputs floating. We could also set the PIO_MDER registers to 0xFFFFFFFF to enable all pins in multi-drive mode (open drain)...but the pullups would still be enabled during reset.

Chris

#16 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 31 May 2011 - 05:01 AM

Hi Mario,

I didn't find anything about the value of the internal MCU pull-ups. I guess their value should be around 10-20K Ohms.

The SAM7X datasheet (p.610) lists the pull-up resistor current values as:
Netduino analog pins 0-3: 20.6mA typical
Netduino--all other pins: 321mA typical

If Ohm's law serves me right (R = V/I in this case), this gives us rough pullup resistor values of:
Netduino analog pins 0-3: ~16020 ohms
Netduino--all other pins: ~1025 ohms

If you want to use a pull-down resistor to offset the internal pull-ups during reset and with a maximum current of 600mA on the inputs...I'd use a pull-down resistor of 500 ohm or less on the digital pins (and pins A4/A5) and a pull-down resistor of 5 kilohm or less on the analog pins A0-A3.

Chris

#17 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 May 2011 - 05:29 AM

I'd use a pull-down resistor of 500 ohm or less on the digital pins (and pins A4/A5) and a pull-down resistor of 5 kilohm or less on the analog pins A0-A3.

Ya...
I confirm the pull-down solution is even worser than the worst!
Thank you, Chris.
Cheers

EDIT: I checked the specs because your values sound too odds.
The currents are in MICRO-amperès, not milliamps.
The pullup resistors are scaled by 10: about 160K and about 10K.

I think would be an hard task make flowing 600mA through an I/O without blowing it!
Ciao
Biggest fault of Netduino? It runs by electricity.

#18 georgejh

georgejh

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationGlasgow, UK

Posted 31 May 2011 - 12:15 PM

I have tried the pull-down resistors but didn't like the idea of draining so much energy. Using 500Oms resistor will drain 6.6mA per pin!
With 8mA per pin (excluding 16mA for 2,3,7) this is pretty close to the limit.

To solve this problem I used different approach (which for me is more flexible):
I used one of the Netduino Digital I/O to control a wee transistor-relay switch but used PNP transistor so on start up relay is off.
Then later in code simply setting the port down opens the transistor and relay goes on. Rest of the schematics gets power from the relay's controlled circuit.
This is flexible also gives me power at any time to switch ON/OFF the power to the circuitry from code.
This is next thing I am writing down into this tutorial. I also will describe using thyristor instead of relay and also possibility to use single power PNP transistor for cases
you power schematics from Netduino's +5V. In this case you should not consume more than 200mA which makes any >1W transistor suitable.
Later in this tutorial I also will describe how one can use FET/MOSFET, DIOD or Transistor NAND as well as NAND TTL IC to achieve same.

#19 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 31 May 2011 - 12:33 PM

I have tried the pull-down resistors but didn't like the idea of draining so much energy. Using 500Oms resistor will drain 6.6mA per pin!
With 8mA per pin (excluding 16mA for 2,3,7) this is pretty close to the limit.

I agree at all for the waste, especially where is the need of battery-powered devices.

I used one of the Netduino Digital I/O to control a wee transistor-relay switch but used PNP transistor so on start up relay is off.

I agree with you again, but:
  • most of the readers cannot figure out your idea, so attach any picture describing the circuit (without any formula);
  • for a single output, I would have done as you say, but for 16 relays maybe is compact, simpler and cheaper having a couple of ICs (e.g. 74HC244).
Anyway, any good tutorial on how to solve a similar problem with transistor or mosfet is surely welcome.
Thank you very much for your post.
Cheers
Biggest fault of Netduino? It runs by electricity.

#20 georgejh

georgejh

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts
  • LocationGlasgow, UK

Posted 31 May 2011 - 12:41 PM

I agree with you again, but:

  • most of the readers cannot figure out your idea, so attach any picture describing the circuit (without any formula);


I mentioned that I am currently writing exactly this part of the tutorial. I tend to release chapter per week so expect this to be public next week :)
Meanwhile, following you advice, I will post an schematics image later today so people can get impression.

for a single output, I would have done as you say, but for 16 relays maybe is compact, simpler and cheaper having a couple of ICs (e.g. 74HC244).

I am not understanding exactly what you mean? I am using this schema to control the general power flow to the rest of the schematics.
This could be 1 as well as 16 other relays schemes. May be picture will clarify what I am doing :)


Schematics attached.
From the relay controlled circuit you can power as many other LED switches or any other devices.
Keep in mind 800mA total limit that you can get from Netduino's 5VDC. In fact I use a resettable fuse, connected between +5V pin and relay switch, to prevent any damage to N+). If you need more current use external power device. If you need more voltage you have to recalculate R1 and R2 (calculations example will be provided in the tutorial). As I mentioned before there are other possibilities to make this schema more elegant with replacing the relay or using different switching techniques. Again, those will be illustrated in the tutorial.

To switch "power on" just declare
var powerSwitch = new OutputPort(Pins.GPIO_PIN_D13, false);

Then you can:
powerSwitch.Write(true) // OFF
powerSwitch.Write(false) // ON

You may think you can use PNP transistor to power the LED directly, That's true. Only "uncomfortable" thing is you have to set the port to false to turn the LED On. This is small issue but for somebody that wants to keep things straight this could be annoying, so I came with this solution. I also like it as it adds a bit more control.

Attached Files






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.