Pages: [1]   Go Down
Author Topic: internal RTC  (Read 2605 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 21
Posts: 1419
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

According to the datasheet, the SAM3X has an internal RTC. There is also a 32.768Khz oscillator attached to the XOUT32 and XIN32 pins.
Is there a possibility to use the internal RTC with the Arduino libraries?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes there is a possibility, as to whether or not anyone has done that work yet I don't know but I very much doubt it because some other basic stuff has not been implemented yet.

They may just leave it for a bright young lad to port an existing RTC library.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, but what about the RTC battery?
When we turn off the DUE also the RTC will go off, sounds like whe need to syncronize it every time we turn on the DUE.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, there's no provision for a backup battery so having the RTC is of limited value I think.

It's a shame because the SAM has really good features for shutting itself and the entire PCB down.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, the DUE RTC seems to be ticking, but i'm trying to enable the "second" interrupt.  See the following sketch
Code:
// due rtc   32khz
//  pps interrupt
//   RTC        (0x400E1A60U)  rtc registers

#define BOARD_LED_PIN 13
volatile static unsigned long ticks,us;
static unsigned long us0;
static uint8_t hr,min,sec,day,m,wk;
static uint16_t yr;


void RTC_Handler() {
    if (us0 == 0) us0 = micros();
     else {
        ticks++;
        us = micros() - us0;
    }
}

void setup() {

    pinMode(BOARD_LED_PIN,OUTPUT);
Serial.begin(9600);
// pmc_set_writeprotect(false);
// pmc_enable_periph_clk(RTC_IRQn);
hr=1; min =2; sec=3; m=4; day=5; wk=6; yr=2012;
RTC_SetTime(RTC,hr,min,sec);
RTC_SetDate(RTC,yr,m,day,wk);
RTC_EnableIt(RTC,(1<<2));     // pps
// NVIC_EnableIRQ(RTC_IRQn);
delay(3000);
print_time();
}

void loop() {
    // compare micros to pps
    int ppm;
    char str[32];

    while(1) {
        ppm = ticks*1000000 - us;
        ppm = 1.e6 * ppm/ (float)us;
        sprintf(str,"%ld %ld %d",ticks,us,ppm);
        Serial.println(str);
print_time();
        delay(5000);
    }
}

void print_time() {
char str[64];

RTC_GetTime(RTC,&hr,&min,&sec);
RTC_GetDate(RTC,&yr,&m,&day,&wk);
sprintf(str,"%d/%d/%d %02d:%02d:%02d",m,day,yr,hr,min,sec);
Serial.println(str);
}


I get no ticks in the RTC_Hander() as the code is.  If i uncomment the NVIC_Enable, it hangs. 

my first try the DUE interrupts etc. 

thoughts?
Logged

Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now seeing the other RTC thread, I incorporated some of that code, and now I'm getting into the RTC_Handler working.  Code reports that RTC is within 3ppm of system clock -- makes me wonder if code is really using the 32Khz crystal ?

Here are some frequency offsets for other MCU crystals, resonators, RTC ...
Code:
  processor    oscillator       spec       measured(ppm)
  avr 328p    16Mhz resonator  0.5%     -1330        uno
               16MHz resonator  0.5%     -1422        breadboard 328p
                16MHz crystal    50ppm    -42          breadboard 328p
  avr 328p    11Mhz crystal     ?             -23          3.74v batteries
  avr 328p    11Mhz crystal     ?       -16          5v
  avr 128      14Mhz             ?       1738         no schematic, resonator?

  DUE         12MHz*x crystal    ?       -4
  DUE RTC     32Khz   crystal    ?       3           work in progress
  maple       8MHz*9 crystal    ?        -5
  propeller   5Mhz*16 crystal   ?        -40         board1 (quickstart)
  propeller   5Mhz*16 crystal   ?        -98         board2 (quickstart)

  ds1307 RTC  32khz   cyrstal  20ppm    23           external "watch" crystal
  ds3132 RTC  32khz   cyrstal   2ppm     1           chronodot TCXO i2c
  ds3134 RTC  32khz   cyrstal   2ppm     1           TCXO SPI

  maple RTC   32khz   cyrstal   20ppm     -41         breadboard 512hz ticks
  bad         32khz   crystal   20ppm   -891019      breadboard 512hz ticks
 
  avr 328  RC  8Mhz     RC      1%       2100         OSCCAL units 3000 ppm
  avr 328p RC  8Mhz     RC      1%       2700         OSCCAL units 5000 ppm
  avr 328p RC  8Mhz     RC      1%       4061         OSCCAL units 4000 ppm
  maple LSI    40KHz    RC     50%     -19659         calibrate with prescale

  beagle      24MHz*x                    -5          ntp drift
  raspberry   19MHz*x                   -16          ntp drift
  dell desk                             -26          ntp drift
  dell laptop                           -14          ntp drift
« Last Edit: December 06, 2012, 06:05:37 pm by mantoui » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@mantoui

Why du you use the RTC creating ticks? The SAM3X has a 24 bit system tick timer. It creates 1 ms ticks. In the arduino software it is already implemented --> millis() // returns the current system time.
« Last Edit: December 07, 2012, 12:45:10 am by M4nu » Logged

Offline Offline
Jr. Member
**
Karma: 9
Posts: 79
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ticks from the RTC were only used to measure frequency accuracy of the 32khz crystal
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh sorry I understand you wrong. Back to your problem. I think you have to clear the second clear bit (RTC_SCCR_SECCLR). This is a small example which i did before:

Code:
void RTC_Handler(void)
{
  uint32_t ul_status = rtc.rtc_get_status(RTC);
  rtc.rtc_get_time(RTC, &hour, &minute, &second);
 
  /* Second increment interrupt */
  if ((ul_status & RTC_SR_SEC) == RTC_SR_SEC)
  {     
    rtc_time = "Time: ";
    rtc_time += String(hour);
    rtc_time += ":";
    rtc_time += String(minute);
    rtc_time += ":";
    rtc_time += String(second);
    Serial.println(rtc_time);
   
    rtc.rtc_clear_status(RTC, RTC_SCCR_SECCLR);
  }
 
  /* Time or date alarm */
  if ((ul_status & RTC_SR_ALARM) == RTC_SR_ALARM)
  {
    Serial.println("Alarm");
    rtc.rtc_clear_status(RTC, RTC_SCCR_ALRCLR);
   
  }
}
Logged

Pages: [1]   Go Up
Jump to: