Arduino Zero TCC Capture

Hi Daniel,

Do you have an idea to control the phase of a generated PWM signal at 40 kHz ?

If you require a 180° phase shift then you could try using the polarity bits to invert the waveform in the WAVB (Waveform Buffer register).

Buffered registers such as CCxB, PERB etc..., should be used when changing the duty-cycle/period during operation. Loading these registers cause the output to update at the beginning of the next timer cycle (overflow), preventing the changes from causing glitches on your waveform output. (Changes to the CCx, PER, etc... take effect on the output immediately).

An example of loading a buffered counter compare register:

REG_TCC0_CCB0 = 1500;
while(TCC0->SYNCBUSY.bit.CCB0);

Another alternative, for fine control over the PWM signal is to use dual slope critical PWM, where two of the timer's counter compare channels (CCx) are used to control the position of both the rising and falling edges of the PWM output. This could be used to generate whatever phase shift in the signal you require.

Kind regards,
Martin