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.
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:
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.
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.
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.
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
The I2C pins probably have internal protection diodes, anode to the pin, cathode to Vcc. So I expect you will find that the voltage on the I2C pins is about 0.6v higher than the voltage on that Vcc pin.
Hi Nick, circuit attached below. I call it a "night light" because the sketch includes an algorithm that calculates sunrise and sunset time, and turns the LED on at sunset and off at sunrise.
Say, regarding the capacitor issue, I think it's a very interesting question, and I'd be willing to sacrifice an ATmega328P if you'd like to discuss a test protocol and circuit. I suppose we could cycle the pin hundreds if not thousands of times per second, so shouldn't be a terribly lengthy test.
Nice and simple project. Do you have a code to share ? That will be nice.
Hi Techone,
Yes, I'll be glad to share code as well, I'm still tweaking it a bit though. I'm working on a blog post which will describe the code as well as the circuit. I'm not sure that it's a terribly "practical" project, but it does demonstrate several interesting features, and so I found it educational if nothing else!
Give me a few days and I'll let you know when I've got the post complete.
Thanks, Jack! But where's the 1 MHz RC oscillator? You seem to be using a 32.768 KHz crystal.
I'm not sure what that would prove, though. Basically the pins fail because of physical things (like, getting too hot). So cycling the capacitor thousands of times a second would put a totally different strain on the output circuit, compared to doing it once a minute (when it gets a chance to cool down).
I'm happy with the resistor, the capacitor seems to charge within a microsecond as far as I can tell, so it hardly introduces a lengthy delay. And as a general principle (eg. for a radio transmitter board) it is probably better to be safe than sorry.
Right, but the 32kHz crystal is only clocking Timer2, and the internal RC oscillator, set to 1MHz, is the system clock. Pretty cool, eh! Fuses are: lfuse=0x62, hfuse=0xD6, efuse=0x06, and then Timer2 is configured with
TIMSK2 = 0; //stop timer2 interrupts while we set up
ASSR = _BV(AS2); //Timer/Counter2 clocked from external crystal
TCCR2A = 0; //override arduino settings, ensure WGM mode 0 (normal mode)
TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20); //prescaler clk/1024 -- TCNT2 will overflow once every 8 seconds
TCNT2 = 0; //start the timer at zero
while (ASSR & (_BV(TCN2UB) | _BV(TCR2AUB) | _BV(TCR2BUB))) {} //wait for the registers to be updated
TIFR2 = _BV(OCF2B) | _BV(OCF2A) | _BV(TOV2); //clear the interrupt flags
TIMSK2 = _BV(TOIE2); //enable interrupt on overflow
[quote author=Nick Gammon link=topic=89182.msg669906#msg669906 date=1327789394][quote author=Jack Christensen link=topic=89182.msg669892#msg669892 date=1327788536]
Say, regarding the capacitor issue, I think it's a very interesting question, and I'd be willing to sacrifice an ATmega328P if you'd like to discuss a test protocol and circuit. I suppose we could cycle the pin hundreds if not thousands of times per second, so shouldn't be a terribly lengthy test.
[/quote]
I'm not sure what that would prove, though. Basically the pins fail because of physical things (like, getting too hot). So cycling the capacitor thousands of times a second would put a totally different strain on the output circuit, compared to doing it once a minute (when it gets a chance to cool down).
I'm happy with the resistor, the capacitor seems to charge within a microsecond as far as I can tell, so it hardly introduces a lengthy delay. And as a general principle (eg. for a radio transmitter board) it is probably better to be safe than sorry.
[/quote]
Well, I'd be interested to know if a 100nF capacitive load is ultimately a harmful thing. So I was thinking we could wire it up, cycle the pin a lot of times, and see whether it fails after some large number of iterations.