Oscillators/PCA/Timers/SMBus/UART/SPI
  More than 1 sec precision from RTC. msecs are in need.

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   More than 1 sec precision from RTC. msecs are in need.
AlexeiP
New Member
posted August 15, 2010 02:48 AM     Click Here to See the Profile for AlexeiP     Edit/Delete Message
I use (simplified here) code for capturing RTC ticks. I need all CAPRUTEn register values. But fail to get it (for unknown reasons). Seconds-years read OK, but I need msecs. Is it possible (and how) to get what i need.

RTC0ADR = 0x5; // CAPTURE5 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[0] = RTC0DAT;

RTC0ADR = 0x4; // CAPTURE4 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[1] = RTC0DAT;

RTC0ADR = 0x3; // CAPTURE3 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[2] = RTC0DAT;

RTC0ADR = 0x2; // CAPTURE2 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[3] = RTC0DAT;

RTC0ADR = 0x1; // CAPTURE1 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[4] = RTC0DAT;

RTC0ADR = 0x0; // CAPTURE0 Target the capture registers
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
s_counts_temp.byte[5] = RTC0DAT;

IP: Logged

Scotty
Member
posted August 15, 2010 03:21 AM     Click Here to See the Profile for Scotty     Edit/Delete Message
Hi AlexeiP,

this is too little information. Which device are you using? How do you initialize RTC? ...

Regards,

Scotty

IP: Logged

AlexeiP
New Member
posted August 15, 2010 03:37 AM     Click Here to See the Profile for AlexeiP     Edit/Delete Message
I use c8051F410.Initialization is IMHO OK. I read seconds. But fail to get proper data from CAPTURE0 and CAPTURE1. Thank you for replying.Please, advice for any type of MCU. Any general information on getting all 47 bits of RTC current value.

IP: Logged

AlexeiP
New Member
posted August 15, 2010 03:40 AM     Click Here to See the Profile for AlexeiP     Edit/Delete Message
My read initialization in reply for your request Scotty.

LONG RTC_Read(void){
s_counts_temp.l = 0;
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
RTC0ADR &= 0xF0;
RTC0ADR |= 0x06;

RTC0DAT = 0xD9; // Initiate the transfer to the CAPTUREn
// registers

while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit

// Poll on the RTC0CAP bit until it indicates the transfer to the CAPTUREn
// registers is complete
RTC0ADR = 0x86; // Disable autoreads
while ((RTC0ADR & 0x80) == 0x80); // Poll on the BUSY bit
while ((RTC0DAT & 0x01) == 0x01){
RTC0ADR |= 0x80;
while ((RTC0ADR & 0x80) == 0x80);
}
......
}

IP: Logged

Scotty
Member
posted August 15, 2010 06:18 AM     Click Here to See the Profile for Scotty     Edit/Delete Message
Hi AlexeiP,

I use c8051F410
Okay, now I have a datasheet to work with

Initialization is IMHO OK
Sometimes this is the error But I assume it's really okay...

Please, advice for any type of MCU.
Only possible if any CPU uses the same RTC peripheral. If any CPU means any F41x device, then the peripheral is the same.

I read seconds. But fail to get proper data from CAPTURE0 and CAPTURE1.
Hm... I'm not sure if I understand your RTC_Read() function, for me it doesn't do what the name says... If I'd to read the capture register, my first try would look like this (not tested):


LONG RTC_Read(void){

while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag

RTC0ADR &= 0xF0;
RTC0ADR |= 0x06; // set address for RTC control register
RTC0DAT = RTC0DAT | 0x01; // initiate transfer to capture registers

while(1) {
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
if(RTC0DAT & 0x01 == 0) // check if transfer is complete
break;
}

RTC0ADR &= 0xF0;
RTC0ADR |= 0x00; // set address for Capture0 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture0 register

RTC0ADR &= 0xF0;
RTC0ADR |= 0x01; // set address for Capture1 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture1 register

RTC0ADR &= 0xF0;
RTC0ADR |= 0x02; // set address for Capture2 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture2 register

RTC0ADR &= 0xF0;
RTC0ADR |= 0x03; // set address for Capture3 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture3 register

RTC0ADR &= 0xF0;
RTC0ADR |= 0x04; // set address for Capture4 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture4 register

RTC0ADR &= 0xF0;
RTC0ADR |= 0x05; // set address for Capture5 register
RTC0ADR |= 0x80; // initiate indirect data transfer
while(RTC0ADR & 0x80 == 0x80); // Poll on the busy flag
ucBCap0 = RTC0DAT; // read content of Capture5 register

// put in code for needed modifications for return value
}

Note that according to datasheet setting the register adresses in RTC0ADR is not neccessary since the addresses will increment automatically when accessing the capture registers.
And from my understanding of the RTC module, you cannot read seconds, minutes, etc. directly, instead you have to calculate them by yourself...

Regards,

Scotty

[This message has been edited by Scotty (edited August 15, 2010).]

[This message has been edited by Scotty (edited August 15, 2010).]

IP: Logged

AlexeiP
New Member
posted August 15, 2010 06:20 AM     Click Here to See the Profile for AlexeiP     Edit/Delete Message
Topic is closed. CAPTURE0 and CAPTURE1 read OK.
30.51*((CAPTURE0+CAPTURE1<<8)>>1) provides a needed range of a fraction of a second.

IP: Logged

AlexeiP
New Member
posted August 15, 2010 06:27 AM     Click Here to See the Profile for AlexeiP     Edit/Delete Message
Thank you Scotty a lot. Sure, I'm using increment addressing. My question was in a lot simplified form.
A crusial issue was to set a bit to transmit RTC ticks to CAPTUREn registers for futher read.
Another problem for me was how to deal with CAPTURE0/1 values. All this is solved now. Thank you.

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b