1, it is suggested that it can be easily realized by single-chip computer program, especially some single-chip computers have PWM modules, and you can get the PWM waveform with the desired pulse width by directly inputting data.
2. You can also use a comparator. One end inputs triangular wave, and the other end inputs DC level. By changing the DC value, PWM waveforms with different pulse widths can be output.