Given this VHDL PWM process, what is the duty cycle of the output signal pwm_out?
process(clk) variable counter : integer range 0 to 9 := 0; begin if rising_edge(clk) then if counter < 9 then counter := counter + 1; else counter := 0; end if; if counter < 3 then pwm_out <= '1'; else pwm_out <= '0'; end if; end if; end process;
Count how many clock cycles pwm_out stays high in one full cycle.
The counter counts from 0 to 9 (10 cycles). The output is '1' when counter is less than 3, so 3 cycles high out of 10 total cycles. Duty cycle = 3/10 = 30%.
Given the same PWM process as before, what is the frequency of the PWM output signal pwm_out if the input clock clk runs at 50 MHz?
process(clk) variable counter : integer range 0 to 9 := 0; begin if rising_edge(clk) then if counter < 9 then counter := counter + 1; else counter := 0; end if; if counter < 3 then pwm_out <= '1'; else pwm_out <= '0'; end if; end if; end process;
Calculate the PWM period in clock cycles and convert to frequency.
The counter counts 10 clock cycles per PWM period. Clock frequency is 50 MHz, so PWM frequency = 50 MHz / 10 = 5 MHz.
What error will this VHDL code cause when synthesizing a PWM generator?
process(clk) variable counter : integer range 0 to 9 := 0; begin if rising_edge(clk) then if counter <= 9 then counter := counter + 1; else counter := 0; end if; if counter < 3 then pwm_out <= '1'; else pwm_out <= '0'; end if; end if; end process;
Check the condition that increments the counter and the variable range.
The counter variable is declared with range 0 to 9. The condition if counter <= 9 then counter := counter + 1; allows counter to increment to 10, which is outside the declared range, causing a range violation error.
Find the option that corrects the syntax error in this PWM process code snippet.
process(clk) variable counter : integer range 0 to 9 := 0; begin if rising_edge(clk) then if counter < 9 then counter := counter + 1; else counter := 0; end if; if counter < 3 then pwm_out <= '1'; else pwm_out <= '0'; end if; end if; end process;
Check the line before begin for missing punctuation.
In VHDL, variable declarations must end with a semicolon. The line variable counter : integer range 0 to 9 := 0 is missing a semicolon.
Given a PWM generator with a 100 MHz clock and a counter range of 0 to 19, where the output is high when counter < 5, what is the high time of the PWM output in nanoseconds?
process(clk) variable counter : integer range 0 to 19 := 0; begin if rising_edge(clk) then if counter < 19 then counter := counter + 1; else counter := 0; end if; if counter < 5 then pwm_out <= '1'; else pwm_out <= '0'; end if; end if; end process;
Calculate clock period and multiply by number of high cycles.
Clock frequency is 100 MHz, so clock period = 1 / 100 MHz = 10 ns. Output is high for 5 cycles, so high time = 5 * 10 ns = 50 ns.
