Skip to content

This code example will show how to output a crystal clock on a pin by using two functions available in the code. The system clock will not be changed.

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/attiny817-rtc-crystal-frequency-output-mplab

Repository files navigation

MCHP

Real-Time Counter (RTC) Crystal Frequency Output

The projects in this repository will output the crystal clock on a pin. Two projects are made available to accomplish this. The xosc-clock-out-system-clock project will change the system clock source to the 32.768 kHz crystal and use the clock out pin (PB5). The xosc-clock-out-evsys-rtc project will output the crystal frequency divided by 64 using the Peripheral Interrupt Timer (PIT) and the Event System on pin PA2, without switching the system clock to 32.768 kHz.

These examples are based on the Application Note AN2711 - Real-Time Clock Calibration and Compensation on AVR® Microcontrollers, which can be referred to for a more detailed understanding of the concepts.

Related Documentation

Software Used

Hardware Used

Setup

  1. The crystal on the ATtiny817 Xplained Pro board is by default not connected to the TOSC pins, as they are used for UART communication. To connect the pins, remove resistors R307 and R308 and place them on the footprints of R312 and R313. Refer to ATtiny817 Xplained Pro User's Guide for more information on how to do this.

XOSC Clock Out System Clock

This project changes the system clock source to the 32.768 kHz crystal and use the clock out pin (PB5).

MCC Setup

CLKCTRL

Change the Clock Source Selection to 32.768kHz external crystal oscillator and disable the Prescaler enable. Enable System clock out, Enable 32.768kHz Crystal Oscillator Control A and Run standby 32.768kHz Crystal Oscillator Control A. Set Crystal startup time to 64K.

XOSC Clock Out Evsys RTC

This project will output the crystal frequency divided by 64 using the Peripheral Interrupt Timer (PIT) and the Event System on pin PA2, without switching the system clock to 32.768 kHz. With this setup, the system clock can be different from the outputed clock.

MCC Setup

An overview of the MCC setup is shown in the image below:

Clock Controller (CLKCTRL)

Enable Enable 32.768kHz Crystal Oscillator Control A and Run standby 32.768kHz Crystal Oscillator Control A. Set Crystal startup time to 64K.

Real-Time Counter (RTC)

In the RTC peripheral, disable Enable RTC and OverFlow Interrupt Enable as the PIT timer is the only one used and the RTC and PIT timers can be enabled seperately. Set the RTC Clock Source Selection to 32KHz Crystal OSC. Enable PIT Enable.

Event System (EVSYS)

In the EVSYS peripheral connect GENERATORS>ASYNCCH3>PIT_DIV64 to the CHANNELS>ASYNCCH3, then further connect CHANNELS>ASYNCCH3 to USERS>Event Out 0. MCC will then connect that to the PA2 pin as output.

Operation

  1. Connect the board to the PC.

  2. Download the zip file or clone the example to get the source code.

  3. Open the project in MPLAB X IDE.

  4. Build the solution and program the ATtiny817.

Conclusion

These examples have now illustrated how you can output the crystal clock on a pin.

About

This code example will show how to output a crystal clock on a pin by using two functions available in the code. The system clock will not be changed.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published