# Real-Time Clock MCP79410 Pmod Controller (VHDL)

**URL:** <https://forum.digikey.com/t/real-time-clock-mcp79410-pmod-controller-vhdl/13136>\
**Category:** Logic Design\
**Tags:** development-boards-kits-programmers, evaluation-boards, digilent-inc, tech-tips\
**Created:** [March 29, 2021, 7:52pm UTC](https://forum.digikey.com/t/real-time-clock-mcp79410-pmod-controller-vhdl/13136 "2021-03-29T19:52:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_1767](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Scott\_1767](https://forum.digikey.com/u/Scott_1767)\
**Post date:** [March 29, 2021, 7:52pm UTC](https://forum.digikey.com/t/real-time-clock-mcp79410-pmod-controller-vhdl/13136/1 "2021-03-29T19:52:32Z")

</div>

[Logic Home](https://forum.digikey.com/t/logic-home-table-of-contents/12507)

 

# Code Downloads

Real-Time Clock MCP9410 Pmod Controller (top level file): [pmod\_real\_time\_clock.vhd](https://forum.digikey.com/uploads/short-url/ur29P0JBWk8HsDHojgUgro6cPzw.vhd) (16.0 KB)

I2C Master (must be included in project): [i2c\_master.vhd](https://forum.digikey.com/uploads/short-url/eTzT1qKMVrvoZN2gh0DFKWRg0kQ.vhd) (14.1 KB)

# Features

- VHDL source code of a streamlined interface to [Digilent’s Pmod RTCC](https://www.digikey.com/en/products/detail/digilent-inc/410-218/4090090?s=N4IgTCBcDaIIxgBwDYC0c4FYAMqByAIiALoC%2BQA) (Pmod for Microchip’s [MCP79410](https://www.digikey.com/en/products/filter/clock-timing-real-time-clocks/690?s=N4IgTCBcDaILIGEAKB2AnAFgIwAYQF0BfIA) real-time clock/calendar)
- Continually outputs latest clock and calendar data on parallel interfaces
- Simple interface for user to set the clock and calendar
- Handles all I2C communication with the RTCC Pmod
- Configurable system clock rate

# Introduction

This details a VHDL component that handles interfacing an FPGA to Digilent’s Real-Time Clock/Calendar (RTCC) Pmod, shown in Figure 1. Figure 2 illustrates a typical example of this RTCC Pmod Controller integrated into a system. As shown, the RTCC Controller connects to the Pmod ports and executes transactions to both set the time and date on the Pmod and collect ongoing time and date values. The time and date outputs are continually updated and presented on simple parallel interfaces.

 ![MFG_410-218](https://global.discourse-cdn.com/digikey/original/2X/7/7634ada0f3ca6dc281b412073e6c2dab00b4d7da.jpeg)

**Figure 1.** Digilent Real-Time Clock/Calendar Pmod

 ![block_diagram](https://global.discourse-cdn.com/digikey/original/2X/a/aca397491f29a73d88f39bb1ccd12046675a9573.jpeg)

**Figure 2.** Example Implementation

# Theory of Operation

The RTCC Pmod Controller consists primarily of a state machine and an I2C Master component.

## State Machine

The design uses the state machine depicted in Figure 3 to implement its operation. Upon start-up, the component immediately enters the _start_ state. It remains in this state for 100ms to ensure the Pmod has ample time to power-up. It then proceeds to the _route_ state. If the user logic has latched in new clock settings by toggling the _set\_clk\_ena_ signal, it routes to the _set\_clock_ state. Otherwise, it routes to the _read\_clock_ state. The _set\_clock_ state writes the new user supplied clock settings to the RTCC on the pmod and then returns to the _route_ state. The _read\_clock_ state retrieves the current time and date from the RTCC, then progress to the _output\_result_ state, where it outputs the time and date to the corresponding output data ports. Although not shown, resetting the component at any time returns it to the _start_ state.

The RTCC Pmod Controller activates the RTCC’s on-board oscillator in the _set\_clock_ state. This begins the time-keeping process. Therefore, the output reads all zeros until the user sets the clock for the first time.

 ![state_diagram](https://global.discourse-cdn.com/digikey/original/2X/9/94a692edb4a2b9fb81bd697521ad51a8e27c8910.jpeg)

## I2C Master

During the _set\_clock_ and _read\_clock_ states, the state machine controls an I2C Master component to communicate with the MCP79410 RTCC on the Pmod. Documentation for the I2C Master is available [here](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=10125324).

# System Clock Frequency

In the entity, the generic parameter _sys\_clk\_freq_ must be set to the frequency (in Hz) of the system clock provided to the RTCC Pmod Controller on its _clk_ port.

# I2C Pull-Up Resistors

Unlike most of Digilent’s Pmod boards, the I2C pull-up resistors shown in Figure 2 above are not included on the Pmod RTCC. The I2C bus will not operate correctly without them.

The user can solve this problem by wiring 2.2 kΩ resistors into the circuit as shown.

Several of Digilent’s other Pmods use I2C, include these resistors, and also include connectors to plug additional Pmods into the same I2C bus. If this RTCC Pmod is used in conjunction with one those Pmods, the user can automatically take advantage of the pull-up resistors already included on those boards and no further action is needed.

# Port Descriptions

Table 1 describes the RTCC Pmod Controller’s ports.

**Table 1.** Port Descriptions

 ![port_descriptions](https://global.discourse-cdn.com/digikey/original/2X/b/b8640d5b3f5b7ba1af544a7f63d085f67de46c6a.jpeg)

# Connections

This Pmod has an 8-pin connector. Table 2 provides the pinout for this connector. The RTCC Pmod Controller’s ports need to be assigned to the FPGA pins that are routed to this connector as listed. The two rows of the J1 connector are tied together on the Pmod board, so only one side needs to be connected to the FPGA.

**Table 2.** RTCC Pmod Pinout and Connections to RTCC Pmod Controller

 ![connections](https://global.discourse-cdn.com/digikey/original/2X/3/3f222a0ba699df9475e7b9a96c37afd1f3bee301.jpeg)

# Reset

The _reset\_n_ input port must have a logic high for the RTCC Pmod Controller component to operate. A low logic level on this port asynchronously resets the component. During reset, the component aborts the current transaction with the Pmod and clears all of the time and date clock outputs, i.e., _seconds_, _minutes_, _hours_, _am\_pm_, _weekday_, _day_, _month_, and _year_. It also clears the _i2c\_ack\_err_ output. It does not reset the RTCC itself, so the RTCC will continue tracking the time and date from its last setting. Once released from reset, the RTCC Pmod Controller restarts its operation. It resumes collecting time and date data from the RTCC and outputting the result.

# Conclusion

This RTCC Pmod Controller is a programmable logic component that interfaces to Digilent’s Pmod RTCC (Real-Time Clock/Calendar Pmod). It handles all communication with this Pmod to allow the user to set the time and date, start the timekeeping, and continuously output the updated time and date back to the user.

# Related Topics

[I2C Master (VHDL)](https://www.digikey.com/eewiki/pages/viewpage.action?pageId=10125324)
