X-Git-Url: https://rtime.felk.cvut.cz/gitweb/fpga/pwm.git/blobdiff_plain/899c4aaf8411af38d4077fd70ef8872e5093b6f0..e91adf9cda5fcc9e81e9468583363e96dfe32f80:/pwm.vhd diff --git a/pwm.vhd b/pwm.vhd index 3590d54..4ac8765 100644 --- a/pwm.vhd +++ b/pwm.vhd @@ -53,12 +53,13 @@ begin -- Peripheral register PWM_REGISTER : process (clk, reset) begin - if reset = '1' then - reg <= (others => '0'); - - elsif rising_edge(clk) then - if we = '1' then - reg <= din; + if rising_edge(clk) then + if reset = '1' then + reg <= (others => '0'); + else + if we = '1' then + reg <= din; + end if; end if; end if; end process; @@ -69,18 +70,20 @@ begin -- with next clk edge. Pwm output is delayed by one clock. PWM_GEN : process (clk, reset) begin - if reset = '1' then - pwm <= '0'; - - elsif rising_edge(clk) then - if pwm_cyc = '1' then - cmp <= reg; - end if; - - if pwm_cnt < cmp then - pwm <= '1'; - else + if rising_edge(clk) then + if reset = '1' then pwm <= '0'; + + else + if pwm_cyc = '1' then + cmp <= reg; + end if; + + if pwm_cnt < cmp then + pwm <= '1'; + else + pwm <= '0'; + end if; end if; end if; end process;