Editor's Choice


Keeping time to save money in smart meters

14 June 2017 Editor's Choice DSP, Micros & Memory

Mary Tamar Tan from Microchip Technology explains how a real-time clock and calendar module can reduce component count and cut programming costs in smart meters and other applications.

Reducing both the component count and user programming costs are goals in almost any design. Both of these desires can be addressed by using a real-time clock and calendar (RTCC) module that provides accurate time and date keeping and is optimised for low power usage with little or no intervention from the CPU. This can provide benefits in applications such as digital alarm clocks and smart energy meters, something becoming increasingly important as more and more countries role out smart grids.

Available with Microchip PIC microcontrollers, the module is a 100-year clock and calendar with automatic leap year detection. The range goes from the first second of 1 January 2000 until a second before midnight on 31 December 2099 and uses the 24-hour rather than the AM and PM 12-hour format, with visibility down to 0,5 s.

The alarm is configurable for 0,5, 1 and 10 s, 1, 10 and 60 min, or day, week and month. Figure 1 shows the block diagram of the module. It uses a separate clock source coming from an external crystal oscillating at 32,768 kHz from the secondary oscillator (SOSC) of the T1OSC for some devices. This lets the module continue running even when the CPU clock is disabled during deep sleep mode.

Figure 1. Block diagram of the RTCC module.
Figure 1. Block diagram of the RTCC module.

The 1:16384 clock prescaler provides the 0,5 s visibility to the user, which in turn allows the RTCC timer to increment the appropriate second, minute, hour, day, month and year values stored in the RTCVALx registers. These values are compared with the user-set alarm values to trigger an alarm interrupt whenever a match occurs.

The alarm values are stored in the ALRMVALx registers. Alarm masks are used to set the time interval between each alarm event if multiple periodic alarms are needed. The RTCC pin can output either the seconds clock or an alarm pulse at half the frequency of the alarm, depending on the configured settings. To simplify the firmware, the register interface for the RTCC and alarm values are implemented using binary coded decimal (BCD) format.

Peripheral configuration

The user configures the time by writing the required year, month, day, hour, minutes and seconds to the timer registers. However, the RTCC enable bit (RTCEN) and the RTCVALH and RETCVALL registers can only be written to when the RTCC value registers write enable bit (RTCWREN) is set to one, otherwise any write to these registers will be ignored. The RTCC timer (RTCVALx) and alarm timer (ALRMVALx) registers can only be accessed through corresponding register pointers. Every write or read to the RTCVALH register decrements the RTCC pointer value by one until it reaches 00.

When the RTCC output pin is enabled, the user can choose either to output the seconds clock or an alarm pulse, operating at half the frequency of the alarm. For more accurate timing and to ensure uninterrupted operation of the RTCC even in deep sleep, the SOSC is recommended as the peripheral’s clock source. Once the RTCC is enabled, the timer proceeds with the count from the configured starting point. Also, to avoid accidental writes to the RTCC timer register, it is advised that the RTWREN bit be cleared when not writing to the register.

The alarm feature is configurable from half a second to one year and can be repeated as desired by the user. Every read or write to the ALRMVALH register decrements the alarm pointer value by one.

Battery backup mode

A feature of the RTCC module is its ability to continue operating from a backup battery if there is a power loss that would otherwise affect its timing accuracy. This is VBAT mode, and the PIC microcontrollers have both MCU power reduction and uninterrupted operation of the RTCC through the VBAT hardware-based power mode. This mode uses a backup power source connected to the VBAT pin as shown in Figure 2.

Figure 2. VBAT mode topology.
Figure 2. VBAT mode topology.

An on-chip power switch detects the power loss from the VDD and connects the VBAT pin to the retention regulator. This provides power at 1,2 V to maintain the retention regulator, as well as the RTCC, with its clock source if enabled and the deep sleep general purpose registers (DSPGPRx). The RTCC continues to operate as if there was no power interruption.

The device automatically wakes from VBAT mode once VDD is restored. Wake up from this mode is identified by checking the state of the VBAT bit. If this is set when the device is awake and starting to execute the code from the reset vector, it indicates that the exit was from VBAT mode. To identify future VBAT wake-up events, the bit must be cleared in software.

One of the Microchip demonstration boards that supports the VBAT operation is the LCD Explorer demonstration board. It is provided with a battery holder for a CR2032 3V button cell.

Digital alarm clocks

Figure 3 shows a sample implementation of the RTCC with the LCD driver and the capture-compare-PWM (CCP) modules for a digital alarm clock application.

Figure 3. Digital alarm clock implementing the RTCC module.
Figure 3. Digital alarm clock implementing the RTCC module.

The SOSC provides the clock for the RTCC module. If the RTCC pin is configured to output the seconds clock, this allows LED D1 to blink once every second. The values in the RTCVALx registers are manipulated by firmware to be displayed on LCD1 through the LCD driver module.

The alarm interrupt triggers the CCP module to generate a pulse-width modulated output that activates the P1 piezo buzzer on every alarm event. The duration of the alarm is controlled through firmware.

The S1, S2 and S3 pushbutton switches are used to set the initial RTCC time and date as well as the alarm settings. One of the buttons can also be used to trigger the start of the RTCC count.

There are several Microchip demonstration boards that can be used for this application. Several PIC microcontrollers with the RTCC module also have an internal LCD driver module that can directly drive the LCD glass while others can use the MSSP module to communicate with the LCD while displaying the time and date.

Energy meters

In an energy metering device, the RTCC module can be integrated with other peripherals such as the analog-to-digital converter (ADC) and LCD driver modules. MCUs for metering applications should have a high-resolution ADC for voltage and current measurements, must consume low power, be able to operate from a battery to maintain uninterrupted operation of the RTCC, and have an EEPROM for data logging and storage of calibration data. Microchip has a number of 8-bit PIC microcontrollers that meet these requirements.

The periodic auto-adjust feature in the RTCC module can be used with the ADC module to perform software temperature compensation for a more accurate time. These microcontrollers also have a built-in LCD module that can directly drive an LCD to show the real-time energy consumption. And they have an external interface for a battery source through the VBAT pin, which lets the RTCC run continuously during a power loss.

Conclusion

The RTCC modules of PIC microcontrollers provide the necessary features to maintain accurate time and date keeping. They are easy to configure, provide automatic error calibration and have very low power consumption. Since the RTCC is usually not implemented by itself, its usefulness is better appreciated when integrated with other peripherals. PIC microcontrollers provide versatile choices of peripherals that can be implemented with the RTCC module for digital alarm clocks, energy meters and other applications.



Credit(s)



Share this article:
Share via emailShare via LinkedInPrint this page

Further reading:

Solving South African power problems with locally built intelligence
Editor's Choice Power Electronics / Power Management
Smart metering infrastructure in South Africa remains patchy. The rollout has been slow, coverage is inconsistent, and for the most part, granular per-unit measurement simply does not exist.

Read more...
From the editor's desk: The art of measuring the truth
Technews Publishing Editor's Choice News
All electronic measurements are a lie. The trick is making the lie as small as possible.

Read more...
Engineering for failure: why resilient telemetry matters more than perfect connectivity
Editor's Choice Telecoms, Datacoms, Wireless, IoT
One of the biggest assumptions in modern tracking systems is that connectivity will always be available. From an engineering perspective, this creates an interesting problem.

Read more...
Lesley Havenga: Building partnerships for Africa’s electronics future
Editor's Choice News
As Würth Electronik expands its footprint across South Africa and the broader sub-Saharan region, Havenga’s blend of manufacturing expertise, supply chain knowledge, and people-centred leadership appears well suited to the task.

Read more...
Generating negative voltages from a positive supply
Altron Arrow Editor's Choice Passive Components
It is common for IoT devices, industrial sensors, meters, and medical equipment to require both a positive and negative voltage, and this article explains the options available to produce a negative rail from a positive rail supply.

Read more...
PEAK’s first automotive Ethernet solution
Industrial Data Xchange (IDX) Editor's Choice Telecoms, Datacoms, Wireless, IoT
The PAE-Media Converter is a robust and compact device designed to connect Automotive Ethernet (100BASE-T1 or 1000BASE-T1) with standard Ethernet (100BASE-TX or 1000BASE-T) networks.

Read more...
EMC limits and levels
Altron Arrow Editor's Choice Circuit & System Protection
As soon as electronics and electrical systems started interfering with each other, the world had to come to some consensus. Considering physics is universal and does not care about what country electrical/electronic products are used in, it should be the same everywhere, right? It is nearly there, but not quite.

Read more...
Sigfox SA powers smart connectivity
Editor's Choice Telecoms, Datacoms, Wireless, IoT
Sigfox South Africa is carving out a unique role, delivering low-power, wide-area network connectivity designed specifically for Internet of Things applications.

Read more...
Seeing through the noise
RF Design Editor's Choice Telecoms, Datacoms, Wireless, IoT
How Adaptive Long Coherent Integration (ALCI) delivers superior measurement and positioning performance where conventional receivers fall short.

Read more...
Case Study: Turning data into insight
Hamamatsu Photonics UK Editor's Choice Opto-Electronics
Hamamatsu Photonics’ InGaAs PIN photodiode detector has proven consistent, reliable, and robust for more than a decade, helping Axetris to deliver stable, repeatable measurements.

Read more...









While every effort has been made to ensure the accuracy of the information contained herein, the publisher and its agents cannot be held responsible for any errors contained, or any loss incurred as a result. Articles published do not necessarily reflect the views of the publishers. The editor reserves the right to alter or cut copy. Articles submitted are deemed to have been cleared for publication. Advertisements and company contact details are published as provided by the advertiser. Technews Publishing (Pty) Ltd cannot be held responsible for the accuracy or veracity of supplied material.




© Technews Publishing (Pty) Ltd | All Rights Reserved