This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832: Determine current position in sequence PWM with DMA

Hello,

I'm using the PWM peripheral to generate a waveform. The waveform is loaded into RAM and then I use the SEQ[n].PTR and SEQ[n].CNT registers to set up the DMA. The output is working quite nicely.

In my application, though, there has arose the need to determine where in the particular sequence based on actions happening outside of the PWM. Is there a way to read the values of COMP[N] and/or COUNTERTOP from figure 141 of nRF52832_PS v1.4 or to figure out where the DMA is currently pointing?

Let me demonstrate with some generic example. Assume I want to generate the following waveform with the PWM:

uint16_t pwmPattern = 
{
    COMP0[0],   COMP1[0],   COMP2[0],   TOP[0],
    COMP0[1],   COMP1[1],   COMP2[1],   TOP[1],
    COMP0[2],   COMP1[2],   COMP2[2],   TOP[2],
    COMP0[3],   COMP1[3],   COMP2[3],   TOP[3],
    COMP0[4],   COMP1[4],   COMP2[4],   TOP[4],
    COMP0[5],   COMP1[5],   COMP2[5],   TOP[5],
};

I configure the DMA to point to the waveform:

// Configure PWM
NRF_PWM1->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
NRF_PWM1->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);
NRF_PWM1->LOOP = (1 << PWM_LOOP_CNT_Pos);
NRF_PWM1->DECODER = (PWM_DECODER_LOAD_WaveForm << PWM_DECODER_LOAD_Pos) |
                    (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);
NRF_PWM1->SEQ[0].ENDDELAY = 0;
NRF_PWM1->SEQ[0].REFRESH = 0;

// Set up DMA for SEQ0
NRF_PWM1->SEQ[0].PTR = &COMP0[0];   // Start of pattern in RAM
NRF_PWM1->SEQ[0].CNT = 6 * 4;       // Number of PWM Periods * 4

And start the PWM

NRF_PWM1->TASKS_SEQSTART[0] = 1;

Let's say that while the PWM is outputting COMP0[3], my application wants to know the current state of the PWM. Is there a way to read what values are loaded into the DMA or where the DMA is currently pointed?

Parents Reply Children
No Data
Related