gray_code¶
Dependencies¶
None
Description¶
This package provides functions to convert between Gray code and binary. An example implementation of a Gray code counter is also included.
Example usage¶
-- Conversion functions
signal bin, gray, bin2 : std_ulogic_vector(7 downto 0);
...
bin <= X"C5";
gray <= to_gray(bin);
bin2 <= to_binary(gray);
-- Gray code counter
gc: gray_counter
port map (
Clock => clock,
Reset => reset,
Load => '0', -- Not using load feature
Enable => '1', -- Count continuously
Binary_load => (binary_count'range => '0'), -- Unused load port
Binary => binary_count, -- Internal binary count value
Gray => gray_count -- Gray coded count
);
Components¶
gray_counter¶
-
gray_code.
gray_counter
¶ An example Gray code counter implementation. This counter maintains an internal binary register and converts its output to Gray code stored in a separate register.
Generics: - RESET_ACTIVE_LEVEL (std_ulogic) – Asynch. reset control level
Port: - Clock (in std_ulogic) – System clock
- Reset (in std_ulogic) – Asynchronous reset
- Load (in std_ulogic) – Synchronous load, active high
- Enable (in std_ulogic) – Synchronous enable, active high
- Binary_load (in unsigned) – Loadable binary value
- Binary (out unsigned) – Binary count
- Gray (out unsigned) – Gray code count
Subprograms¶
-
gray_code.
to_gray
(Binary : std_ulogic_vector) → std_ulogic_vector¶ - Convert binary to Gray code.
Parameters: - Binary (std_ulogic_vector) – Binary value
Returns: Gray-coded vector.
-
gray_code.
to_gray
(Binary : std_logic_vector) → std_logic_vector¶ - Convert binary to Gray code.
Parameters: - Binary (std_logic_vector) – Binary value
Returns: Gray-coded vector.
-
gray_code.
to_gray
(Binary : unsigned) → unsigned¶ - Convert binary to Gray code.
Parameters: - Binary (unsigned) – Binary value
Returns: Gray-coded vector.
-
gray_code.
to_binary
(Gray : std_ulogic_vector) → std_ulogic_vector¶ - Convert Gray code to binary.
Parameters: - Binary – Gray-coded value
Returns: Decoded binary value.
-
gray_code.
to_binary
(Gray : std_logic_vector) → std_logic_vector¶ - Convert Gray code to binary.
Parameters: - Binary – Gray-coded value
Returns: Decoded binary value.
-
gray_code.
to_binary
(Gray : unsigned) → unsigned¶ - Convert Gray code to binary.
Parameters: - Binary – Gray-coded value
Returns: Decoded binary value.