Pwm output is high on bootup?

Hello all,
For testing purpose I have here a very simple setup using the Duemilanove.
Just a 10k potentiometer on the Analog Pin 0.
An scope connected to pwm out pin 11.

Now the code is just your basic analogRead from the potentiometer and digitalWrite to pwm pin 11.
This works obviously great. I have full pwm control on pin 11, no problems there.

BUT,
I have noticed with the scope on pin 11. That that pin goes high for half a second orso when I boot up the Arduino. Meaning when I plug in the usb cable. So it very shortly hoes high, displaying a pwm signal. Then goes low and after a second or so comes up high again and the board is ready to use. So it seems, while the Arduino is booting just after you plug in the power it very briefly sets the pwm high.

This is not wanted since further on I want to control a full bridge motor controller with the Arduino. And I can not have unwanted high signals on bootup.

So is there a way to keep all pins absolutely low until the Arduino is fully booted?

Thanks!
Kind regards,
Steven

This happens because initially the pins default to being inputs and they float high. You can stop this by simply putting a 10K pull down resistor on each output. That is a resistor connected between the output and ground.

1 Like

Hi and thanks for the reply.
Yes I forgot to mention that, but indeed I am using pull down resistors as well.

The brief signal I'm seeing during the Arduino boot sequence is a 5v pwm signal.
It only seems to happen on the pwm pins. I see no such thing happening on the other 'normal' pins.

Thanks!

That is odd, do you see this if you don't initialises the the pins on start up.
Maybe you need to set them to zero before you define them as inputs in the start up function.

How long ago did you get the Arduino? Does it have Optiboot installed?

PLEASE do not cross-post.

Hello all,
Very sorry for the double post. I removed the other.

Here is some additional info:

The circuit:

And here is a video:
http://home.planet.nl/~sintt000/Arduino.wmv

You can see that after the usb cable is plugged in you see the pwm signal very briefly, then it goes away and after a while the booting is done and the board is ready to use.

But this short pwm output during booting is not wanted when driving H bridges and such.

The Arduino board was bought about 4 months ago.

The code:
int Pwm_output_pin_11 = 11;
int Potmeter_pin = 0;
int Potmeter_value = 0;
void setup()
{

  • pinMode(Pwm_output_pin_11, OUTPUT);*
    }
    void loop()
    {
  • Potmeter_value = analogRead(Potmeter_pin);*
  • analogWrite(Pwm_output_pin_11, Potmeter_value / 4);*
    }

A quick experiment. Load the IDE example blink program into the arduino and then disconnect and reconnect the USB cable and see if your scope still shows the pin #11 PWM signal or not during the bootloader initialization.

Lefty

Hi Lefty,
Thanks for the suggestion. I tried that and no, pin #11 stays low on startup, but in the code it is not initialized either.
But pin #13 is initialized in the code, so I tried that one next. And yes during boot-up that one also goes though some high cycles before normal operation is started.

Any idea?
Anyone else here with a scope who can test this?

Many thanks!
Kind regards,
Steven

I tried that and no, pin #11 stays low on startup

That rules out the bootloader.

How does this behave...

int Pwm_output_pin_11 = 11;
int Potmeter_pin = 0;
int Potmeter_value = 0;

void setup()
{
  pinMode(Pwm_output_pin_11, OUTPUT);
  Potmeter_value = analogRead(Potmeter_pin);
  delay( 50 );
  Potmeter_value = analogRead(Potmeter_pin);
  delay( 50 );
  Potmeter_value = analogRead(Potmeter_pin);
  delay( 50 );
}

void loop()
{
  Potmeter_value = analogRead(Potmeter_pin);
  analogWrite(Pwm_output_pin_11, Potmeter_value / 4);
}

Hi Coding Badly,
Thanks for the code.
I tried it and here are the results:
home.planet.nl/~sintt000/Arduino2.wmv

The video starts the moment I plug in the usb cable. Almost directly a high output, then a little while nothing, then the board is ready to go.

Thanks
Kind regards,
Steven

Is the glitch also present on digital pin 3 (PD3/OC2B)?

Yes the result is the same.

I hate to continue sending you on "little errands" but it will help to definitively isolate the offending line(s) of code.

Is there a glitch present on digital pin 5 (PD5/OC0B)?

Is there a glitch present on digital pin 6 (PD6/OC1B)?

Is there a glitch present on digital pin 9 (PB1/OC1A)?

Is there a glitch present on digital pin 10 (PB2/OC1B)?

Which Arduino IDE version are you using?

Is the second PWM output from you adjusting the potentiometer?

How does this behave...

int Pwm_output_pin_11 = 11;

void setup()
{
  pinMode(Pwm_output_pin_11, OUTPUT);
  analogWrite(Pwm_output_pin_11, 128);
}

void loop()
{
}

Hi Coding Badly,
Thanks for the input I appreciate it!
I have tried pin 5, 6, 9 and 10 just now and it's the same problem for each pin.
Then I tried your code on each of these pins as well, and indeed it's the same situation. The output goes high for a short moment, then low and after a small pause it is up again and running.

Yes the moving pwm in the video is me adjusting the potmeter.

Found something else...
When you power the Arduino from a 9volt battery the problem is gone. It also seems like it boots multiple times faster that way. You plug in the power and a second later the thing is running, the short 'high' pwm problem is gone when run from battery.

So maybe the usb data connection initialization is causing the problem as well as the way slower boot time?
I wonder how to solve this usb situation...

Booting powered from 9v battery = 2 seconds. (no brief output going high problems during boot)
Booting from plugging in the usb cable = 7 seconds. (brief output going high problems during boot)

Thanks,
Steven

Which Arduino IDE version are you using?

Whoops sorry about that,
Version 0021

This is probably an Uno/Optiboot 'feature' - optiboot does less initialization, probably not reseting pins to input mode. Power-up reset does this but subsequent resets don't?

probably not reseting pins to input mode.

No that happens automatically as a result of the reset pin being hit. It is a hardware thing.

Grumpy_Mike:

probably not reseting pins to input mode.

No that happens automatically as a result of the reset pin being hit. It is a hardware thing.

I'm not so sure, the Uno/Optiboot 'features' and the new 8u2 usb converter chip sure made for a rather rocky introduction to the latest board offerings from Arduino, with more bugs then any other new board offerings I can recall. And also requiring two IDE releases in very short order.

In hind site they would probably been better off just introducing the 8u2 feature and put off changing from their more proven bootloader code. That or they need a better beta process before rushing new boards to market.

My money 2 cents is that this symptom uncovered in this posting will be at least related to the new bootloader if not directly caused by it. No proof, just shooting from the hip. :wink:

nali2001:
Whoops sorry about that,

No problem.

Version 0021

I cannot find anything in 0021 that would cause this sort of problem. I cannot find anything going from 0021 to 0022 that would effect PWM.

But, just in case I missed something, I suggest upgrading to 0022 and rerunning the tests.