3.3 DMA-Based Peripheral Sequencing

As an extension of the use case mentioned above in section Firmware-Driven Peripheral Operation, DMA can be used to write to the LATW register instead of the firmware, creating an automated sequence of peripherals being triggered by the Signal Routing Port.

DMA-Based Peripheral Sequencing with Signal Routing Port shows a use case where a Universal Timer triggers DMA1, which writes a sequence of data into LATW register. Based on the data written into LATW, the peripherals connected to the Signal Routing Port are controlled in a desired sequence.

DMA-Based Peripheral Sequencing with Signal Routing Port

// Input to SRPORT: LATW Register (DMA-driven)
// Output from SRPORT: PWM1 ERS, ADC Auto-conversion, CLC Input 1 PPS inputs
// Note: Initialization routines are not shown

uint8_t LATW_Data[] = {0x1, 0x2, 0x4};

void DMADriverSetup_SRPORT()
{
    // Set RW0/1/2 inputs as LATW0/1/2
    PORTWIN0 = 0x00;       // 0x00 = LATW0 on PIC18F46Q71
    PORTWIN1 = 0x00;       // 0x00 = LATW1 on PIC18F46Q71
    PORTWIN2 = 0x00;       // 0x00 = LATW2 on PIC18F46Q71
    
    // Set RW0/1/2 as PPS inputs for PWM1 ERS, ADC Auto-conversion, CLC Input 1
    PWM1ERSPPS = 0x38;     // 0x38 = RW0 on PIC18F46Q71
    ADACTPPS   = 0x39;     // 0x39 = RW1 on PIC18F46Q71
    CLCIN0PPS  = 0x3A;     // 0x3A = RW2 on PIC18F46Q71     
}

void DMA1_Setup()
{
    // Configure DMA as follows:
    // Source: LATW_Data[]
    // Destination: LATW Register
    // Source Counter: 3 and source pointer increment
    // Destination Counter: 1 and destination pointer not increment
    // Start trigger: Anything appropriate, like TU16A Period Match
}