How to control outputport after power on

I have a controlbox using a G120. I have 2 outputs to control relays. They are connected to P1_15 and P1_9. My problem is that the processor is 6 s to reach main, where I set the port to output low. In these 6s one output is enabled and my relay is activated. How can I prevent the one relay being activated after power on?
Br. Jacob

You may want to post your code. If its taking 6s to get into your main then I suspect you need to restructure ProgramStarted().

Ok, something new to me, I do not have a ProgramStarted
In fact I have a lot of different projects, but they are all cloned from the same first project I made years ago. An they have this structure

namespace Application
public class Program
public static void Main()
OutputPort op = new OutputPort(G120.P1_15, false);

Do you have an example or reference to code or documentation describing the start up procedure in NETMF at G120

You may need to add pull down resistors, so the pins would be low before controller starts.

1 Like

Yes pull down resistors is a solution, but I was hoping to find a sw solution, the pcb is finished and in production :frowning:

Sorry, I assumed that since you posted in the .NET Gadgeteer forum that you were using the Gadgeteer framework. You’re using native NETMF. Still, if you can post more of your code it would be helpful. If you’re initializing your pins first thing in Main() there’s something else going on if its taking 6 seconds for it to take effect.

Sorry, this is actually a hardware problem. You will need to add pull-downs. All you can do is shorten the time when the IO pin floats or is potentially in the wrong state, where what you need to do is to have it in a known “failsafe” state. Pulldowns are the only viable solution; anything else is a workaround that can still bite you in the butt.

I will add pull downs.
It really takes 6s from power on, to my first line of code in main is called. My hex file is 850KB. But I will still have a problem if it is only 1s :frowning:

I’d still wonder why 6s though. Seems excessive, but you are right to add pulldowns since that’s the only thing that will allow the state to be controlled before any control is exerted.

Just a quick addition to the pull down resistors for future projects not all pins are the same. For example on the G400 there are several pins that are used for other functions that can go hi on startup, regardless of the pull down resistor, so you need to ensure that your not using any of these pins.

(For the G400)
Port 18, Pin6 goes hi for about 2 seconds, and Pin4 goes hi for about 1 second, after a 1 second delay
Port 1, Pin2 flashes for milliseconds
Port 2, Pin4 goes hi for about 2 seconds. (And yes, I know its not labeled for use with the load module, but ran out of ports).

i had asked this type of question to gus in the past. there is no way to control the state of the pins at startup. No amount of pull up or down resistors is going to accomplish this.

I think you’re wrong - but only if you’re trying to make sweeping statements.

Pins that are held in Hi-Z by the processor at startup, and that aren’t influenced in the firmware, can be controlled by pull-up/down. If the processor doesn’t start them in Hi-Z, or the firmware adjusts their state, then you’re correct, external pull-up/down can’t be influenced.

so gus’ distinction was between power on vs startup. it is possible to know what the state is at power on, but since a device can be restarted by watchdog e.g. it is impossible to know the pin state at start up.

Agree. With few exceptions,most processors put the GPIO lines in either HI-Z or input state. Careful reading of the datasheet will reveal the state and then your design should be based on this information. To simply choose a GPIO pin without reference to the datasheet for a critical output that you need to know the state during power up would be a bad design decision. :slight_smile:

In almost all cases, along with careful IO choice, a pull up or down must be considered as part of your design if you need the port in a known state at power up.

1 Like

Reading the datasheet for the processor for each state will allow you to determine what state the IO will be in. You need then to choose carefully those IO you need in a predetermined state. :slight_smile:

1 Like