Preface
Real-time clocks (RTCs) can be applied to a variety of fields - from clocks to time-stamping events, and even to generating events. In the fields of communication engineering, power automation, industrial control, and other fields with a high degree of automation, many devices are unattended in most cases, and it is hoped that the time of the failure and related information can be recorded for specific analysis. There are many dedicated RTC devices on the market, which often have poor flexibility and low system integration. The MSP430F11X series of microcontrollers have the advantages of low cost, low current consumption, flexible and simple use, and good scalability, making it an ideal substitute for dedicated RTC devices in some special occasions.
This system uses TI's ultra-low power 16-bit microprocessor - MSP430F111, which has extremely low power consumption, strong anti-interference ability and high cost performance. The whole system can work for a long time with only two ordinary batteries (working voltage is 3V), without other power supply, which greatly broadens the scope of application.
System working principle and implementation
The main difficulty of this system is how to generate a stable system clock. All MSP430 devices contain both a digitally controlled RC oscillator and a crystal oscillator. Generally, the RC oscillator is used for the CPU clock, while the crystal oscillator is used for peripheral devices. In real-time clock applications, the crystal oscillator can be used as the clock source for the timer/counter used as the time base. Therefore, there is no instability problem that is common to RC oscillators.
The process of making an MSP430 into an RTC is simple, including a timer/counter to provide 1s interrupts and a small CPU subroutine to count the interrupts. Between interrupts, the CPU can be in sleep mode or perform other functions. The actual operation process should also include an interface subroutine for the host processor to extract time from the MSP430 RTC, as well as other system functions such as battery monitoring, system monitoring, communication interfaces, etc.
The MSP430F111 is a very simple and inexpensive device in the MSP430F11X series, with 14 general-purpose I/O pins, 2 16-bit timers, 2KB flash memory, 128B RAM and a basic clock module.
Clock Generation
The RTC uses the LFXT1 oscillator with a 32768Hz crystal in LF mode to generate the clock. The output of the LFXT1 oscillator is used to provide ACLK, which is then used as the clock source for the timer/counter, which in turn is used as the time base for the RTC.
The DCO generates the CPU clock MCLK. In fact, the CPU and peripheral device timer/counter run asynchronously. As long as the CPU can calculate each interrupt from the timer/counter before the next interrupt arrives, the accuracy of the RTC will not be affected.
Timer/Counter Selection
MSP430F111 contains 2 timers: watchdog timer and timer A. Timer A is used as a time base and is designed to count continuously and provide an interrupt every 1s. Since timer A uses ACLK as its clock source, and the operating crystal frequency of ACLK is precisely 32768Hz, timer A can simply count to 32768 and then start to roll over to 0, giving an interrupt every time it counts to 32768. The CPU can simply calculate the interrupt from timer A.
External Interfaces
Because various RTC interfaces are now easily available, most of them can be applied to MSP430, such as I2C, parallel interface, UART and serial interface. TI has ready-made program code modules to implement the interface with MSP430 and are easy to integrate. In this way, building a complete RTC based on MSP430 becomes a simple matter of choosing an interface.
Circuit Description
Figure 1 is the circuit diagram of the RTC, the only external component required here is a 32768Hz crystal.
Figure 1 RTC circuit diagram [page]
Current Consumption
The typical current consumption of the MSP430F111 in normal working mode (3V, 1MHz) is 330μA. The typical current consumption in low power mode (sleep mode) is 1.5μA (3V). The device wakes up from low power mode in less than 6μs, and the clock program can be executed in about 130μs. Due to the extremely low current consumption and the extremely short time in active mode, using the 'F111 as an RTC consumes only very little current, so its battery life is the longest.
The accuracy of the crystal and
the accuracy of the selected RTC depends only on the accuracy of the crystal selected for the crystal oscillator. We can buy the appropriate crystal based on the accuracy we expect.
The accuracy of a crystal is primarily affected by two factors: the frequency tolerance of the crystal and the specified load capacitance.
The tolerance of the crystal is very obvious. The smaller the tolerance of the crystal frequency, the more accurate the RTC will be.
The specified load capacitance of the crystal also affects the accuracy of the RTC. The load capacitance of the crystal is the sum of the capacitance required by the crystal, not the sum of the capacitance provided by the crystal. The crystal needs appropriate load capacitance to start oscillating at the specified frequency. The 32768Hz oscillator used in all MSP430 devices has integrated a load with a rated capacitance of 12pF. This provides a full 12pF load for the crystal, which means that in order to obtain the best RTC accuracy, the connected 32768Hz crystal must be specified to use a 12pF load capacitance.
In applications where tighter RTC tolerance is required, a more adjustable capacitor can be used that is adjusted during manufacturing.
Higher grade ceramic (i.e. NP0 type) capacitors and polyester film capacitors are better suited for timing applications because they have lower dielectric losses and better temperature coefficients than general purpose ceramic capacitors.
The scalable
MSP430F111 is an extremely low power, low cost microcontroller that is ideal for real-time clock devices. One of the main advantages of using the MSP430 as an RTC is its scalability compared to dedicated RTC devices. All MSP430x11x devices include a 16-bit RISC CPU, 16-bit watchdog timer, 16-bit Timer A (with 3 capture/compare registers and analog comparator), a minimum of 128B of RAM, a minimum of 2Kb of ROM, and a minimum of 14 pins of general purpose I/O ports. It is clear that the MSP430 can provide flexibility that other dedicated RTCs cannot match.
In addition, the Timer A module can provide slope A/D conversion, PWM output and UART working speed up to 115200 baud rate. The watchdog timer can also be used as a simple timer, and the general I/O ports and all peripherals have expandable interrupt capabilities. [page]
Software Design
The RTC application code is quite simple and includes an initialization subroutine, a main loop, a clock counting subroutine to calculate hours, minutes and seconds, and an interrupt service subroutine to handle the 1s interrupt from timer A.
The initialization routine initializes the different parts of the MSP430. The watchdog timer is disabled and the Timer A module is configured to count continuously from 0 to 32768 and give an interrupt each time it reaches 32768. The basic clock module is also set.
The main loop is an infinite loop. Whenever timer A issues an interrupt, it calls the clock counting subroutine, otherwise it puts the CPU into sleep mode. When the CPU is asleep, timer A continues to count.
The Timer A Interrupt Service Routine (ISR) processes the Status Register (SR) bits that are pushed onto the stack before entering the ISR. This allows the CPU to be in active mode instead of sleep mode just after returning from the ISR. The ISR also clears the Timer A interrupt flag.
The clock counting subroutine counts each timer A interrupt as 1 second.
Source Program
START | MOV | #Stack,SP | |
CALL | #Setup | ; Initialization settings | |
Mainloop | BIS | #LPM3,SR | ; CPU enters low power mode 3 |
CALL | #Clock | ; Enter the clock calculation after interrupt processing | |
JMP | Mainloop | ; Enter power saving mode again | |
Clock | SETC | ; Set the carry bit | |
DADC.b | SECOND | ; Second plus 1 | |
CMP.b | #060d,SECOND | ; Determine whether it is full 1 minute | |
JLO | Clockend | ; If dissatisfied, jump out | |
CLR.b | SECOND | ; Clear the seconds counter | |
DADC.b | MINUTE | ; Points plus 1 | |
CMP.b | #60d,MINUTE | ; Determine whether it is full 1 hour | |
JLO | Clockend | ; If dissatisfied, jump out | |
CLR.b | MINUTE | ; Clear the minute counter | |
DADC.b | HOUR | ; hour plus 1 | |
CMP.b | #024d,HOUR | ; Determine whether it is full 24 hours | |
JLO | Clockend | ; If dissatisfied, jump out | |
CLR.b | HOUR | ; Clear the hour counter | |
Clockend | RET | ||
; Set up modules and control registers | |||
Setup | MOV | #WDTPW+WDTHOLD,&WDTCTL | ; Disable watchdog |
MOV.b | #08Ch,&BCSCTL1 | ; Set up the oscillator and clock control registers | |
MOV.b | #000h,&BCSCTL2 | ; Select DCOCLK as the MCLK clock source | |
SetupTA | MOV | #0106h,&TACTL | ; Set timer A control register |
MOV | #CCRE0,&CCTL0 | ; Interrupt enable | |
MOV | #8000h,&CCR0 | ; Set the time interval | |
BIS | #10h,&TACTL | ; Start TA and start count-up mode | |
ClearRAM | MOV.b | #00h,SECOND | ; Clear the seconds, minutes and hours counters |
MOV.b | #00h,MINUTE | ||
MOV.b | #00h,HOUR | ||
EINT | ; Interrupt enable | ||
RET | |||
Timer A Interrupt Service Routine (ISR) | |||
TAint | BIC | #SCG0+CPUOFF,0 (SP) | ; Processing status register (SR) bits |
BIC | #TAIFG,&TACTL | ; Clear the timer A interrupt flag | |
RETI |
Conclusion
The whole system has a simple structure, strong scalability, and low cost (one piece of 'F111 is only more than 10 yuan), and the system is in low power consumption mode most of the time. Therefore, this system is suitable for implementing a real-time clock in unattended situations and harsh environments without considering power supply issues.
Reference
1 Hu Dake MSP430 Series FLASH Ultra-Low Power 16-bit Microcontroller Beijing University of Aeronautics and Astronautics Press 2001
Previous article:Design of MSP430 Mixed Voltage and Logic System
Next article:D/A conversion based on MSP430 Timer_B
Recommended ReadingLatest update time:2024-11-16 17:34
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 2022 Digi-Key Innovation Design Competition + ESP32-S2-KALUGA1 Unboxing
- Defensive C Programming in Embedded Development
- MSP CapTIvate MCU Development Kit Evaluation Model
- Please tell me, what is the difference between NB-IOT module and NB-IOT chip, what additional features and functions does the former have over the latter?
- 【Home treasure】 esp32s2 freertos communication between tasks Event Groups
- View Circuit-ADC and System (2)
- Hi3559A Flying Camera Solution
- I would like some advice on troubleshooting the mnemonic reading device in the analog circuits book?
- A brief explanation of FPGA static timing analysis
- [TI star products limited time sale] + Buy, buy, buy!