Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: nali2001 on Feb 10, 2011, 12:47 pm

Title: Pwm output is high on bootup?
Post by: nali2001 on Feb 10, 2011, 12:47 pm
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
Title: Re: Pwm output is high on bootup?
Post by: Grumpy_Mike on Feb 10, 2011, 02:18 pm
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.
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 10, 2011, 02:36 pm
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!
Title: Re: Pwm output is high on bootup?
Post by: Grumpy_Mike on Feb 10, 2011, 02:41 pm
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.
Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 10, 2011, 08:45 pm
How long ago did you get the Arduino?  Does it have Optiboot installed?

PLEASE do not cross-post.
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 11, 2011, 11:10 am
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]
Title: Re: Pwm output is high on bootup?
Post by: retrolefty on Feb 11, 2011, 06:11 pm
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
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 14, 2011, 09:37 am
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
Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 14, 2011, 09:43 am
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);
}
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 14, 2011, 11:45 am
Hi Coding Badly,
Thanks for the code.
I tried it and here are the results:
home.planet.nl/~sintt000/Arduino2.wmv (http://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



Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 15, 2011, 01:06 am
Is the glitch also present on digital pin 3 (PD3/OC2B)?
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 15, 2011, 11:42 am
Yes the result is the same.
Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 15, 2011, 08:06 pm
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()
{
}
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 16, 2011, 03:58 pm
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

Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 17, 2011, 05:06 am
Which Arduino IDE version are you using?
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 17, 2011, 09:51 am
Whoops sorry about that,
Version 0021

Title: Re: Pwm output is high on bootup?
Post by: MarkT on Feb 17, 2011, 04:20 pm
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?
Title: Re: Pwm output is high on bootup?
Post by: Grumpy_Mike on Feb 17, 2011, 04:22 pm
Quote
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.
Title: Re: Pwm output is high on bootup?
Post by: retrolefty on Feb 17, 2011, 07:07 pm

Quote
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.  ;)
Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 17, 2011, 09:52 pm
Whoops sorry about that,


No problem.

Quote
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.
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 18, 2011, 10:17 am
Hi all,
I tried this code on version 0022:

Code: [Select]
int Pwm_output_pin_10 = 10;

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

void loop()
{
}


Same result. Output still goes high for a short moment. Just to check I also tried it all on an other Arduino board and the problem is still there.

I have two new video's.
You see it with a led instead of the scope.
I plug in the cable and you see the process. It goes high for a little while, then nothing and after that high again and it's ready for use. I also later on press reset and you see it now does 'reboot' nicely without the 'going high' problem.

First video:
http://home.planet.nl/~sintt000/Arduino3.wmv (http://home.planet.nl/~sintt000/Arduino3.wmv)

Second video:
Here you see the boot process when powered from a battery.
This works fast and without the problem.

http://home.planet.nl/~sintt000/Arduino4.wmv (http://home.planet.nl/~sintt000/Arduino4.wmv)

Thanks.



Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 18, 2011, 10:30 am
The processor that's on that board ... where did you get it?  Is it the processor that came with the board?

Is that the same board you were using earlier with the oscilloscope testing?

Just to confirm ... the LED is on pin 10?

Do you have an ICSP?  Another Arduino?
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 18, 2011, 11:24 am
I tried this code:
So no Arduino native PWM but a digitalWrite and Delay combo on pin 8.
Problem is the same.

Code: [Select]
int LedTest1 = 8;

void setup() {
  pinMode (LedTest1, OUTPUT);
}

void loop() {
  digitalWrite(LedTest1, HIGH);
  delay(25);
  digitalWrite(LedTest1, LOW);
  delay(25);
}


Please see the video:
http://home.planet.nl/~sintt000/Arduino5.wmv (http://home.planet.nl/~sintt000/Arduino5.wmv)

Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 18, 2011, 11:32 am
Hi,
Yes the board came ready to use so including the chip.
I'm not really sure where we got them, probably a local Dutch electronics store. My boss bought them (we have 2 boards)

Yes the same board as used in the scope video.

Yes pwm pin 10.

I have two boards and both behave the same.
I have no ICSP

Thanks!


The processor that's on that board ... where did you get it?  Is it the processor that came with the board?

Is that the same board you were using earlier with the oscilloscope testing?

Just to confirm ... the LED is on pin 10?

Do you have an ICSP?  Another Arduino?

Title: Re: Pwm output is high on bootup?
Post by: Coding Badly on Feb 22, 2011, 12:06 am
Using the "Arduino Duemilanove or Nano w/ ATmega328" board option (ATmegaBOOT_168_atmega328.hex bootloader) I cannot reproduce the problem.  Everything works as expected.

I have not been able to test with the "Arduino Uno" (optiboot_atmega328.hex bootloader)...

Code: [Select]
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.


Would someone with an Uno (or someone who can get Optiboot working) mind trying to reproduce this problem.  All that's needed are a few LEDs + resistors and one of the Sketches above.
Title: Re: Pwm output is high on bootup?
Post by: nali2001 on Feb 22, 2011, 10:05 am
Thanks for trying,
Odd that you don't see this issue, I tried two broads and the problem is the same.
That is, only when powered from usb cable, powered from battery solves the problem.

Looks like the usb communication interrupts the operation of the board when cable is just plugged in.

So if anyone wants to verify this problem, this is what you need:
470ohm resistor and a led.


And this code:

Code: [Select]
int Pwm_output_pin_10 = 10;

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

void loop()
{
}


Power it from usb and see if the led goes on for a short moment, then off, and after a while on again.

Thanks!
Title: Re: Pwm output is high on bootup?
Post by: knowledge on Jun 07, 2018, 07:44 am
Hey,

Is this problem solved of getting pulse when booting up arduino??

I am facing same problem.