3.15 PTG Driver

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.

3.15.1 Module Documentation

3.15.1.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.

3.15.1.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.

Data structures
  • struct PTG_INTERFACE

    Structure containing the function pointers of PTG driver.

Definitions
  • #define PTG_STEP0 PTGQUE0bits.STEP0

    PTG execution steps.

  • #define PTGCTRL (0x0u << 4u )

    PTG command macros.

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.

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. 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.

3.15.1.1.2 Definition Documentation

PTG_STEP0

#define PTG_STEP0 PTGQUE0bits.STEP0

PTG execution steps.

PTGCTRL

#define PTGCTRL (0x0u << 4u )

PTG command macros.

3.15.1.1.3 Function Documentation

PTG_Deinitialize()

void PTG_Deinitialize (void )

Deinitializes the PTG to POR values.

Parameters:
none
Returns:

none  

PTG_Disable()

void PTG_Disable (void )

Disables the PTG module.

Parameters:
none
Returns:

none  

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  

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  

PTG_Initialize()

void PTG_Initialize (void )

Initializes PTG module.

Parameters:
none
Returns:

none  

PTG_SoftwareTriggerSet()

void PTG_SoftwareTriggerSet (void )

Sets the software trigger for PTG module.

Parameters:
none
Returns:

none  

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  

PTG_StepSequenceStop()

void PTG_StepSequenceStop (void )

Stops the PTG step sequence execution.

Parameters:
none
Returns:

none  

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  

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  

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  

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  

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  

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  

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  

3.15.1.1.4 Enumeration Type Documentation

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

3.15.1.1.5 Variable Documentation

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.

3.15.2 Data Structure Documentation

3.15.2.1 PTG_INTERFACE Struct Reference

Structure containing the function pointers of PTG driver.

3.15.2.1.1 Detailed Description

Structure containing the function pointers of PTG driver.

#include <ptg_interface.h>

Data Fields

3.15.2.1.2 Field Documentation

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

source/

ptg_interface.h

Disable

void(* Disable) (void)

Pointer to PTG_Disable.

Enable

void(* Enable) (void)

Pointer to PTG_Enable.

EventCallbackRegister

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

Pointer to PTG_EventCallbackRegister.

Tasks

void(* Tasks) (enum PTG_EVENTS event)

Pointer to PTG_Tasks (Supported only in polling mode)

3.15.3 File Documentation

3.15.3.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"

3.15.3.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.

3.15.3.1.2 Macros

3.15.3.1.3 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. 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.

3.15.3.1.4 Detailed Description

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

PTG Generated Driver Header File

3.15.3.1.5 Macro Definition Documentation

PTG_STEP1

#define PTG_STEP1 PTGQUE0bits.STEP1

PTG_STEP10

#define PTG_STEP10 PTGQUE2bits.STEP10

PTG_STEP11

#define PTG_STEP11 PTGQUE2bits.STEP11

PTG_STEP12

#define PTG_STEP12 PTGQUE3bits.STEP12

PTG_STEP13

#define PTG_STEP13 PTGQUE3bits.STEP13

PTG_STEP14

#define PTG_STEP14 PTGQUE3bits.STEP14

PTG_STEP15

#define PTG_STEP15 PTGQUE3bits.STEP15

PTG_STEP16

#define PTG_STEP16 PTGQUE4bits.STEP16

PTG_STEP17

#define PTG_STEP17 PTGQUE4bits.STEP17

PTG_STEP18

#define PTG_STEP18 PTGQUE4bits.STEP18

PTG_STEP19

#define PTG_STEP19 PTGQUE4bits.STEP19

PTG_STEP2

#define PTG_STEP2 PTGQUE0bits.STEP2

PTG_STEP20

#define PTG_STEP20 PTGQUE5bits.STEP20

PTG_STEP21

#define PTG_STEP21 PTGQUE5bits.STEP21

PTG_STEP22

#define PTG_STEP22 PTGQUE5bits.STEP22

PTG_STEP23

#define PTG_STEP23 PTGQUE5bits.STEP23

PTG_STEP24

#define PTG_STEP24 PTGQUE6bits.STEP24

PTG_STEP25

#define PTG_STEP25 PTGQUE6bits.STEP25

PTG_STEP26

#define PTG_STEP26 PTGQUE6bits.STEP26

PTG_STEP27

#define PTG_STEP27 PTGQUE6bits.STEP27

PTG_STEP28

#define PTG_STEP28 PTGQUE7bits.STEP28

PTG_STEP29

#define PTG_STEP29 PTGQUE7bits.STEP29

PTG_STEP3

#define PTG_STEP3 PTGQUE0bits.STEP3

PTG_STEP30

#define PTG_STEP30 PTGQUE7bits.STEP30

PTG_STEP31

#define PTG_STEP31 PTGQUE7bits.STEP31

PTG_STEP4

#define PTG_STEP4 PTGQUE1bits.STEP4

PTG_STEP5

#define PTG_STEP5 PTGQUE1bits.STEP5

PTG_STEP6

#define PTG_STEP6 PTGQUE1bits.STEP6

PTG_STEP7

#define PTG_STEP7 PTGQUE1bits.STEP7

PTG_STEP8

#define PTG_STEP8 PTGQUE2bits.STEP8

PTG_STEP9

#define PTG_STEP9 PTGQUE2bits.STEP9

PTGADD

#define PTGADD (0x1u << 4u )

PTGCOPY

#define PTGCOPY (0x1u << 4u )

PTGIRQ

#define PTGIRQ (0x7u << 4u )

PTGJMP

#define PTGJMP (0xau << 4u )

PTGJMPC0

#define PTGJMPC0 (0xcu << 4u )

PTGJMPC1

#define PTGJMPC1 (0xeu << 4u )

PTGSTRB

#define PTGSTRB (0x2u << 4 )

PTGTRIG

#define PTGTRIG (0x8u << 4u )

PTGWHI

#define PTGWHI (0x4u << 4u )

PTGWLO

#define PTGWLO (0x5u << 4u )

3.15.3.2 source/ptg_interface.h File Reference

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

3.15.3.2.1 Data structures

  • struct PTG_INTERFACE

    Structure containing the function pointers of PTG driver.

3.15.3.2.2 Detailed Description

PTG Generated Driver Interface Header File

3.15.3.3 source/ptg_types.h File Reference

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

3.15.3.3.2 Detailed Description

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

PTG Generated Driver Types Header File