Setting the PTG Output Trigger Pulse Width
The PTGTRIG Step Command causes the Peripheral Trigger Generator (PTG) to generate one of the 32 trigger signals (PTGO0 - PTG3O1). These signals are used as control inputs to other MCU peripherals synchronizing activity. PTG trigger signals can be configured in one of the two modes:
- In Toggle mode, the current value of the trigger signal will be toggled when PTGTRIG is executed.
- In Pulse mode, PTGTRIG will trigger a one-time pulse on PTGOx. Here, the width of the pulse is set by the application program.
Selecting the Trigger Mode
The mode of the Trigger signal is determined by the Toggle Output Mode bit in the PTG Control and Status Register (PTGCST<12>).
PTGCST: PTG Status and Control Register
bit 12 | PTGTOGL: TRIG Output Toggle Mode bit 1 = Toggle the state of PTGOx on each PTGTRIG command |
Determining the Pulse Width of the Trigger
When Trigger Pulse mode is selected, the width of the pulse is determined by a field in the PTG Control Register (PTGCON<7:4>).
PTGCON: PTG Control Register
bit 7 - 4 | PTGPWD<3:0>: PTG Trigger Output Pulse Width bits 1111 = All triggers are 16 PTG clock cycles 0001 = All triggers are 2 PTG clock cycles |
Example Code
#include <xc.h>
// Setting the PTG the Toggle mode
PTGTOGL = 1; // Set for Toggle Mode
// Setting the PTG for a Pulse width of 3 PTG clocks
PTGEN = 0; // PTGCON can only be written with PTGEN = 0
PTGPWD = 2; // Set pulse width to 3
PTGTOGL = 0; // set for pulse mode