Output high at bootup (need to stay low) Solved

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

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

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

Paco

I zip the .ino

slotracecontroller_306_ino.zip (6.4 KB)

backbone:
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).

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

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().

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.

 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

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