Pulse Width Modulation

***You must be running at least V5.3 Firmware for this feature to work***.

Version 5.3 of the Firmware will be available on the Firmware page in the next couple of days.

As well as having 4 channels dedicated to producing hi speed variable Pulse Trains with 50% Duty Cycle, we have now added two PWM dedicated channels.

Both of these channels have a 12bit resolution duty cycle that can be set via simple commands. Also the Frequency can be set so you can control various hardware that needs a PWM signal.

For a good explanation of what PWM is, please check out this link

Below are some scope shots of the raw output of Channel 1 across various stages of the Duty Cycle.


To set the Frequency and Duty Cycle of each of the two channels you can simply send the desired frequency and the duty cycle percentage.


This would set the Frequency to 50Hz and set the Duty Cycle to 25% on channel X


Would set the Frequency to 25kHz and set the Duty Cycle to 50% on channel Y


Would set the Frequency to 15kHz and set the Duty Cycle to 80.5% on channel X

So as you can see the first 7 digits set the frequency and the last 5 digits set the percentage of duty cycle.

To set both channels and start at the same time you could use the following command


This would set channel X to 50Hz with a 50% Duty Cycle and channel Y to 100Hz with 25% Duty Cycle.

Here is a test of 1MHz with 50% Duty Cycle on channel X.


As you can see there is a fair bit of ringing going on, but remember there is connected directly to the processor pin.

The Connections for the two PWM channels can be seen below.

We would advise adding some sort of buffer circuit to the outputs to protect them or voltage shifter circuit if you need to upscale the output from 3.3v to 5v. We have found most 5v RC Servos for example are happy with a 3.3v PWM signal, even though they require a mains 5v supply.

Back in December 2017 we published a Laser Light Show example which uses the two PWM channels on the PTHAT and it can be viewed on the link below:

Also on this page I will be adding an example of controlling a couple of RC Servos in the future..




Closer look at the PCB's

Share This