chipKIT® Development Platform

Inspired by Arduino™

SoftPWMServo Invert Pin

Created Thu, 03 Jan 2013 20:38:23 +0000 by cobra18t


cobra18t

Thu, 03 Jan 2013 20:38:23 +0000

Is there a way to invert a pin in the SoftPWMServo library (start low, switch high)? If not, can anyone make suggestions on how to change it to do so?

I have a half-bridge motor driver which relies on a bootstrapped gate drive on the high side. This means that I need to force the output low during the first part of the PWM cycle to charge the bootstrap capacitor. It must be at the beginning of the cycle since it must align with another active-high PWM output.

Ideas?

-Thomas


EmbeddedMan

Fri, 04 Jan 2013 21:44:07 +0000

Since the SoftPWMServo library is purely software (bit-banging the I/O pins), it should be very easy to add an invert ability. In fact, a really quick and easy hack might be to swap the SetPort and ClearPort values for the pin you want to be 'inverted'.

*Brian


cobra18t

Mon, 07 Jan 2013 17:37:23 +0000

Thanks EmbeddedMan.

I added a "pin_Inv" element to the ChanStruct structure to keep track of which pins are inverted. I used the way "IsServo" is handled as a template to add support for "pin_Inv." Now whenever SetPort or ClearPort were called it checks the pin_Inv element and does the opposite if it is true.

It works great now.

-Thomas


EmbeddedMan

Mon, 07 Jan 2013 18:05:54 +0000

Thomas,

Awesome! I'm really glad you got it to work for your project.

*Brian