Enabling and Starting the PTG Module
Last modified by Microchip on 2023/11/10 11:07
Contents
In order for the Peripheral Trigger Generator (PTG) to begin executing step commands, two separate actions must be taken by the application:
- The PTG must first be enabled.
- Once enabled, the PTG will begin operating when it is started.
Enabling and starting the PTG are accomplished by writing to the PTG Control and Status (PTGCST) register.
PTGCST: PTG Status and Control Register
bit 15 | PTGEN: Module Enable bit 1 = Enables the PTG module |
bit 7 | PTGSTRT: Start PTG Sequencer bit 1 = Starts to sequentially execute Step commands |
Example of Enabling/Starting the PTG Using the MPLAB® XC16 C Compiler
1
2
3
4
5
6
7
2
3
4
5
6
7
// include the XC header file to define all register and bit names
#include <xc.h>
PTGEN = 1; // enables the PTG Module
PTGEN = 0; // disables the PTG Module
PTGSTRT = 1; // starts Step command executions
PGTSTRT = 0 ; // stops execution
#include <xc.h>
PTGEN = 1; // enables the PTG Module
PTGEN = 0; // disables the PTG Module
PTGSTRT = 1; // starts Step command executions
PGTSTRT = 0 ; // stops execution
Notes to Remember on Enabling and Starting the PTG
At reset, the PTG module is disabled and stopped.
- PTGCST is the only PTG Special Function Register (SFR) that can be written while the PTG Module is enabled. To modify any other PTG SFR, you must first disable the PTG by clearing PTGEN.
- When PTGEN is set, the PTG Queue Pointer Register (PTGQPTR) is set to point to the first entry in the Step Queue. Starting and stopping PTG execution has no effect on PTGQPTR.