i didn't check your whole code but, have you try with a pulse generator instead of the switches?? if so, what are the results?

did you use a scope to see PWM and Switches signal. What about your supply line (again and again)