To convert analog signal to PWM, you can use timer.
First, convert or scale analog input value to be converted and send the value to preset value of timer. Then, the preset time of timer will be vary depend on the value read by analog input channel.
After that, configure that timer to act as free running pulse generator, then the ON period and OFF period of pulse will be depend on preset value which is get value from analog input.