2.19 PTG Driver

2.19.1 Introduction

Overview

The Peripheral Trigger Generator (PTG) module is a user-programmable sequencer, which is capable of generating complex trigger signal sequences to coordinate the operation of other peripherals. The PTG module is designed to interface with other modules, such as Analog-to-Digital Converter (ADC), output compare and PWM modules, timers and interrupt controllers.

Features Supported

  • Behavior is Step Command-Driven
    • Step commands are 8 bits wide.
    • Commands are Stored in a Step Queue.
  • Programmable Step execution time (Step delay).
  • Hardware Input Triggers
    • Sensitive to either positive or negative edges, or a high or low level.
    • One Software Input Trigger.
  • Generates up to 32 Unique Output Trigger Signals.
  • Generates Two Types of Trigger Outputs
    • Individual.
    • Broadcast.
  • Two 16-Bit General Purpose Timers.
  • Flexible Self-Contained Watchdog Timer (WDT) to Set an Upper Limit to Trigger Wait Time.
  • Clock source and clock divider are user configurable, it is selected from the PLIB.

2.19.2 Module Documentation

2.19.2.1 PTG Driver

Peripheral Trigger Generator Driver is a user-programmable sequencer that is capable of generating complex trigger signal sequences to coordinate the operation of other peripherals using dsPIC MCUs.

2.19.2.1.1 Module description

Peripheral Trigger Generator Driver is a user-programmable sequencer that is capable of generating complex trigger signal sequences to coordinate the operation of other peripherals using dsPIC MCUs.

2.19.2.1.1.1 Data structures
  • struct PTG_INTERFACE

    Structure containing the function pointers of PTG driver.

2.19.2.1.1.3 Functions
  • void PTG_Initialize (void)

    Initializes PTG module.

  • void PTG_Deinitialize (void)

    Deinitializes the PTG to POR values.

  • void PTG_Enable (void)

    Enables the PTG module.

  • void PTG_StepSequenceStart (void)

    Starts the PTG step sequence execution.

  • void PTG_SoftwareTriggerSet (void)

    Sets the software trigger for PTG module.

  • bool PTG_WatchdogTimeoutStatusGet (void)

    Returns the status of PTG watchdog timeout bit.

  • void PTG_StepSequenceStop (void)

    Stops the PTG step sequence execution.

  • void PTG_Disable (void)

    Disables the PTG module.

  • void PTG_EventCallbackRegister (enum PTG_EVENTS event, void(*callback)(void))

    This function can be used to override default callback and to define custom callback for PTG events.

  • void PTG_Trigger0Callback (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 PTG_Trigger0CallbackRegister.

  • void PTG_Trigger1Callback (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 PTG_Trigger1CallbackRegister.

  • void PTG_Trigger2Callback (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 PTG_Trigger2CallbackRegister.

  • void PTG_Trigger3Callback (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 PTG_Trigger3CallbackRegister.

  • void PTG_WatchDogTimerCallback (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 PTG_WatchDogTimerCallbackRegister.

  • void PTG_Tasks (enum PTG_EVENTS event)

    This function is used to implement the tasks for polled implementations.

2.19.2.1.1.4 Variables
  • const struct PTG_INTERFACE PTG

    Structure object of type PTG_INTERFACE with the custom name given by the user in the Melody Driver User interface.

2.19.2.1.2 Function Documentation

2.19.2.1.2.1 PTG_Deinitialize()

void PTG_Deinitialize (void )

Deinitializes the PTG to POR values.

Parameters:
none
Returns:

none

2.19.2.1.2.2 PTG_Disable()

void PTG_Disable (void )

Disables the PTG module.

Parameters:
none
Returns:

none

2.19.2.1.2.3 PTG_Enable()

void PTG_Enable (void )

Enables the PTG module.

Precondition:

PTG_Initialize function should have been called before calling this function.

Parameters:
none
Returns:

none

2.19.2.1.2.4 PTG_EventCallbackRegister()

void PTG_EventCallbackRegister (enum PTG_EVENTS event, void(*)(void) callback)

This function can be used to override default callback and to define custom callback for PTG events.

Parameters:
in event

- PTG events that are available

in callback

- Address of the callback function

Returns:

none

2.19.2.1.2.5 PTG_Initialize()

void PTG_Initialize (void )

Initializes PTG module.

Parameters:
none
Returns:

none

2.19.2.1.2.6 PTG_SoftwareTriggerSet()

void PTG_SoftwareTriggerSet (void )

Sets the software trigger for PTG module.

Parameters:
none
Returns:

none

2.19.2.1.2.7 PTG_StepSequenceStart()

void PTG_StepSequenceStart (void )

Starts the PTG step sequence execution.

Precondition:

PTG_Initialize and PTG_Enable functions should have been called before calling this function.

Parameters:
none
Returns:

none

2.19.2.1.2.8 PTG_StepSequenceStop()

void PTG_StepSequenceStop (void )

Stops the PTG step sequence execution.

Parameters:
none
Returns:

none

2.19.2.1.2.9 PTG_Tasks()

void PTG_Tasks (enum PTG_EVENTS event)

This function is used to implement the tasks for polled implementations.

Precondition:

PTG_Initialize() function should be called before calling this function.

Parameters:
in event

- PTG events that are available

Returns:

none

2.19.2.1.2.10 PTG_Trigger0Callback()

void PTG_Trigger0Callback (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 PTG_Trigger0CallbackRegister.

Parameters:
none
Returns:

none

2.19.2.1.2.11 PTG_Trigger1Callback()

void PTG_Trigger1Callback (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 PTG_Trigger1CallbackRegister.

Parameters:
none
Returns:

none

2.19.2.1.2.12 PTG_Trigger2Callback()

void PTG_Trigger2Callback (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 PTG_Trigger2CallbackRegister.

Parameters:
none
Returns:

none

2.19.2.1.2.13 PTG_Trigger3Callback()

void PTG_Trigger3Callback (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 PTG_Trigger3CallbackRegister.

Parameters:
none
Returns:

none

2.19.2.1.2.14 PTG_WatchdogTimeoutStatusGet()

bool PTG_WatchdogTimeoutStatusGet (void )

Returns the status of PTG watchdog timeout bit.

Parameters:
none
Returns:

true - PTG watchdog timeout occurred

false - PTG watchdog timeout not occurred

2.19.2.1.2.15 PTG_WatchDogTimerCallback()

void PTG_WatchDogTimerCallback (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 PTG_WatchDogTimerCallbackRegister.

Parameters:
none
Returns:

none

2.19.2.1.3 Enumeration Type Documentation

2.19.2.1.3.1 PTG_EVENTS

enum PTG_EVENTS

Defines the PTG events that are available.

Trigger0

PTG Trigger0 Event

Trigger1

PTG Trigger1 Event

Trigger2

PTG Trigger2 Event

Trigger3

PTG Trigger3 Event

WatchDogTimer

PTG WatchDogTimer Event

2.19.2.1.4 Variable Documentation

2.19.2.1.4.1 PTG

const struct PTG_INTERFACE PTG

Structure object of type PTG_INTERFACE with the custom name given by the user in the Melody Driver User interface.

The default name e.g. PTG can be changed by the user in the PTG user interface.This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.

2.19.3 Class Documentation

2.19.3.1 PTG_INTERFACE Struct Reference

Structure containing the function pointers of PTG driver.

2.19.3.1.1 Detailed Description

Structure containing the function pointers of PTG driver.

#include <ptg_interface.h>

2.19.3.1.1.1 Public Attributes

2.19.3.1.2 Member Data Documentation

The documentation for this struct was generated from the following file:

source/

ptg_interface.h

2.19.3.1.2.1 Deinitialize

void(* Deinitialize) (void)

Pointer to PTG_Deinitialize.

2.19.3.1.2.2 Disable

void(* Disable) (void)

Pointer to PTG_Disable.

2.19.3.1.2.3 Enable

void(* Enable) (void)

Pointer to PTG_Enable.

2.19.3.1.2.4 EventCallbackRegister

void(* EventCallbackRegister) (enum PTG_EVENTS event, void(*callback)(void))

Pointer to PTG_EventCallbackRegister.

2.19.3.1.2.5 Initialize

void(* Initialize) (void)

Pointer to PTG_Initialize.

2.19.3.1.2.9 Tasks

void(* Tasks) (enum PTG_EVENTS event)

Pointer to PTG_Tasks (Supported only in polling mode)

2.19.4 File Documentation

2.19.4.1 source/ptg.h File Reference

This is the generated driver header file for the PTG driver.

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>
#include "ptg_types.h"
#include "ptg_interface.h"

2.19.4.1.1 Functions

  • void PTG_Initialize (void)

    Initializes PTG module.

  • void PTG_Deinitialize (void)

    Deinitializes the PTG to POR values.

  • void PTG_Enable (void)

    Enables the PTG module.

  • void PTG_StepSequenceStart (void)

    Starts the PTG step sequence execution.

  • void PTG_SoftwareTriggerSet (void)

    Sets the software trigger for PTG module.

  • bool PTG_WatchdogTimeoutStatusGet (void)

    Returns the status of PTG watchdog timeout bit.

  • void PTG_StepSequenceStop (void)

    Stops the PTG step sequence execution.

  • void PTG_Disable (void)

    Disables the PTG module.

  • void PTG_EventCallbackRegister (enum PTG_EVENTS event, void(*callback)(void))

    This function can be used to override default callback and to define custom callback for PTG events.

  • void PTG_Trigger0Callback (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 PTG_Trigger0CallbackRegister.

  • void PTG_Trigger1Callback (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 PTG_Trigger1CallbackRegister.

  • void PTG_Trigger2Callback (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 PTG_Trigger2CallbackRegister.

  • void PTG_Trigger3Callback (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 PTG_Trigger3CallbackRegister.

  • void PTG_WatchDogTimerCallback (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 PTG_WatchDogTimerCallbackRegister.

  • void PTG_Tasks (enum PTG_EVENTS event)

    This function is used to implement the tasks for polled implementations.

2.19.4.1.2 Variables

  • const struct PTG_INTERFACE PTG

    Structure object of type PTG_INTERFACE with the custom name given by the user in the Melody Driver User interface.

2.19.4.1.3 Detailed Description

This is the generated driver header file for the PTG driver.

PTG Generated Driver Header File

2.19.4.2 source/ptg_interface.h File Reference

#include <stdbool.h>
#include "ptg_types.h"

2.19.4.2.1 Data structures

  • struct PTG_INTERFACE

    Structure containing the function pointers of PTG driver.

2.19.4.2.2 Detailed Description

PTG Generated Driver Interface Header File

2.19.4.3 source/ptg_types.h File Reference

This is the generated driver types header file for the PTG driver.

2.19.4.3.2 Detailed Description

This is the generated driver types header file for the PTG driver.

PTG Generated Driver Types Header File