Pages: [1] 2   Go Down
Author Topic: Will this capacitor damage my output pin?  (Read 1469 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to get my head around how fast this capacitor will charge, and what current it will draw:



Basically the idea is to turn on the DS1307 clock chip, as required to read the time. Then to turn it off again using a digital pin as the "power" pin, like this:

Code:
#include <Wire.h>
#include "RTClib.h"

const byte POWER = 8;

RTC_DS1307 RTC;

void setup () { }

void loop () {
  delay (1000);

  // power up clock chip
  pinMode (POWER, OUTPUT);
  digitalWrite (POWER, HIGH);
  // wait for it to be read
  delay (5);
  // talk to it
  Wire.begin();
  RTC.begin();
  // get time
  DateTime now = RTC.now();

  // do something with the time
 
  // drop power to chip
  pinMode (POWER, INPUT); 
  digitalWrite (POWER, LOW);  // turn off pull-up

  // turn off I2C
  TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
}  // end of loop

I think someone said a while back that the 0.1uF capacitor (which is the decoupling capacitor on the clock board) might drain too much current for the good of the digital pin.

  • Is that true?
  • How do I calculate exactly how much it would drain?
  • Can I "save" my pin in some way, like a small series resistor? If so, what value?
  • Or would a MOSFET as the "power switch" be indicated?

I've been looking at some web sites about the charge rate of capacitors, and they talk about "the series resistor" which is part of the equation. But there is no resistor there. Is there an implied one, like the ESR of the capacitor? Or something else?

Also I seem to be getting "reverse" current back from the capacitor when the digital pin switches off and the capacitor discharges.

  • Is that bad?
  • Should I put a diode there to drain this current?

Thanks for any advice.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 76
Posts: 7305
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick,

What is the purpose of the capacitor? I read your post and you are trying to turn on a chip but I didn't see why you need that capacitor. Maybe for voltage stabilization?

I glanced at the doc and didn't find a DC resistance of each pin. Without a serial resistor, the capacitor will pull a large current, initially equal to 5V/DC resistance of the pin. That is what I guestimate. So to maintain the current below 20mA, you need a resistor between pin 8 and the junction made by the 3 wires. So 5V/20mA=250ohm. When the capacitor is fully charged, its voltage will be 5V and there's no voltage drop on the resistor. If you switch on the chip with pin 8, do you know the maximal current draw of the chip? Should be in spec sheet. If that is greater than 20mA, the max of arduino pin (fig. 30-350 in doc), then you may need a MOSFET as a switch. It seems to me a bit tricky since the chip has a backup battery at 3.3V. You will have to sandwich the chip 5V and GND between the MOSFET and 5V. MOSFET source pin is connected to GND, gate pin to pin 8, drain pin to the chip GND. If you already have the GND of the chip connected to common GND, you have to disconnect it. That's what I think. See if others can comment on my method.

The capacitor actually never finishes charging but here's the fomula:
i=V/R_serial(exp(-t/(R_serial*C)))
Logged


United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With prolonged use, I think that might well damage the output pin. Even when driving the gate of a power mosfet with about 50 times less capacitance, a series resistor is recommended. The active current for the DS1307 is specified as 1.5mA maximum, so I think you can add a series resistor of e.g. 220 ohms between the pin and the capacitor/DS1307 and still provide enough voltage to supply the DS1307. Make sure you allow enough time between setting the pin high and reading the clock for the capacitor to charge.
« Last Edit: January 27, 2012, 06:59:50 pm by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the purpose of the capacitor?

I didn't put it there, but I gather it's a decoupling capacitor between Vcc and Gnd.



Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the purpose of the capacitor?
I didn't put it there, but I gather it's a decoupling capacitor between Vcc and Gnd.

Indeed it is. I have no basis for saying this, but I really don't know how much sleep I'd lose over it. I have several of those RTCs from AFI and often plug them directly in to an Uno, powering them via

Code:
    //power the DS1307 RTC breakout board from the A2 (ground) and A3 (+5VDC) pins
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    digitalWrite(A2, LOW);
    digitalWrite(A3, HIGH);

The above code is always in setup(), so happens relatively infrequently.

So if I were to guess, you're putting the MCU to sleep and you want the RTC to run from the backup battery in the meantime?
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 76
Posts: 7305
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

220-250 resistor will be needed. No need for Mosfet
Logged


Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So if I were to guess, you're putting the MCU to sleep and you want the RTC to run from the backup battery in the meantime?

Yes it's part of my ongoing research into saving power. The idea is to let the watchdog timer wake you up (at a slower clock speed this could be fairly infrequently) and then from time to time power up the clock chip and find out the actual time. Since the clock chip has a battery backup that should stay correct for years.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well this is what I don't totally get ...

Looking at the pin D8, when running the above sketch, I see this:



Note that for most of the time the pin is at 3.44V, even though it is in input mode, with pull-ups turned off.

Now strangely enough (after quite a bit of experimenting) if I add these two lines after turning off D8:

Code:
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);

Then I see this:



But that isn't pins A4 or A5. It seems as if somehow the I2C pull-up current is somehow working its way through the DS1307 chip, and making itself felt at the Vcc pin. Well that's weird.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That look like a discharging curve.  In my opinion
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, but once the curve has discharged, in the upper screen shot, the flat line is at 3.44V, not 0V, for most of the time.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 76
Posts: 7305
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, but once the curve has discharged, in the upper screen shot, the flat line is at 3.44V, not 0V, for most of the time.

Just a wild guess, what happens if you disconnect the 3.3V backup battery?
Logged


Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking along those lines myself, but I don't see how a 3.3V battery would hold Vcc at 3.44 V. Plus, once I pulled the SDA/SCL lines from the clock chip, and the voltage immediately dropped to zero, I thought I had found the culprit.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Full Member
***
Karma: 2
Posts: 144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, thanks for posting this, found it really useful.
Logged

a][+ ascii express, 110/300 novation cat, xmodem

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My pleasure, and thanks to everyone for clearing up the resistor value. I am worried that I might confidently post complete nonsense if I don't check up on the finer details. smiley

My summaries of power-saving techniques so far:

http://www.gammon.com.au/forum/?id=11497
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So if I were to guess, you're putting the MCU to sleep and you want the RTC to run from the backup battery in the meantime?

Yes it's part of my ongoing research into saving power. The idea is to let the watchdog timer wake you up (at a slower clock speed this could be fairly infrequently) and then from time to time power up the clock chip and find out the actual time. Since the clock chip has a battery backup that should stay correct for years.

I've been playing with clocking Timer2 from a 32.768kHz crystal. Have one 328P on a breadboard, running from 2xAA cells, using 1MHz RC oscillator for system clock, Timer2 generating an interrupt every 8 seconds. The ISR is a software RTC. Works nicely, minimal parts. Draws about a microamp. Can adjust the prescaler for one interrupt per second if having the second hand jump eight notches at a time is too coarse smiley-lol
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Pages: [1] 2   Go Up
Jump to: