Changing Arduino Zero PWM Frequency

Hi evi7538,

Glad to hear you got it working.

Out of interest I decided to have a go at getting the PWM to generate a synchronised 2 byte SPI command output, in order to simulate sending an SPI conversion signal (including register sub-address and command bytes) to an external device. This all occurs without CPU intervention (the loop() function is empty) and runs like a clockwork machine.

The code uses timer TCC0 and all of its 4 channels to generate the necessary timing. Channel 2 generates a 62.5kHz PWM output and channel 3 the SPI chip select output. Channels 0 and 1 are set up to route their compare match events through the event system to DMA channels 0 and 1. The DMA channels 0 and 1 simply output the first (sub-address) and second (command) bytes on the SPI port respectively.

(Unfortunately, it's not possible to use a single DMA channel to send two SPI bytes, as the SAMD21 doesn't support DMA burst mode).

On my Arduino Zero, the code outputs a 62.5kHz PWM signal on digtial pin D6 (yellow), the SPI chip select on D7 (light blue), SPI's SCK (pink) and MOSI (dark blue):

Sync_PWM_To_SPI.jpg

Sync_PWM_To_SPI.jpg