I'm getting the following errors:
Error (10822): HDL error at pwm.vhd(15): couldn't implement registers for assignments on this clock edge
Error (10822): HDL error at pwm.vhd(18): couldn't implement registers for assignments on this clock edge
Obviously the problem is the two rising edges that both change 'output'. How could I fix this problem?
code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity PWM is
port(
button1, button2 : in STD_LOGIC;
output : inout STD_LOGIC_VECTOR(7 downto 0) := "00000000"
);
end PWM;
architecture behavioral of PWM is
begin
process(button1, button2)
begin
if rising_edge(button1) then
output <= output + 1;
end if;
if rising_edge(button2) then
output <= output - 1;
end if;
end process;
end behavioral;
Best Answer
The circuit you describe is a register with two input clocks, which doesn't really exist. There are DDR registers, but that is not what you described.
Futhermore, clocks are very special in a FPGA, and must be used with special care. A button is not a clock. Although it is possible to use normal signal as a clock, it is not recommended.
What you need is a real clock to drive your circuit, every board has one! Then, you need to detect the rising edges of your button according to that clock domain:
Several things to note:
Finally, physical buttons needs debouncing. As you push on it, the electrical connection goes on and off multiple times while the physical switch reaches its final position. Thus, it's likely that multiple rising edges of the buttons will be detected when you push it, incrementing the counter more than once.