1.26.11 Periodic Interval Timer 64-bit (PIT64B)

The 64-bit Periodic Interval Timer (PIT64B) provides the operating system scheduler interrupt, as well as any periodic source of interrupt to software. It is designed to offer maximum accuracy and efficient management, even for systems with long response times.

  • 4-bit Prescaler

  • Single Shot or Continuous Mode

Using The Library

PIT64B peripheral library can be used to poll for a periodic timeout, generate periodic interrupts or generate timed waits. The following examples shows different modes of its usage.

Polling method

int main ( void )
{
    int i;
    /* Initialize all modules */
    SYS_Initialize ( NULL );

    while ( true )
    {
        while(!PIT64B_TimerPeriodHasExpired());
        LED_BLUE_Toggle();
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}

Interrupt method

static void timerHandler (uintptr_t context)
{    
    (void)context;
    
    LED_BLUE_Toggle(); 
}

int main ( void )
{
    /* Initialize all modules */
    SYS_Initialize ( NULL );

    PIT64B_TimerCallbackSet(timerHandler, 0);
    PIT64B_TimerStart();

    while ( true )
    {
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}

Delay routines

int main ( void )
{
    /* Initialize all modules */
    SYS_Initialize ( NULL );
    
    PIT64B_TimerStart();

    while ( true )
    {
        PIT64B_DelayMs(1000U);
        LED_BLUE_Toggle();
        /* Maintain state machines of all polled MPLAB Harmony modules. */
        SYS_Tasks ( );
    }

    /* Execution should not come here during normal operation */

    return ( EXIT_FAILURE );
}

Library Interface

Periodic Interval Timer 64-bit peripheral library provides the following interfaces:

Functions

Name Description
PIT64B_TimerInitialize Initialize PIT64B registers per user config
PIT64B_TimerRestart Restart the PIT64B counter
PIT64B_TimerStart Start the PIT64B counter
PIT64B_TimerStop Stop the PIT64B counter
PIT64B_TimerPeriodSet Set the timer period value
PIT64B_TimerPeriodGet Get the timer period value
PIT64B_TimerCounterGet Get the timer counter value
PIT64B_TimerFrequencyGet Get the timer clock frequency
PIT64B_TimerPeriodHasExpired Return whether or not the Timer Period has expired
PIT64B_DelayMs Delays processing for x milliseconds
PIT64B_DelayUs Delays processing for x microseconds
PIT64B_TimerCallbackSet Register callback for PIT64B interrupt
PIT64B_ClearInterrupt PIT64B Clear Interrupt

Data types and constants

Name Type Description
PIT64B_CALLBACK Typedef PIT64B Interrupt Callback Function definition