2.19 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.
2.19.1 Module Documentation
2.19.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.
2.19.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.
Enumerations
enum PTG_EVENTS { Trigger0, Trigger1, Trigger2, Trigger3, WatchDogTimer }
Defines the PTG events that are available.
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.
2.19.1.1.2 Function Documentation
PTG_Deinitialize()
void PTG_Deinitialize (void )
Deinitializes the PTG to POR values.
none |
none |
PTG_Disable()
void PTG_Disable (void )
Disables the PTG module.
none |
none |
PTG_Enable()
void PTG_Enable (void )
Enables the PTG module.
PTG_Initialize function should have been called before calling this function. |
none |
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.
in | event |
- PTG events that are available |
in | callback |
- Address of the callback function |
none |
PTG_Initialize()
void PTG_Initialize (void )
Initializes PTG module.
none |
none |
PTG_SoftwareTriggerSet()
void PTG_SoftwareTriggerSet (void )
Sets the software trigger for PTG module.
none |
none |
PTG_StepSequenceStart()
void PTG_StepSequenceStart (void )
Starts the PTG step sequence execution.
PTG_Initialize and PTG_Enable functions should have been called before calling this function. |
none |
none |
PTG_StepSequenceStop()
void PTG_StepSequenceStop (void )
Stops the PTG step sequence execution.
none |
none |
PTG_Tasks()
void PTG_Tasks (enum PTG_EVENTS event)
This function is used to implement the tasks for polled implementations.
PTG_Initialize() function should be called before calling this function. |
in | event |
- PTG events that are available |
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.
none |
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.
none |
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.
none |
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.
none |
none |
PTG_WatchdogTimeoutStatusGet()
bool PTG_WatchdogTimeoutStatusGet (void )
Returns the status of PTG watchdog timeout bit.
none |
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.
none |
none |
2.19.1.1.3 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 |
2.19.1.1.4 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.
2.19.2 Class Documentation
2.19.2.1 PTG_INTERFACE Struct Reference
Structure containing the function pointers of PTG driver.
2.19.2.1.1 Detailed Description
Structure containing the function pointers of PTG driver.
#include <ptg_interface.h>
Public Attributes
void(* Initialize )(void)
Pointer to PTG_Initialize.
void(* Deinitialize )(void)
Pointer to PTG_Deinitialize.
void(* Enable )(void)
Pointer to PTG_Enable.
void(* Disable )(void)
Pointer to PTG_Disable.
void(* StepSequenceStart )(void)
Pointer to PTG_StepSequenceStart.
void(* SoftwareTriggerSet )(void)
Pointer to PTG_SoftwareTriggerSet.
bool(* WatchdogTimeoutStatusGet )(void)
Pointer to PTG_WatchdogTimeoutStatusGet.
void(* StepSequenceStop )(void)
Pointer to PTG_StepSequenceStop.
void(* EventCallbackRegister )(enum PTG_EVENTS event, void(*callback)(void))
Pointer to PTG_EventCallbackRegister.
void(* Tasks )(enum PTG_EVENTS event)
Pointer to PTG_Tasks (Supported only in polling mode)
2.19.2.1.2 Member Data Documentation
Deinitialize
void(* Deinitialize) (void)
Pointer to PTG_Deinitialize.
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.
Initialize
void(* Initialize) (void)
Pointer to PTG_Initialize.
SoftwareTriggerSet
void(* SoftwareTriggerSet) (void)
Pointer to PTG_SoftwareTriggerSet.
StepSequenceStart
void(* StepSequenceStart) (void)
Pointer to PTG_StepSequenceStart.
StepSequenceStop
void(* StepSequenceStop) (void)
Pointer to PTG_StepSequenceStop.
Tasks
void(* Tasks) (enum PTG_EVENTS event)
Pointer to PTG_Tasks (Supported only in polling mode)
WatchdogTimeoutStatusGet
bool(* WatchdogTimeoutStatusGet) (void)
Pointer to PTG_WatchdogTimeoutStatusGet.
2.19.3 File Documentation
2.19.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"
2.19.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.
2.19.3.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.3.1.3 Detailed Description
This is the generated driver header file for the PTG driver.
PTG Generated Driver Header File
2.19.3.2 source/ptg_interface.h File Reference
#include <stdbool.h> #include "ptg_types.h"
2.19.3.2.1 Data structures
struct PTG_INTERFACE
Structure containing the function pointers of PTG driver.
2.19.3.2.2 Detailed Description
PTG Generated Driver Interface Header File
2.19.3.3 source/ptg_types.h File Reference
This is the generated driver types header file for the PTG driver.
2.19.3.3.1 Enumerations
enum PTG_EVENTS { Trigger0, Trigger1, Trigger2, Trigger3, WatchDogTimer }
Defines the PTG events that are available.
2.19.3.3.2 Detailed Description
This is the generated driver types header file for the PTG driver.
PTG Generated Driver Types Header File