The dsPIC33 family is a really cost-effective and capable option if you need a lot of PWM signals, but the datasheets are pretty intense and the code examples don't usually work right out of the box.
Here I am sharing a code snippet to get you started 🫶
PWM1L,PWM1H,PWM2H,PWM4L,PWM4H are set up in Dual PWM Mode.
They can be controlled by sending data in the format: value1,value2,value3,value4,value5; via Uart (9600 baud rate)
![DUAL_PWM](https://private-user-images.githubusercontent.com/11893651/393604380-7d852249-b856-4b7c-a95c-027e56f6a655.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTk3NjUsIm5iZiI6MTczOTAxOTQ2NSwicGF0aCI6Ii8xMTg5MzY1MS8zOTM2MDQzODAtN2Q4NTIyNDktYjg1Ni00YjdjLWE5NWMtMDI3ZTU2ZjZhNjU1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDEyNTc0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY0ZDQ3YzIzOWFkZmMwMzk1OWE1MWFmNmE5NGU2MzFjMThjZGU2MDAwMTdlZmFjZjM3ZmYxZDBiMDBiMmRmMGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.YeR_1Qxgw5ve0ev3Zv7jXRi8XBTvP-6AGEurij5KMto)
I found two ways to combine multiple PWM Pins with logic gates.
- PWM3L is set to PWM4L or PWM4H using the "Combinatorial PWM Logic" functinallity.
- PWM3L is set to PWM4L nor PWM4H using the "Combinatorial PWM Logic" functinallity.
It is also possible to use the “CLC” functionality, but you have to connect the PWM pins to the input pins of the CLC block, as an internal connection is not possible.
Note the Blue arrows on the Pinout image.
- Pin RB0 is set to PWM1L or PWM1H or PWM2H
- Pin RB2 is set to not(PWM1L or PWM1H or PWM2H)