<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Clock calendar implementation on RTC</title>
		<link>http://forums.leaflabs.com/topic.php?id=1058</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:14:04 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1058" rel="self" type="application/rss+xml" />

		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=11#post-21929</link>
			<pubDate>Tue, 08 Jan 2013 17:26:17 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21929@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You are correct. The example was supposed to be on the github... but got overlooked and to be honest I've been swamped with work and my masters. :( &#60;/p&#62;
&#60;p&#62;About your question. &#60;/p&#62;
&#60;p&#62;Lady Ada uses this on her library&#60;/p&#62;
&#60;p&#62;//RTC.adjust(DateTime(__DATE__, __TIME__));&#60;/p&#62;
&#60;p&#62;I haven't looked at it or how to use it in my code, but there's a good chance that it may work. &#60;/p&#62;
&#60;p&#62;I'll try to add the example to the github repository. &#60;/p&#62;
&#60;p&#62;By the way, after looking at the library and at the Arduino implementation of time.h... I think (still need to test) that my implementation may be better as it doesn't use strings and it uses the original time.h. But it's mostly about not having much time to do much about it. &#60;/p&#62;
&#60;p&#62;Thank you for your suggestions and for testing the library. :)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gsentlin on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=11#post-21919</link>
			<pubDate>Tue, 08 Jan 2013 08:45:40 +0000</pubDate>
			<dc:creator>gsentlin</dc:creator>
			<guid isPermaLink="false">21919@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks! That worked.  It's unfortunate that the time must be set when the unit is reset.  Any idea how to read the computer time so the STM32 time can be set when reprogrammed?&#60;/p&#62;
&#60;p&#62;In the interest of making this board more accessible to new users, have you considered packaging the above code with the github download?&#60;/p&#62;
&#60;p&#62;Great work.  Next I'm onto the SD Card.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21870</link>
			<pubDate>Sat, 05 Jan 2013 20:20:27 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21870@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;Thanks for the feedback. &#60;/p&#62;
&#60;p&#62;Unfortunately, no. The Olimexino doesn't have a backup battery for timekeeping. :( &#60;/p&#62;
&#60;p&#62;This is the test sketch I used:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#include &#38;lt;RTClock.h&#38;gt; 

/* choose one of the available Clocks.
 * I&#38;#39;ll choose the HSE/128 that works in all boards
 * people with Olimexino can choose any clock (LSE is the 32kHz).
*/
//RTClock rt(RTCSEL_LSE);
RTClock rt(RTCSEL_HSE);
//RTClock rt(RTCSEL_LSI);
//RTClock rt; // this starts HSE clock as a default. 

void AlarmFunction () {

  SerialUSB.println(&#38;quot;WAKE UP!!!!&#38;quot;);//somehow this shows up late in the USB connection. :( 

  //if you want an interrupt every minute...
  //time_t now = rt.getTime();
  //rt.setAlarmTime(now + 60);
}

struct tm time_tm, *tm_ptr;//this is a structure with date and time fields
time_t Alarm_period; //this can hold the number of seconds from 00:00:00 1/1/1970

void setup() {
  pinMode(BOARD_LED_PIN, OUTPUT);//setup our alive pin.
//define My Epoch. No need to try, don&#38;#39;t use these numbers in passwords.
  time_tm.tm_sec = 0;
  time_tm.tm_min = 45;
  time_tm.tm_hour = 15;
  time_tm.tm_mday = 27;
  time_tm.tm_mon = 6;
  time_tm.tm_year = 80;//years since 1900

  rt.setTime(&#38;amp;time_tm);
  rt.attachSecondsInterrupt(&#38;amp;toggleLED);//the led will toggle every second.

  time_tm.tm_min = 47;
  rt.createAlarm(&#38;amp;AlarmFunction, &#38;amp;time_tm); //ring the alarm 2 minutes later... 

}

void loop() {
  if (SerialUSB.available() &#38;gt;0) {
       SerialUSB.read(); //bogus read...
       tm_ptr = rt.getTime(tm_ptr);
       SerialUSB.print (&#38;quot;time: &#38;quot;);
       SerialUSB.print (tm_ptr-&#38;gt;tm_hour);
       SerialUSB.print (&#38;quot;:&#38;quot;);
       SerialUSB.print (tm_ptr-&#38;gt;tm_min);
       SerialUSB.print (&#38;quot;:&#38;quot;);
       SerialUSB.println (tm_ptr-&#38;gt;tm_sec);
       SerialUSB.print (&#38;quot;date: &#38;quot;);
       SerialUSB.print (tm_ptr-&#38;gt;tm_mday);
       SerialUSB.print (&#38;quot;/&#38;quot;);
       SerialUSB.print (tm_ptr-&#38;gt;tm_mon);
       SerialUSB.print (&#38;quot;/&#38;quot;);
       SerialUSB.println ((1900 + tm_ptr-&#38;gt;tm_year));
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Hope it's what you're looking for. &#60;/p&#62;
&#60;p&#62;I might try to convert, or create a new version of this library and port the DateTime library from Arduino to Maple in order to make it easier to move from the Arduino to Maple.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gsentlin on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21864</link>
			<pubDate>Sat, 05 Jan 2013 13:15:47 +0000</pubDate>
			<dc:creator>gsentlin</dc:creator>
			<guid isPermaLink="false">21864@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I have an Olimexino-STM32 and I've successfully installed the bubulindo RTC libraries and have the example code working.  Thanks for all of your work on this.  Unfortunately, this is all rather new to me.  I've been working with the Arduino Uno up until now and the Maple discussions are quite technical.  Can you please provide a link to some example code that I could use to convert the output of rt.getTime() to date:time, and possibly date:time strings. &#60;/p&#62;
&#60;p&#62;Ideally you could also provide code to synch the clock to the computer clock, and possibly adjust for drift.  Is there battery backup of the RTC or do you have to set it each time the board is powered up?&#60;/p&#62;
&#60;p&#62;Thanks
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21600</link>
			<pubDate>Mon, 10 Dec 2012 11:09:55 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21600@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Actually... I just found out that the Arduino has an official time library. Maybe that is exactly where this functionality should go. They already implemented the date calculations from the timestamp so it should be simple. &#60;/p&#62;
&#60;p&#62;I think I'll keep this implementation as is, and put the version with the time counting inside the Arduino time.h. :\ Lot less work, I'd say.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21551</link>
			<pubDate>Fri, 07 Dec 2012 21:13:19 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21551@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;As for my pin 11 (OCR2A) problems -- pilot error.  I had 8mhz 328p hotwired off empty uno board, and i was running my scope probe to the header on the uno board instead of the breadboard pin -- DUH.&#60;/p&#62;
&#60;p&#62;OK, so both mine and your pulse works on pin 11 every second.  HOWEVER, it's not going to give you a pulse-per-second type signal.  It will toggle the pin on for a second, off for a second, so you're only going to get a rising edge every 2 seconds.  You'd need to switch to a PWM mode to double the pulse rate ...&#60;/p&#62;
&#60;p&#62;I ran similar frequency checks on DUE (-4 ppm off for system cyrstal, 3ppm for onboard 32khz/RTC,&#60;br /&#62;
and -117701ppm for RC-mode RTC)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21528</link>
			<pubDate>Fri, 07 Dec 2012 01:06:57 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21528@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'm looking into that now.&#60;br /&#62;
my settings don't seem to take effect on the TCCRA, there's some interlock in the functions that disables the light from blinking each second. &#60;/p&#62;
&#60;p&#62;If you try to disable the blink, it will start blinking. :&#124; I changed the code and it seemed to work fine, but I didn't fully understand what was wrong. I'll probably only have time to get back to that around new year. :(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21520</link>
			<pubDate>Thu, 06 Dec 2012 20:45:20 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21520@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo: Re: your AVR RTC lib&#60;/p&#62;
&#60;p&#62;It seems to work on 328p/ 8MHz RC and 32khz crystal, it says&#60;br /&#62;
 time is:15:28:17&#60;br /&#62;
 time is:15:28:18&#60;br /&#62;
 ...&#60;/p&#62;
&#60;p&#62;turning on pin11 (n/f) didn't seem to light the LED if i ran 11 to pin 13 ?&#60;/p&#62;
&#60;p&#62;I had my own timer2 sketch, and i couldn't really see that OCR2A was effecting anything ???
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21515</link>
			<pubDate>Thu, 06 Dec 2012 13:42:23 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21515@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thinking back without delving too much into the threads about that I believe it was gbulmer or rodgilchrist that mentioned the possibility to tune the crystal by means of the prescaler. &#60;/p&#62;
&#60;p&#62;Thanks for testing that... no one used it (to my knowledge) before.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21496</link>
			<pubDate>Wed, 05 Dec 2012 14:54:14 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21496@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo: thanks for nice RTC interface, by setting  RTClock rt (RTCSEL_LSE,0x7ffe); I brought my crystal from -35ppm too slow, to -4 ppm.  And by setting  RTClock rt (RTCSEL_LSI, 0x9920); I got the LSI down from -19000ppm to 200 ppm
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21494</link>
			<pubDate>Wed, 05 Dec 2012 12:02:48 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21494@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I like the simple unixsecs++ in the ISR (plus if you decided to do drift correction, e.g, you knew your crystal was slow by 10 ppm, then every 100,000 secs you could add 2 instead of 1  :-).  You might look at code from some of the RTC modules where they do some of the unixseconds to time struct conversions&#60;/p&#62;
&#60;p&#62;   &#60;a href=&#34;https://github.com/maniacbug/RTClib&#34; rel=&#34;nofollow&#34;&#62;https://github.com/maniacbug/RTClib&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;For RTC crystal calibration on the maple besides using an NTP host, you can use the master crystal via micros() -- in the one-second RTC interrupt ISR, add the value of micros to another counter.  After a few mintues you can see the drift.  The 32Khz crystal that I checked with the NTP host was -41 ppm, and then using the pps-ISR and micros, I measured -35 ppm.&#60;/p&#62;
&#60;p&#62;Also I confirmed that adjusting the BKP calibration register does in fact change the timing of the RTC pps-interrupt.  And you can change the prescaler to assist in calibrating the 32khz crystal. One unit of prescaler (1/32768) is 30 ppm.&#60;/p&#62;
&#60;p&#62;I measured the LSI (RC) frequency offset on my maple at -19688 ppm.  The LSI can be adjusted by the  20-bit prescaler
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bubulindo on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21489</link>
			<pubDate>Wed, 05 Dec 2012 09:53:11 +0000</pubDate>
			<dc:creator>bubulindo</dc:creator>
			<guid isPermaLink="false">21489@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, &#60;/p&#62;
&#60;p&#62;I'm really glad you came up with that question. First, this is the first version and is intended to prove the concept and test the counting logic.&#60;br /&#62;
At the time I thought about the typical Arduino user that will ask for the time more times than once per second (taking lots of resources for the calculation) but also trying to maintain some standard by using (a somewhat modified) the struct tm &#60;/p&#62;
&#60;p&#62;But then started thinking about making the ISR to count seconds (and implement now()), and hit the first wall. The AVR-libc doesn't come with a time.h and after going through the time.h lib from newlib, I think that most of the logic might be overkill for an AVR and depending on how the library is used ending up taking more system resources than the time counting code I have now.  &#60;/p&#62;
&#60;p&#62;On the other hand, because time.h is not standard in the AVR-libc, some of the fields in the struct tm are &#34;useless&#34; as there is no simple way (unless implementing time.h functions) to confirm or calculate the values. The day of year is one of such variables. &#60;/p&#62;
&#60;p&#62;So the last conclusion I took was to cut the fat from the actual version (leaving year, month, day, hours, minutes and seconds) and create another version of the library (or even within the same) to just implement the counting of seconds. &#60;/p&#62;
&#60;p&#62;What is your opinion about the best structure? &#60;/p&#62;
&#60;p&#62;I came up with this while thinking out loud about a binary clock, so my concern then was merely hours and minutes and trying to do this with the least amount of resources so I could put the controller to sleep and run it at 1MHz.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21484</link>
			<pubDate>Wed, 05 Dec 2012 06:48:59 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21484@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bubulindo: Re: your AVR RTC lib&#60;/p&#62;
&#60;p&#62;In the timer2 ISR, would it be cleaner to just have a  volatile long unixsecs; that holds the unix seconds since 1970 value, and all that is done in the ISR is  unixsecs++.  Then do all your conversions to day/month/year in the lib only when user requests time.... or not.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21482</link>
			<pubDate>Wed, 05 Dec 2012 06:02:57 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21482@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#38;gt;You can calibrate and slow an RTC crystal down with the RTCCR register, but I wasn't able to affect any change that I could see on crystal rate. May be some more black magic needed to get that to work&#60;/p&#62;
&#60;p&#62;The 512 hz output will not be affected by the changes in the prescale or calibration register of the RTC, because it is emitted upstream of the RTC register counters.  I'll need to measure changes in the pulse-per-second rate of the RTC to observe the effects of prescaler/calibration.  The prescaler for the LSE is in units of 1/32khz (30 ppm) and the calibration register can slow the RTC from 1 to 120 ppm.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>manitou on "Clock calendar implementation on RTC"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1058&amp;page=10#post-21453</link>
			<pubDate>Tue, 04 Dec 2012 11:28:04 +0000</pubDate>
			<dc:creator>manitou</dc:creator>
			<guid isPermaLink="false">21453@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I got the 512hz pulses from the 32khz crystal hooked to the maple RTC (pins 22,23) by doing&#60;/p&#62;
&#60;p&#62;BKP_BASE-&#38;gt;RTCCR &#124;= BKP_RTCCR_CCO;&#60;/p&#62;
&#60;p&#62;I ran a wire from pin 21 (512hz pulse pin) to pin 4 and attached an ISR to pin 4 and counted ticks.  Sure enough I got 512 ticks/second.  Using those ticks, I calibrated the 32khz crystal with the NTP host, and crystal was slow by 41 ppm (spec is +- 20 ppm).  I had another 32khz crystal, but it was BAD.  The RTC one second blink was taking 9 seconds!  The NTP drift check showed -889000 ppm.&#60;/p&#62;
&#60;p&#62;You can calibrate and slow an RTC crystal down with the RTCCR register, but I wasn't able to affect any change that I  could see on crystal rate.  May be some more black magic needed to get that to work.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
