How does Duemilanove power switching work?

How does Duemilanove power switching work?

I’m powering my Arduino Duemilanove with a wall-wart but I want to add a battery backup via the USB port to handle power glitches and outages from the wall-wart. My understanding is that the Duemilanove will switch power sources automatically, but it’s not working as I expected so I am hoping somebody can explain it to me.

As a way of testing the automatic power switching, I did the following:
a. I loaded the LiquidCrystal Library “Hello World” example sketch, which displays “Hello World” on my LiquidCrystal display and then increments and displays a counter once a second. This works.
b. After loading the above sketch, I exited from the Arduino program on my Windows PC, so that the USB connector is only providing power. The displayed counter continued to increment without interruption, as expected.
c. I attached a wall wart to the Duemilanove and then disconnected the USB cable. The displayed counter continued to increment without interruption, as expected.
d. I reconnected the USB cable to the PC. The onboard LED blinks several times, and then the counter resets and starts counting from zero. This is NOT what I expected or desire to occur. Apparently, plugging the USB cable back in causes the Arduino board to reset. Does this always happen? Or is it related to something that Windows might be doing? Would the reset occur if I supplied power to the USB port via a battery instead of using my PC (that’s what I originally planned to do but was testing with the PC to make sure it will work) ?

Thanks in advance for any explanation.

It's possible the PC is initializing the FT232RL causing it to reset the board. You could try disableing auto-reset.

It's possible the PC is initializing the FT232RL

Not only is it possible it is exactly what is happening.

Disabling the auto reset will work. There are lots of ways to do this. I have a small slider switch soldered onto mine. Other ways are a low value pull up resistor on the reset pin. Or a large capacitor from the reset to ground.

Thanks for your responses.

Would the reset occur if I supplied power to the USB port via a battery instead of using my PC ? Or does the reset occur whenever power is is applied to the USB port, regardless of its source ?

Is there any way to disable the automatic reset via software, or does it require one of the hardware modifications that Grumpy Mike mentioned?

Thanks again.

Is there any way to disable the automatic reset via software

No it is a hardware thing. The only thing you could do in software is to re write the PC drivers.

Would the reset occur if I supplied power to the USB port via a battery instead of using my PC

No, it is not the power that is causing the reset it is the driver on the USB / Serial port that is toggling the DTR line on start up.