PWM generation in Simulink works by comparing a reference signal with a carrier triangle wave. At each time step, if the reference is greater than the carrier, the PWM output is 1; otherwise, it is 0. This creates a pulse-width modulated signal where the width of the pulses depends on the reference value. The carrier wave frequency determines how often the PWM signal repeats. For example, with a 1 kHz carrier, the PWM pattern repeats every 1 millisecond. This method is visualized step-by-step by tracking the reference, carrier, condition, and PWM output values over time.