How do I get rid of duplication

Sorry, I don't quite see what you are getting at. You have a pointer to an object... and you have two objects (pwm0 and pwm1)... What's next?