RTC real-time clock

Source: Internet
Author: User

Instructor song,Hua Qing vision embedded college lecturer.

1.1 Introduction to rtc

In an embedded system, RTC is usually used to provide reliable system time, including hour, minute, second, and year, month, and day, it is also required that the system work properly when it is shut down (usually powered by a backup battery ). Its Peripheral does not require too much auxiliary electrical channels. Typically, it only requires a high-precision 32.768khz crystal and resistance capacitor, as shown in 10-8.


Figure 10-8 RTC external circuit

1.2 RTC Controller

The real-time clock (RTC) unit can be powered by a backup battery, so it can continue to work even if the system power is off. RTC can use the strb/ldrb command to send eight BCD code data to the CPU. The BCD data includes seconds, minutes, hours, dates, weeks, months, and years. The RTC Unit provides a clock through an external 32.768khz crystal oscillator. RTC provides the timed alarm function, as shown in Figure 10-9. RTC controller function description:


Figure 10-9 RTC Controller

Clock data adopts BCD encoding.
Automatically processes the year, month, and day of a leap year.
With the alarm function, when the system is shut down, an alarm is triggered and interrupted.
With independent power input.
Provides millisecond-level clock interruption, which can be used as the kernel clock of the embedded operating system.

1.3 RTC controller register details

The register description is shown in Table 10-9.

Table 10-9 RTC control registers

Rtccon Bit Description Reset Value
Retained [31: 9] Retained 0
Ticen [8] Tick Timer
0 = disabled
1 = Enable
0
Ticcksel [7: 4] Select the clock source when the timer is tick
4 'b0000 = 32768Hz 4 'b0001 = 16384Hz
4 'b0010 = 8192Hz 4 'b0011 = 4096Hz
4 '0100 = 2048Hz 4 'b0101 = 1024Hz
4 'b0110 = 512Hz 4 'b0111 = 256Hz
4 'b1000 = 128Hz 4' b1001 = 64Hz
4 'b1010 = 32Hz 4 'b1011 = 16Hz
4 'b1100 = 8Hz 4' b1101 = 4Hz
4 'b1110 = 2Hz 4 'b1111 = 1Hz
4 'b0000
Clkrst [3] Reset RTC clock count
0 = No Reset
1 = Reset
0
Cntsel [2] BCD count Selection
0 = allocated BCD count
1 = Reserved
0
Clksel [1] BCD clock Selection
0 = xtal 1/divided clock
1 = reserved (xtal frequency Supply)
0
Rtcen [0] RTC control enabling
0 = disabled
1 = Enable
0

The BCD value register description is shown in Table 10-10.

Table 10-10 BCD value registers

Bcdsec Bit Description Reset Value
Retained [31: 7] Retained -
Secdata [6: 4] BCD Value
0 ~ 5
-
[3: 0] 0 ~ 9 -

1.4 experiment 11 real-time clock RTC Experiment

1.4.1 tutorial Purpose

Understand the hardware control principle and design method of RTC;
Master the RTC module programming method (timing, alarm, and time slice) of s5pv210 processor );

1.4.2 Experiment Principles

The real-time clock (RTC) unit can work with a backup battery when the system power is off. RTC can use the strb/ldrb arm operation to send 8-bit binary Exchange Code (BCD) value data to the CPU. The data includes the time information of the year, month, day, week, hour, minute, and second. According to the working principle of RTC and the introduction of RTC registers. You can read and write the corresponding registers to implement the modification time and the actual time.

1.4.3 experiment content

1. RTC design steps
1) after the system is reset, it must be set to 1 in the RTC control program to enable data read/write.
2) set the current RTC clock time.
3) before power loss, the rtcen bit should be cleared to 0 to prevent accidental writing to the RTC register.
4) read the data of related registers such as year, month, and day to display on the screen.

2. Visit the door software program design

The following code implements the function of setting and reading RTC by year, month, day, hour, minute, and second.

# Include "s5pv210. H"

Void rtc_init (void)
{
RTC. rtccon = 0x01; // The Clock controller enables RTC control.
RTC. bcdsec = 0x59; // second Controller
RTC. bcdmin = 0x56; // minute Controller
RTC. bcdhour = 0x16; // Time Controller
RTC. bcdday = 0x12; // daily Controller
RTC. bcddayweek = 0x05; // controller for the week
RTC. bcdmon = 0x10; // monthly Controller
RTC. bcdyear = 0x14; // year Controller

RTC. rtccon = 0; // The Clock controller enables RTC control.
}

/******************** Main function ***************** ********************/
Int main ()
{
Unsigned int I = 0;

Uart0_init (); // serial port Initialization
Rtc_init (); // initialize rtc

While (1) // print the clock cyclically
{
Printf ("year 20% X: Mon % x: Date % x: day % d", RTC. bcdyear, RTC. bcdmon, RTC. bcdday, RTC. bcddayweek );
Printf ("hour % x: min % x: sec % x \ n", RTC. bcdhour, RTC. bcdmin, RTC. bcdsec );
For (I = 0; I <1500000; I ++ );
}
Return 0;
}

1.4.4 experiment steps

For the tutorial procedure, see section 5.4.4 or 7.3.4,

Source code path of the CD-Rom experiment: Tsinghua vision-cortexa8 materials 2 \ Experiment materials \ 1. Arm architecture and Interface Technology Section \ 14-rtc

1.4.5 Experimental Phenomenon

Debug debugging click the run button. In the receiving area of the debugging assistant, you can view the terminal printing information. The second data of the RTC clock is increased in one second.


Figure print real-time clock Information

Source:Huaqing vision embedded College,Original article address:Http://www.embedu.org/Column/Column867.htm

For more information about embedded systems, seeHua Qing visionInstructor blog>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.