Go Down

Topic: Pwm output is high on bootup? (Read 4247 times) previous topic - next topic

nali2001

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

Grumpy_Mike

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.

nali2001

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!

Grumpy_Mike

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.

Coding Badly

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

PLEASE do not cross-post.

nali2001

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:
[font=Verdana]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);
}
[/font]

retrolefty

#6
Feb 11, 2011, 06:11 pm Last Edit: Feb 11, 2011, 06:12 pm by retrolefty Reason: 1
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

nali2001

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

Coding Badly

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


That rules out the bootloader.

How does this behave...

Code: [Select]
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);
}

nali2001

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




Coding Badly

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

nali2001


Coding Badly

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

Code: [Select]
int Pwm_output_pin_11 = 11;

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

void loop()
{
}

nali2001

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


Coding Badly

Which Arduino IDE version are you using?

Go Up