I tried to take a naïve approach to (if needed) toggle an output pin either on the rising or falling edge of clock signal.
Line 17 below:
entity variable_clock is Port ( clk_i : in STD_LOGIC; resetn_i : in STD_LOGIC; ticks_i : in STD_LOGIC_VECTOR (7 downto 0); clk_o : out STD_LOGIC ); end variable_clock; architecture Behavioral of variable_clock is signal counter_s: natural range 0 to 2**ticks_i'length-1 := 0; signal clk_out_s: STD_LOGIC := '0'; begin process (clk_i, resetn_i) begin if rising_edge(clk_i) then if resetn_i = '0' then counter_s <= 0; clk_out_s <= '0'; else if counter_s >= unsigned(ticks_i) then -- >= because the value can change counter_s <= 0; clk_out_s <= not clk_out_s; else counter_s <= counter_s + 1; end if; clk_o <= clk_out_s; end if; end if; end process; end Behavioral;
This synthesises without errors, but the output is identical when I use
if rising_edge(clk_i) then
or
if (rising_edge(clk_i) or falling_edge(clk_i)) then
Not double speed when using both edges, as the naïve me would expect.
Internet has many opinions and warnings on this subject - both for simulation and synthesis. Your thoughts?