Setting the PTG Output Trigger Pulse Width

Last modified by Microchip on 2023/11/09 09:00

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.

The different trigger modes of the PTG - toggle and pulse

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

Back to top

PTGCST: PTG Status and Control Register

The PTGTOGL bit in the PTG Status and Control Register controls the trigger output mode - toggle or pulse

bit 12

PTGTOGL: TRIG Output Toggle Mode bit

1 = Toggle the state of PTGOx on each PTGTRIG command
0 = Generate a single pulse on PTGOx on each PTGTRIG command

Back to top

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

The four PTGWDT bits in the PTGCON register control the pulse width of the trigger pulse output

bit 7 - 4

PTGPWD<3:0>: PTG Trigger Output Pulse Width bits

1111 = All triggers are 16 PTG clock cycles
1110 = All triggers are 15 PTG clock cycles
*
*

0001 = All triggers are 2 PTG clock cycles
0000 = All triggers are 1 PTG clock cycles

Back to top

Example Code

// include the XC header file to define all register and bit names
#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

Back to top

Learn More

Back to top