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
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. 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.
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 |
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
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)
3.15.2.1.2 Field 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.
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
#define PTG_STEP0 PTGQUE0bits.STEP0
PTG execution steps.
#define PTG_STEP1 PTGQUE0bits.STEP1
#define PTG_STEP2 PTGQUE0bits.STEP2
#define PTG_STEP3 PTGQUE0bits.STEP3
#define PTG_STEP4 PTGQUE1bits.STEP4
#define PTG_STEP5 PTGQUE1bits.STEP5
#define PTG_STEP6 PTGQUE1bits.STEP6
#define PTG_STEP7 PTGQUE1bits.STEP7
#define PTG_STEP8 PTGQUE2bits.STEP8
#define PTG_STEP9 PTGQUE2bits.STEP9
#define PTG_STEP10 PTGQUE2bits.STEP10
#define PTG_STEP11 PTGQUE2bits.STEP11
#define PTG_STEP12 PTGQUE3bits.STEP12
#define PTG_STEP13 PTGQUE3bits.STEP13
#define PTG_STEP14 PTGQUE3bits.STEP14
#define PTG_STEP15 PTGQUE3bits.STEP15
#define PTG_STEP16 PTGQUE4bits.STEP16
#define PTG_STEP17 PTGQUE4bits.STEP17
#define PTG_STEP18 PTGQUE4bits.STEP18
#define PTG_STEP19 PTGQUE4bits.STEP19
#define PTG_STEP20 PTGQUE5bits.STEP20
#define PTG_STEP21 PTGQUE5bits.STEP21
#define PTG_STEP22 PTGQUE5bits.STEP22
#define PTG_STEP23 PTGQUE5bits.STEP23
#define PTG_STEP24 PTGQUE6bits.STEP24
#define PTG_STEP25 PTGQUE6bits.STEP25
#define PTG_STEP26 PTGQUE6bits.STEP26
#define PTG_STEP27 PTGQUE6bits.STEP27
#define PTG_STEP28 PTGQUE7bits.STEP28
#define PTG_STEP29 PTGQUE7bits.STEP29
#define PTG_STEP30 PTGQUE7bits.STEP30
#define PTG_STEP31 PTGQUE7bits.STEP31
#define PTGCTRL (0x0u << 4u )
PTG command macros.
#define PTGCOPY (0x1u << 4u )
#define PTGADD (0x1u << 4u )
#define PTGSTRB (0x2u << 4 )
#define PTGWHI (0x4u << 4u )
#define PTGWLO (0x5u << 4u )
#define PTGIRQ (0x7u << 4u )
#define PTGTRIG (0x8u << 4u )
#define PTGJMP (0xau << 4u )
#define PTGJMPC0 (0xcu << 4u )
#define PTGJMPC1 (0xeu << 4u )
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.1 Enumerations
enum PTG_EVENTS { Trigger0, Trigger1, Trigger2, Trigger3, WatchDogTimer }
Defines the PTG events that are available.
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