We have proposed and experimentally verified a pulse-width modulation (PWM) generator which directly generated a PWM signal in the optical domain. Output waveforms were clear at the repetition rate of 16 MHz; the duty cycle (DC) was from 14.7% to 72.1%; and the DC-control resolution was about 4.399 %/dB. The PWM generator's operation principle is based on the injection-locking property of a single-mode Fabry-Perot laser diode (SMFP-LD). The SMFP-LD, which has a self-locked mode wavelength at lambda(PWM), was used to detect the power of the injection-locking signal (optical analog input). If the analog input. power is high, the SMFP-LD is locked to the wavelength of the input signal lambda(a) and there is no output after an optical bandpass filter (OBF). If the analog input power is low, the SMFP-LD is unlocked and there is output signal at lambda(PWM) after the OBF. Thus, the SMFP-LD plus the OBF provide digital output for an analog input. The DC of the output PWM signal can be controlled by tuning the power of the analog input.