Gray Code Updown Counter
Gray Code Updown Counter
Concept: The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral
system where two successive values differ in only one bit. It is a non-weighted code. A 4 bit gray code up down counter counts in a similar way to a normal 4 bit binary up down counter except the fact that it counts using gray code. Up count truthtable(when select bit is 1)
Binary
Gray
Truth table: Clock 0 1 1 1 Reset X 0 1 1 Select X X 1 0 Action Circuit disabled Count=0000 Up count Down count
VHDL code library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity updown is port( clk,r:in std_logic; a:inout std_logic_vector(3 downto 0); g:inout std_logic_vector(3 downto 0)); end; architecture count of updown is begin process(clk) begin if(clk 'event and clk='1' and r='0') then a<="0000" ; g<="0000"; elsif(clk'event and clk='1' and r='1') then a<=a+"1"; end if; g(3)<=a(3); g(2)<=a(3) xor a(2); g(1)<=a(2) xor a(1); g(0)<=a(1) xor a(0); end process; end ;