Pages: [1] 2   Go Down
Author Topic: Pwm output is high on bootup?  (Read 3281 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 596
Posts: 33283
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 596
Posts: 33283
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

PLEASE do not cross-post.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 11, 2011, 12:12:57 pm by retrolefty » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

That rules out the bootloader.

How does this behave...

Code:
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);
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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



Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes the result is the same.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int Pwm_output_pin_11 = 11;

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

void loop()
{
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12737
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino IDE version are you using?
Logged

Pages: [1] 2   Go Up
Jump to: