# Where to start on emulating a Pulse Width Modulation

This is a homework assignment and I don't really want the whole answer just a place to start on this assignment. Here's what I'm supposed to do.

"Emulate a PWM (pulse width modulation) generator. The inputs to the module are a clock signal (Clk) and two select lines. Your module must meet the following specification.

"Pulse width modulation is a popular technique used to control the effective voltage at a source by modifying the duty cycle of the input voltage (the percentage of time in which the voltage is high).

In this problem, you will emulate a PWM generator. The inputs to the module are a clock signal (Clk) and two select lines (s). Your module must meet the following specification: If s = 00, the output must stay high for 1 clock cycle and go low for the next three clock cycles. If s = 01, the output must stay high for 2 clock cycles and go low for the next 2 clock cycles. If s = 10, the output must stay high for 3 clock cycles and go low for the next clock cycle. If s = 11, the output must stay always high."

Thank's.

• do you what what a PWM waveform is? Commented Feb 19, 2016 at 18:47
• Set up a 4 bit truth table with one output. 2 bits for state and 2 bits as a 2 bit counter. And do kmap. Commented Feb 19, 2016 at 18:48
• How many cycles in your PWM period? Make a counter that counts that many cycles. Then compare the counter with your select line and generate the output based on that. Commented Feb 19, 2016 at 19:56
• If s = 00, the output must stay high for 1 clock cycle and go low for the next three clock cycles. If s = 01, the output must stay high for 2 clock cycles and go low for the next 2 clock cycles. If s = 10, the output must stay high for 3 clock cycles and go low for the next clock cycle Commented Feb 19, 2016 at 20:11
• @JuanSalazar yes, you said that already. Commented Feb 19, 2016 at 20:16

## 1 Answer

The key to this is to count the clock cycles. Depending then on what the input 's' state is and how many clock cycles you've counted, you'll either change state and start counting again, or you'll keep counting.

If you're having trouble picturing it, try drawing the clock and output waveforms out on paper with the input states.