Go Down

Topic: Output high at bootup (need to stay low) Solved (Read 739 times) previous topic - next topic

backbone

Dec 01, 2012, 12:44 pm Last Edit: Dec 01, 2012, 03:58 pm by backbone Reason: 1
When I supply power at the MEGA it sets two outputs HIGH which start a motor to turn for a scond or so.

When I power up the LED 13 blinks two times.
Pin is set as output PWM and drive a FET to drive an single motor.
As soon as I supply the power the motor starts to turn until the second blink of LED13 is OFF.

Is there a way during boot-power up to keep the output low?

I googled and also used the search function here but no useable info.

Paco
Never to old to learn and I learn every day

tuxduino

Please post your code, using code tags button (#).

backbone

Sorry the full code is more then 9500 characters! So I can not put it between code tags! :-(

Paco
Never to old to learn and I learn every day

backbone

Never to old to learn and I learn every day

fungus


When I supply power at the MEGA it sets two outputs HIGH which start a motor to turn for a scond or so.


They're probably not high, just floating.

Try connecting them to ground via a 4.7k resistor (or something in that range).

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

DeepZ

Do you use pull-down resistors on those 2 pins?

When the MCU resets, all i/o pins go into Tri-State (High Impedance) and then default to input pins (Also high input resistance) until your sketch defines them as output pins.

Using a resistor (one for each pin, 10K/47K or so) to ground will make sure the pin stays LOW unless explicitly driven HIGH by the output.

Hope this helps,
Guido

tuxduino

Code: [Select]
void setup()
{
  Serial.begin(9600);                       // Output to serial writing or BT

  pinMode(led7Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led8Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led12Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led13Pin, OUTPUT);                // initialize the led as a output control pin //
  //pinMode(11,INPUT); //for calibration push button
  //digitalWrite(11, HIGH);    // enable the 20k internal pullup for MEGA board
  digitalWrite((54), HIGH);  // enable the 20k internal pullup for MEGA board

// lots of code


I'd try to drive the pins to a known state at the beginning of setup().

backbone

I first pulled down the outputs 9 and 10 to GND with 13K7 resistor.
Same problem.
Then added the code that controls the outputs below the pinmode declarations
Same problem.
Then I moved it up directly under serial begin.
Problem solved.

Thanks for your cooperation. I hope others benefit from it too.

Code: [Select]
void setup()
{
  Serial.begin(9600);                       // Output to serial writing or BT

  speedfinalValue =  0; //this value determens if the motor is running. if value = 0 then PWM signal = 0
  brakeNValue = 0; //this value determens if the motor is braked. if value = 0 then PWNM signal = 0
 
  pinMode(led7Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led8Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led12Pin, OUTPUT);                // initialize the led as a output control pin //
  pinMode(led13Pin, OUTPUT);                // initialize the led as a output control pin //
  //pinMode(11,INPUT); //for calibration push button
  //digitalWrite(11, HIGH);    // enable the 20k internal pullup for MEGA board
  digitalWrite((54), HIGH);  // enable the 20k internal pullup for MEGA board
Never to old to learn and I learn every day

Graynomad

Quote
I'd try to drive the pins to a known state at the beginning of setup().

They are still floating for 1-2 seconds as the chip starts up and (by far the longest) the bootloader screws around.

Pull down resistors are the only answer I think.

EDIT: I see you last post, don't know how that's worked but if it has well and good.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up