3.26.2 Clock Driver

Overview

The Clock peripheral helps the user to easily configure System Clock frequency and other Clock Generator frequencies using MCC Melody User Interface.

Features

Clock Generators

  • Supports multiple Clock Generators
  • Each Clock Generator has
    • Selectable Clock Source
    • Clock Divider block
    • Fail safe clock monitors
    • A backup clock source

Phase Locked Loop(PLL) Blocks

  • Supports multiple PLL Blocks
  • Selectable Clock Source
  • Fail safe clock monitors
  • A backup clock source
  • PLL OUT divider output
  • PLL VCO divider output

Clock Generator and PLL Clock Sources

  • RC oscillator (FRC)
  • RC backup oscillator (BFRC)
  • Internal Low Power RC Oscillator(LPRC)
  • PLL OUT output
  • PLL VCO divider output
  • External/Primary Oscillator
  • External Reference Input (REFI pin)

3.26.2.1 Module Documentation

3.26.2.1.1 Clock Driver

Clock configurator driver for System and Peripheral Clock using dsPIC MCUs.

Module description

Clock configurator driver for System and Peripheral Clock using dsPIC MCUs.

Version:

PLIB Version 1.1.0-rc.6

Definitions
Functions
  • void CLOCK_Initialize (void)

    Initializes all the CLOCK sources and clock switch configurations.

  • static uint32_t CLOCK_GeneratorFrequencyGet (enum CLOCK_GENERATOR generator)

    This inline function returns clock generator frequency in Hz.

  • static uint32_t CLOCK_FailStatusGet (void)

    This inline function returns clock generator failure status.

  • void CLOCK_CombinedClockFailCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CLOCK CombinedClockFail event.

  • void CLOCK_CombinedClockFailCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CLOCK_CombinedClockFailCallbackRegister.

Definition Documentation

CLOCK_FastPeripheralFrequencyGet

#define CLOCK_FastPeripheralFrequencyGet( ) ((uint32_t)CLOCK_SystemFrequencyGet())

This macro is used to read the Fast Peripheral Clock (1:1) Frequency configured in the MCC Melody User Interface  

CLOCK_InstructionFrequencyGet

#define CLOCK_InstructionFrequencyGet( ) ((uint32_t)CLOCK_SystemFrequencyGet())

This macro is used to read the Instruction Clock (FCY) Frequency configured in the MCC Melody User Interface.

CLOCK_SlowPeripheralFrequencyGet

#define CLOCK_SlowPeripheralFrequencyGet( ) ((uint32_t)CLOCK_SystemFrequencyGet() / (uint32_t)4)

This macro is used to read the Slow Peripheral Clock (1:4) Frequency configured in the MCC Melody User Interface  

CLOCK_StandardPeripheralFrequencyGet

#define CLOCK_StandardPeripheralFrequencyGet( ) ((uint32_t)CLOCK_SystemFrequencyGet() / (uint32_t)2)

This macro is used to read the Standard Peripheral Clock (1:2) Frequency configured in the MCC Melody User Interface  

CLOCK_SystemFrequencyGet

#define CLOCK_SystemFrequencyGet( ) (8000000UL)

This macro is used to read the System clock (FOSC) Frequency configured in the MCC Melody User Interface.

Function Documentation

CLOCK_CombinedClockFailCallback()

void CLOCK_CombinedClockFailCallback (void )

This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

CLOCK_CombinedClockFailCallbackRegister.

Parameters:
none
Returns:

none  

CLOCK_CombinedClockFailCallbackRegister()

void CLOCK_CombinedClockFailCallbackRegister (void(*)(void) handler)

This function can be used to override default callback and to define custom callback for CLOCK CombinedClockFail event.

Parameters:
in handler

- Address of the callback function.  

Returns:

none  

CLOCK_FailStatusGet()

inline static uint32_t CLOCK_FailStatusGet (void )

This inline function returns clock generator failure status.

Precondition:

none

Parameters:
none
Returns:

32-bit status value. Use status masks in CLOCK_FAIL_STATUS_MASKS to derive individual status.

Note:

In interrupt mode this function has to be called inside CLOCK_CombinedClockFailCallback to know the status during failure event.

CLOCK_GeneratorFrequencyGet()

inline static uint32_t CLOCK_GeneratorFrequencyGet (enum CLOCK_GENERATOR generator)

This inline function returns clock generator frequency in Hz.

Precondition:

none

Parameters:
in generator

- instance of clock generator

Returns:

Clock frequency in Hz

CLOCK_Initialize()

void CLOCK_Initialize (void )

Initializes all the CLOCK sources and clock switch configurations.

Precondition:

none

Parameters:
none
Returns:

none  

Enumeration Type Documentation

CLOCK_FAIL_STATUS_MASKS

enum CLOCK_FAIL_STATUS_MASKS

Mask values for clock fail status.

CLOCK_GEN1_FAIL_MASK

Fail mask for Clock Generator 1

CLOCK_GEN2_FAIL_MASK

Fail mask for Clock Generator 2

CLOCK_GEN3_FAIL_MASK

Fail mask for Clock Generator 3

CLOCK_GENERATOR

enum CLOCK_GENERATOR

CLOCK generator instances.

CLOCK_GENERATOR_1

Clock Generator 1

CLOCK_GENERATOR_2

Clock Generator 2

CLOCK_GENERATOR_3

Clock Generator 3

CLOCK_SYSTEM

Clock for System

CLOCK_FRC

Clock for FRC

CLOCK_WDT

Clock for WDT

CLOCK_BFRC

Clock for BFRC

CLOCK_GENERATOR_MAX
CLOCK_MONITOR

enum CLOCK_MONITOR

CLOCK monitor instances.

CLOCK_MONITOR_MAX

3.26.2.2 File Documentation

3.26.2.2.1 source/clock.h File Reference

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "clock_types.h"

Functions

  • void CLOCK_Initialize (void)

    Initializes all the CLOCK sources and clock switch configurations.

  • static uint32_t CLOCK_GeneratorFrequencyGet (enum CLOCK_GENERATOR generator)

    This inline function returns clock generator frequency in Hz.

  • static uint32_t CLOCK_FailStatusGet (void)

    This inline function returns clock generator failure status.

  • void CLOCK_CombinedClockFailCallbackRegister (void(*handler)(void))

    This function can be used to override default callback and to define custom callback for CLOCK CombinedClockFail event.

  • void CLOCK_CombinedClockFailCallback (void)

    This is the default callback with weak attribute. The user can override and implement the default callback without weak attribute or can register a custom callback function using  

    CLOCK_CombinedClockFailCallbackRegister.

Macros

Detailed Description

CLOCK Generated Driver Header File