I have a project where I am attempting to use the TPM, configured for edge aligned PWM, to produce a series of 24 timed pulses, using the DMA to write new values to the TPM CnV register for each pulse. I'm having a couple of problems with which I need help.
I have the PWM set up as follows:
TPM1_SC = 0x0008;
TPM1_C0SC = 0x29;
TPM1_MOD = 29;
TPM1_C0V = 0;
SIM_SOPT2 |= 0x01000000; // select MCGPLLCLK/2 for TPM clock.
When the SIM_SOPT2 register is written, a 42 nS pulse (i.e. one TPM module clock) appears on the associated output pin. Does anyone have any ideas why this is happening and how to eliminate it?
Second, I have the DMA set up as follows:
const unsigned short DMATable [] = {8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,15,15,15,15,15,15,15,15,0};
DMAMUX0_CHCFG0 = 0x00; // disable DMA channel 0.
DMA_SAR0 = (int)DMATable; // set up DMA source address register.
DMA_DAR0 = (int)&TPM1_C0V; // set up DMA destination address register.
DMA_DSR_BCR0 = sizeof(DMATable); // number of bytes to xfer.
DMA_DCR0 = 0x60640080; // enable peripheral request (ERQ=1)
// cycle steal (CS=1)
// auto-align (AA=0)
// source increment (SINC=1)
// source size 16-bit (SSIZE=10)
// destination increment (DINC=0)
// destination size 16-bit (SSIZE=10),
// Disable request (D_REQ=1)
DMAMUX0_CHCFG0 = DMAMUX_CHCFG_ENBL_MASK | TPM1Ch0Slot; // enable DMA channel 0 for TPM1 channel 0.
As the DMATable shows, 16 pulses, 8 TPM module clocks wide followed by 8 pulses, 15 TPM module clocks wide should appear on the associated TPM pin. Finally, the DMA transfers a value of zero to C0V to have the PWM output remain at zero. However, instead of 16 pulses 8 TPM module clocks wide, only 15 pulses are appearing, followed by the 8 longer pulses.
Does anyone have any ideas what might be going on here?