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