chipKIT® Development Platform

Inspired by Arduino™


Created Thu, 28 Jul 2011 23:36:14 +0000 by davec


Thu, 28 Jul 2011 23:36:14 +0000

Both Tlc5940 and softPWM use timers so can't really be ported automatically.

SoftPWM looks pretty easy because it only uses one timer and bit-bangs the PWM. Also the author has done the right thing and used the digitalPinToPort and digitalPinToBitMask macros rather than direct PORT and mask values, so the PIC32-compatible versions of these macros almost work, although the variables to store them need to be larger.

Attached is my attempt at a quick port of SoftPWM. It uses Timer2 so you can't use the hardware PWM (analogWrite()) at the same time as this library. It seems to work with the SoftPWM_Arduino_LED_Blink example but I haven't tested it otherwise.

This just uses a periodic timer interrupt instead of the Output Compare + Clear on Timer Compare method used in the AVR version. I'm not sure if that is as good for accurate timing and would welcome some opinions.


Fri, 29 Jul 2011 20:02:23 +0000


I'm working on a new SoftPWM library for PIC32 that uses the Core Timer (so it doesn't use any other timers) and can do PWM on all 84 pins. I'm pretty close to having it finished up - I'll post here when it's ready for testing. I expect to finish up this weekend or early this week. It is not heavy on CPU usage because it only schedules the Core Timer to fire when the next edge has to happen.



Sat, 30 Jul 2011 20:54:46 +0000

Thanks Brian, look forward to seeing it.


Sun, 13 Nov 2011 04:24:15 +0000

any updated info on this? i really need a high speed PWM output and would ideally like to program it from an Arduino type sketch am pretty new at this. the Arduino is definitely too slow so i just bought a chipkit 32. i need to produce simple pulses of either triangle or sine waves and am hoping for some simple way to do it with the chipkit. i only need 2000 and 4000 kz signals are a decent sample rate so i probably need something like a PWM frequency of 40 to 100 khz. or any other suggestion as to other ways to accomplish this?


Sun, 13 Nov 2011 17:21:16 +0000

See this thread.


Sun, 13 Nov 2011 18:45:31 +0000

what thread might that be ???


Sun, 13 Nov 2011 19:27:08 +0000

This one. (It's a link.)


Sun, 13 Nov 2011 20:25:00 +0000

thanks, it works now. i have a satellite connection and the link did not work for whatever reason. i thought it was a bad link.


Sun, 13 Nov 2011 20:29:57 +0000

Ah ok. I also made the thread a sticky so that more people can find it.