XiangJun Rong,
Thanks for the reply. Gordy originally posted this on my behalf. I've included a sketch of my expected PWM and timer waveforms to help you visualize what I'm trying to do.
TPM0 is configured in up/down count mode with a MOD value of 800. TPM0 is used to drive PWMs on CH0 and CH2 through C0V and C2V. Each signal is active low. CH0 is centered about TPM0 CNT=MOD event while CH2 is centered about TPM0 CNT=0 event. The intent is to give the two PWMs a 180 degree phase shift. In my sketch the two PWMs have the same duty cycle but that won't necessarily happen in my application. One thing that is not shown in my sketch is the C1V is always set to the same value as C0V and C3V is always set to the same value as C2V. At any given moment only one set of outputs is enabled, either CH0 and CH2 or CH1 and CH3. One set is for forward and one is for reverse.
So, all that TPM0 does is generate PWM waveforms. I also needed to generate a sequence of ADC samples specifically timed to the PWM waveforms. These samples need to be triggered in the center of the active-low on-time of each PWM. TPM1 was configured to trigger the ADC samples. It was set to up count mode with a MOD value 1 less than the TPM0 counter. So, the TPM1 MOD register is set to 799. The TPM1 over-flow events align with the TPM0 CNT=MOD and CNT=0 events. The ADC samples are triggered by the TPM1 C0V event. The C0V event is configured to occur when TPM1 CNT=MOD by setting TPM1 C0V equal to TPM1 MOD.
The DMA is used to buffer all of the ADC samples in my sequence. At the end of the sequence there is a DMA event that restarts the sequence. All TPM timers run continuously throughout this entire process.
Now that I've explained all of that...I am intentionally configuring TPM0 to start counting based on a trigger from TPM1. This is to ensure that TPM0 and TPM1 start up synchronized. When they are enabled TPM1 starts counting immediately while TPM0 sits at CNT=0 waiting for a trigger. When TPM1 hits its first overflow event it triggers TPM0 to start counting. Now the two timers are synchronized and should remain that way forever. This is important to ensure that my ADC samples are synchronized to the PWM waveforms. The left hand side of my sketch illustrates the expected start-up behavior of the two timers.
For the most part all of this seems to be working very well. The only problem I've encountered is what Gordy mentioned in the original post. I stumbled across a specific value written to any of the CxV registers associated with TPM0 that causes strange PWM behavior. A value of 798 should cause either a very low duty cycle on C0V or a very high duty cycle on C2V. Instead it creates about a 50% duty cycle. However, a value of 797 or 799 produces expected behavior.
It's easy to write code to avoid this specific value. My concern is that there may be other values that produce similar behavior. It was really dumb luck that I stumbled across this value. I haven't tried every single possible CxV value. I'm also wondering is this an errata or something caused by my specific configuration.
Thanks for the help.
Jon