Created Thu, 22 Sep 2011 18:18:15 +0000 by jbeale
Thu, 22 Sep 2011 18:18:15 +0000
The PIC32MX320F128H data sheet says the CPU supports "Hardware RTCC", using an external 32.768 kHz crystal. I see the UNO32 board has an unstuffed part labelled X2 which I assume is intended for that part. If I did stuff a 32kHz crystal there, what additional software support would be needed for a usable RTC function?
The datasheet also mentions the RTC module is "Optimized for Long-Term Battery Operation". Is it feasible to use an Uno32 with a coin-cell type backup battery to maintain the RTC, or would voltage regulators or other parts drain too much current?
Fri, 23 Sep 2011 21:21:53 +0000
The RTCC module uses the secondary oscillator as its clock source. There is a bit in the OSCCON register (SOSCEN) that has to be set to enable the secondary oscillator. If you don't do that, the RTCC won't function. You then have to enable the RTCC by setting the ON bit in the RTCCON register.
Refer to Section 6: Oscillators, and Section 29: Real-Time Clock and Calendar (RTCC), of the PIC32 Family Reference Manual on the Microchip web site. The PIC32 data sheets only contain brief summary information for the on-chip peripherals. You need the appropriate sections of the Family Reference Manual for the real information needed to program them.
Gene Apperson Digilent
Sat, 24 Sep 2011 06:41:36 +0000
Setting SOSCEN is not simple since OSCON is a protected register . I have written a small sketch to start RTTC and to check
void setup() {
Serial.begin(9600);
Serial.print("RTCCON= ");
Serial.print(RTCCON, HEX);
Serial.print(" / ");
Serial.print("OSCCON= ");
Serial.print(OSCCON, HEX);
//Unlock OSCCON;
SYSKEY = 0x0;
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
OSCCONSET = 2;
SYSKEY = 0x0;
Serial.println();
Serial.print("RTCCON= ");
Serial.print(RTCCON, HEX);
Serial.print(" / ");
Serial.print("OSCCON= ");
Serial.print(OSCCON, HEX);
Serial.println();
// RTCTIME = 0;
}
void loop() {
Serial.println(RTCTIME, HEX);
delay(1500);
}
the result
RTCCON= 8040 / OSCCON= 1453320
RTCCON= 8040 / OSCCON= 1053322
10073000
10073100
10073300
10073400
Sat, 24 Sep 2011 08:26:47 +0000
Hi!
This is really fascinating! Thank you for sharing.
The datasheet also mentions the RTC module is "Optimized for Long-Term Battery Operation". Is it feasible to use an Uno32 with a coin-cell type backup battery to maintain the RTC, or would voltage regulators or other parts drain too much current?
But what about coin-cell backup battery?
Sat, 24 Sep 2011 20:42:40 +0000
About connecting a coin cell battery I can't say anything in this moment. But I have another issue with the RTCC. I am using a MAX32 with ethernet shield that includes a 32768kHz oscillator. My problem is that as soon as I activate SOSCEN a M1632 display connected as in arduino LiquidCrystal class does not work anymore . I tried to move output 2 and 12 that looks like interfering with RTCC on 6 and 10 but with no results . I do not find anymore where is the interference on activating RTCC and LCD display
Sun, 25 Sep 2011 19:18:31 +0000
Solved with my oscilloscope. I was counting wrong and the problem were on pin 4 (arduino numbering) .
Sun, 25 Sep 2011 21:14:07 +0000
Great :!:
But Arduino-numbering pins 4 and 5 are in charge of i2c —SDA and SCL.
Does that mean that enabling the RTC disables the i2c port :?:
Sun, 02 Oct 2011 15:53:06 +0000
Paul L Thanks for the code , Added xtal to Uno32 and got result ! I needed basic time keeping for my project , I hope it has saved me adding an RTC chip.
Sun, 02 Oct 2011 18:40:13 +0000
Hi!
Do Arduino-numbering pins 4 and 5 in charge of i2c —SDA and SCL— work when RTC is activated?
Thank you!
Sun, 02 Oct 2011 21:03:31 +0000
avenue33 ... If you mean A4 and A5 on Uno32 J7 ? they remain ( with JP6 , JP8 in RG3, RG2 position) as I2C SDA SCL , secondary osc port RC13 , RC14 does not appear to be available on a pin.
Tue, 18 Oct 2011 11:11:21 +0000
Avenue 33
As we discussed by PM I started to write a library for reading and setting the RTCC. The library is in the first state of development. I even did not added any comments but there are some methods that I used in a test sketch for a internal RTCC clock . There are no methods yet for Calendar, only time. I used this library for a clock based on internal RTCC ( oscillator on Network shield) synchronized from time to time with NTP .
I am adding here the library in his very early state only to play with it . I will develop it as I will have time for this project
[attachment=0]chipKITRTCC.zip[/attachment]
Hope that it will be useful even in this development state.
Tue, 18 Oct 2011 12:04:29 +0000
Thank you for sharing :)
Tue, 18 Oct 2011 13:21:45 +0000
Hope you can use it as it is now. Maybe in the weekend i will try to add some comments , new methods, etc.
Wed, 19 Oct 2011 17:27:44 +0000
Thank you for sharing.
I worked on the library and posted the result on :arrow: GitHub.
I used the same functions as for the DS1307 I2C RTC library.
I confirm I2C is not impacted by the RTC.
Enjoy ;)
Sun, 15 Jan 2012 00:30:37 +0000
Seems that the RTC isn't actually keeping time in the pic32 RTC main example. Is there something I need to change?
Sun, 15 Jan 2012 08:46:06 +0000
Seems that the RTC isn't actually keeping time in the pic32 RTC main example. Is there something I need to change?
Could you please specify which sketch, library and release you're referring to?
Internal RTC doesn't keep the time when the chipKIT isn't powered. That's why the DS1307 board has a cell coin battery.
Do you remember the very first IBM PC? At each boot-up, date and time were asked for and entered manually.
Please consider [color=#0000FF]Double_Clock[/color] or [color=#0000FF]NTP_Clock[/color] sketches: date and time are obtained from external DS1307 for [color=#0000FF]Double_Clock[/color], or NTP time server through WiFly for [color=#0000FF]NTP_Clock[/color].
Both are available at the :arrow: GitHub repository.
Enjoy ;)