You can try to use the timer (if you see how its made a PWM with some comparators, the same method can be used here) so you can make a software controlled PWM, on every pin you want not only on the hardware pins
here is a sample code, if you need more help i will try to explain you the code (with pictures )
You need some code for input to change the variable, so you can set the duty cycle.
If you see the signal from the timer, its like a sawtooth signal, if you make the code right so you can change the value of n, you can set the middle of the timer, you can set the point when it