PIC24 Support Libraries
|
Configures the system clock. More...
Go to the source code of this file.
Macros | |
#define | CYCLES_PER_MS ((uint32_t)(FCY * 0.001)) |
#define | CYCLES_PER_US ((uint32_t)(FCY * 0.000001)) |
#defines for CLOCK_CONFIG | |
#define | SIM_CLOCK 0, -1, 1000000L, POSCMD_NONE, -1, configClockSim, 1, 498 |
#define | FRCPLL_FCY16MHz 1, FNOSC_FRCPLL, 16000000L, POSCMD_NONE, -1, configClockFRCPLL_FCY16MHz, (PIC24F_DEFINED || PIC24FK_DEFINED), 498 |
#define | FRC_FCY4MHz 2, FNOSC_FRC, 4000000L, POSCMD_NONE, -1, configClockFRC_FCY4MHz, (PIC24F_DEFINED || PIC24FK_DEFINED), 498 |
#define | PRI_NO_PLL_7372KHzCrystal 3, FNOSC_PRI, 3686400L, POSCMD_XT, 7372800L, configClockPRI_NO_PLL_7372KHzCrystal, (PIC24F_DEFINED || PIC24FK_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED), 498 |
#define | FRC_FCY3685KHz 4, FNOSC_FRC, 3685000L, POSCMD_NONE, -1, configClockFRC_FCY3685KHz, (PIC24E_DEFINED || dsPIC33E_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED), 498 |
#define | FRCPLL_FCY40MHz 5, FNOSC_FRCPLL, 40000000L, POSCMD_NONE, -1, configClockFRCPLL_FCY40MHz, (PIC24E_DEFINED || dsPIC33E_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED), 498 |
#define | PRIPLL_7372KHzCrystal_40MHzFCY 6, FNOSC_PRIPLL, 39920833L, POSCMD_XT, 7372800L, configClockPRIPLL_7372KHzCrystal_40MHzFCY, (PIC24H_DEFINED || dsPIC33F_DEFINED), 498 |
#define | PRIPLL_8MHzCrystal_40MHzFCY 7, FNOSC_PRIPLL, 40000000L, POSCMD_XT, 8000000L, configClockPRIPLL_8MHzCrystal_40MHzFCY, (PIC24H_DEFINED || dsPIC33F_DEFINED || PIC24E_DEFINED || dsPIC33E_DEFINED), 498 |
#define | PRIPLL_8MHzCrystal_16MHzFCY 8, FNOSC_PRIPLL, 16000000L, POSCMD_XT, 8000000L, configClockPRIPLL_8MHzCrystal_16MHzFCY, (PIC24F_DEFINED || PIC24FK_DEFINED), 498 |
#define | PRI_8MHzCrystal_4MHzFCY 9, FNOSC_PRI, 4000000L, POSCMD_XT, 8000000L, configClockPRI_8MHzCrystal_4MHzFCY, (PIC24F_DEFINED || PIC24FK_DEFINED || PIC24H_DEFINED || dsPIC33F_DEFINED || PIC24E_DEFINED || dsPIC33E_DEFINED), 498 |
#define | FRCPLL_FCY60MHz 10, FNOSC_FRCPLL, 59881250L, POSCMD_NONE, -1, configClockFRCPLL_FCY60MHz, (PIC24E_DEFINED || dsPIC33E_DEFINED), 498 |
#define | FRCPLL_FCY70MHz 11, FNOSC_FRCPLL, 70015000L, POSCMD_NONE, -1, configClockFRCPLL_FCY70MHz, (PIC24E_DEFINED || dsPIC33E_DEFINED), 498 |
Some of the #defines produced by CLOCK_CONFIG choice | |
#define | CLOCK_CONFIG_INDEX (GET_CLOCK_CONFIG_INDEX(CLOCK_CONFIG)) |
#define | FNOSC_SEL (GET_FNOSC_SEL(CLOCK_CONFIG)) |
#define | FCY (GET_FCY(CLOCK_CONFIG)) |
#define | POSCMD_SEL (GET_POSCMD_SEL(CLOCK_CONFIG)) |
#define | POSC_FREQ (GET_POSC_FREQ(CLOCK_CONFIG)) |
#define | CONFIG_DEFAULT_CLOCK() (GET_CONFIG_DEFAULT_CLOCK(CLOCK_CONFIG)()) |
Helper macros for clock configuration | |
#define | IS_CLOCK_CONFIG(clockConfig) (_GET_CLOCK_CONFIG_INDEX(clockConfig) == CLOCK_CONFIG_INDEX) |
#define | GET_OSC_SEL_BITS(bits) _GET_OSC_SEL_BITS(bits) |
#define | OSC_SEL_BITS GET_OSC_SEL_BITS(FNOSC_SEL) |
Functions | |
static void | configClock () |
void | switchClock (uint8_t u8_source) |
Configures the system clock.
The clocking options for the PIC24 are chosen in this file. The resulting settings are used in pic24_clockfreq.c to configure and switch the oscillator as necessary after the chip is running.
To choose a clock configuration, simply select a value for CLOCK_CONFIG from the table there. The default selection used by most of the PIC24H examples is FRCPLL_FCY40MHz (the internal FRC+PLL configured for FCY = 40 MHz). Some of the examples in Chapter 12 expect an external 8 MHz crystal, and use the PRIPLL_8MHzCrystal_40MHzFCY option (external 8 MHz crystal + PLL confgured for FCY = 40 MHz).
This file provides several useful defines as a result of the clock selection above:
To define a new clock configuation:
Definition in file pic24_clockfreq.h.
#define CLOCK_CONFIG_INDEX (GET_CLOCK_CONFIG_INDEX(CLOCK_CONFIG)) |
A unique number is assigned to each clock configuration, in order to allow comparsions between configurations. CLOCK_CONFIG_INDEX gives the number assigned to the selected clock configuration. The macro IS_CLOCK_CONFIG uses this number for its comparsisons.
#define CONFIG_DEFAULT_CLOCK | ( | ) | (GET_CONFIG_DEFAULT_CLOCK(CLOCK_CONFIG)()) |
Calls one of the configClock() functions defined in pic24_clockfreq.c based on the CLOCK_CONFIG chosen.
Referenced by configClock().
#define CYCLES_PER_MS ((uint32_t)(FCY * 0.001)) |
A constant which gives the number of processor clock cycles in 1 millisecond. This value is cast to a uint32_t.
Definition at line 332 of file pic24_clockfreq.h.
#define CYCLES_PER_US ((uint32_t)(FCY * 0.000001)) |
A constant which gives the number of processor clock cycles in 1 microsecond. This value is cast to a uint32_t.
Definition at line 338 of file pic24_clockfreq.h.
#define FCY (GET_FCY(CLOCK_CONFIG)) |
FCY specifies the resulting processor clock frequency after all PLL/divide operations take the inital clock and produce a processor clock. The units of this value are Hz, so the value 40000000L is 40 MHz.
NOTE: This should be defined as a long (with a trailing L after the number) to allocate enough space to correctly store the processor clock frequency.
Referenced by CONFIG_BAUDRATE_UART1(), configI2C1(), configUART1(), esos_pic24_configI2C1(), msToU16Ticks(), ticksToMs(), ticksToNs(), ticksToUs(), usToU16Ticks(), and usToU32Ticks().
#define FNOSC_SEL (GET_FNOSC_SEL(CLOCK_CONFIG)) |
Oscillator source selection for the PIC24. FNOSC_SEL is set to one of the following based on CLOCK_CONFIG :
#define GET_OSC_SEL_BITS | ( | bits | ) | _GET_OSC_SEL_BITS(bits) |
A macro to determine the NOSC/COSC bits for the OSCCON register given bits taken from the PIC24's configuration FNOSC word.
Definition at line 359 of file pic24_clockfreq.h.
#define IS_CLOCK_CONFIG | ( | clockConfig | ) | (_GET_CLOCK_CONFIG_INDEX(clockConfig) == CLOCK_CONFIG_INDEX) |
A helper macro to check if the given clock configuration was selected. Example usage is given in pic24_clockfreq.c. A shorter example:
clockConfig | Clock configuration to compare the current clock configuation against. |
Definition at line 353 of file pic24_clockfreq.h.
#define OSC_SEL_BITS GET_OSC_SEL_BITS(FNOSC_SEL) |
A macro giving the NOSC/COSC bits for the OSCCON register which correspond to FNOSC_SEL, the configuration word which contains the FNOSC bits.
Definition at line 372 of file pic24_clockfreq.h.
#define POSC_FREQ (GET_POSC_FREQ(CLOCK_CONFIG)) |
This values gives the primary osciallator frequency (if used). The units of this value are Hz, so the value 40000000L is 40 MHz.
NOTE: This should be defined as a long (with a trailing L after the number) to allocate enough space to correctly store the processor clock frequency.
#define POSCMD_SEL (GET_POSCMD_SEL(CLOCK_CONFIG)) |
Specifies the primary oscillator type. Valid values:
#define SIM_CLOCK 0, -1, 1000000L, POSCMD_NONE, -1, configClockSim, 1, 498 |
Create a table of vales for CLOCK_CONFIG. When adding a new entry, you must also write C code to configure the clock in pic24_clockfreq.c. See that file for examples and the detailed description section at the top of this page for more information. Note that FCY and POSC_FREQ should be defined as a long (with a trailing L) to retain enough accuracy to store these values.
Table entry notes: (see actual code, not the documentation, for the table)
Definition at line 155 of file pic24_clockfreq.h.
|
inlinestatic |
Configure the default clock by calling the CONFIG_DEFAULT_CLOCK() macro.
Definition at line 446 of file pic24_clockfreq.h.
Referenced by configBasic().
void switchClock | ( | uint8_t | u8_source | ) |
Switch the clock to the source specified. The source given will be assigned to NOSC in the OSCCON register, the a switch clock performed.
Note: DO NOT use FNOSC_SEL as the source; instead, use OSC_SEL_BITS. FNOSC_SEL is for configuration bits while switchClock expects a NOSC value to write to the OSCCON register.
u8_source | The clock source to switch to. |
Definition at line 212 of file pic24_clockfreq.c.
Referenced by configClock().