Go Down

Topic: Will this capacitor damage my output pin? (Read 1 time) previous topic - next topic

Nick Gammon

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: [Select]
#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.
Please post technical questions on the forum, not by personal message. Thanks!

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

liudr

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

dc42

#2
Jan 28, 2012, 12:55 am Last Edit: Jan 28, 2012, 12:59 am by dc42 Reason: 1
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.
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.

Nick Gammon


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.



Please post technical questions on the forum, not by personal message. Thanks!

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

Jack Christensen



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: [Select]
    //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?
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

liudr

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

Nick Gammon


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.
Please post technical questions on the forum, not by personal message. Thanks!

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

Nick Gammon

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: [Select]

  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.
Please post technical questions on the forum, not by personal message. Thanks!

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

Techone

That look like a discharging curve.  In my opinion

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

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

liudr


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?

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

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

j514

Nick, thanks for posting this, found it really useful.
a][+ ascii express, 110/300 novation cat, xmodem

Nick Gammon

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

My summaries of power-saving techniques so far:

http://www.gammon.com.au/forum/?id=11497
Please post technical questions on the forum, not by personal message. Thanks!

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

Jack Christensen



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 XD
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Go Up