OpenCores
URL https://opencores.org/ocsvn/potato/potato/trunk

Subversion Repositories potato

[/] [potato/] [trunk/] [soc/] [pp_soc_7seg.vhd] - Diff between revs 61 and 64

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 61 Rev 64
-- The Potato Processor - A simple processor for FPGAs
-- The Potato Processor - A simple processor for FPGAs
-- (c) Kristian Klomsten Skordal 2015 <kristian.skordal@wafflemail.net>
-- (c) Kristian Klomsten Skordal 2015 <kristian.skordal@wafflemail.net>
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
 
 
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std.all;
 
 
entity pp_soc_7seg is
entity pp_soc_7seg is
        generic(
        generic(
                NUM_DISPLAYS : natural := 8;             -- Number of 7-segment displays connected to the module.
                NUM_DISPLAYS : natural := 8;             -- Number of 7-segment displays connected to the module.
                SWITCH_COUNT         : natural;          -- How many ticks of the input clock to count before switching displays.
                SWITCH_COUNT         : natural;          -- How many ticks of the input clock to count before switching displays.
                CATHODE_ENABLE_VALUE : std_logic := '0'; -- Value of the cathode output when enabled.
                CATHODE_ENABLE_VALUE : std_logic := '0'; -- Value of the cathode output when enabled.
                ANODE_ENABLE_VALUE   : std_logic := '0'  -- Value of the anode output when enabled.
                ANODE_ENABLE_VALUE   : std_logic := '0'  -- Value of the anode output when enabled.
        );
        );
        port(
        port(
                clk   : in std_logic;
                clk   : in std_logic;
                reset : in std_logic;
                reset : in std_logic;
 
 
                -- Connections to the displays:
                -- Connections to the displays:
                seg7_anode   : out std_logic_vector(NUM_DISPLAYS - 1 downto 0); -- One for each display
                seg7_anode   : out std_logic_vector(NUM_DISPLAYS - 1 downto 0); -- One for each display
                seg7_cathode : out std_logic_vector(6 downto 0);
                seg7_cathode : out std_logic_vector(6 downto 0);
 
 
                -- Wishbone interface:
                -- Wishbone interface:
                wb_adr_in  : in  std_logic_vector( 0 downto 0);
                wb_adr_in  : in  std_logic_vector( 0 downto 0);
                wb_dat_in  : in  std_logic_vector(31 downto 0);
                wb_dat_in  : in  std_logic_vector(31 downto 0);
                wb_dat_out : out std_logic_vector(31 downto 0);
                wb_dat_out : out std_logic_vector(31 downto 0);
                wb_cyc_in  : in  std_logic;
                wb_cyc_in  : in  std_logic;
                wb_stb_in  : in  std_logic;
                wb_stb_in  : in  std_logic;
                wb_we_in   : in  std_logic;
                wb_we_in   : in  std_logic;
                wb_ack_out : out std_logic
                wb_ack_out : out std_logic
        );
        );
end entity pp_soc_7seg;
end entity pp_soc_7seg;
 
 
architecture behaviour of pp_soc_7seg is
architecture behaviour of pp_soc_7seg is
        signal ctrl_value  : std_logic_vector(NUM_DISPLAYS * 4 - 1 downto 0);
        signal ctrl_value  : std_logic_vector(NUM_DISPLAYS * 4 - 1 downto 0);
        signal ctrl_enable : std_logic_vector(NUM_DISPLAYS - 1 downto 0);
        signal ctrl_enable : std_logic_vector(NUM_DISPLAYS - 1 downto 0);
 
 
        type seg7_array is array (0 to NUM_DISPLAYS - 1) of std_logic_vector(6 downto 0);
        type seg7_array is array (0 to NUM_DISPLAYS - 1) of std_logic_vector(6 downto 0);
        signal output_array : seg7_array;
        signal output_array : seg7_array;
 
 
        subtype display_counter_type is natural range 0 to NUM_DISPLAYS - 1;
        subtype display_counter_type is natural range 0 to NUM_DISPLAYS - 1;
        signal active_display : display_counter_type := 0;
        signal active_display : display_counter_type := 0;
 
 
        constant ANODE_DISABLE_VALUE : std_logic := not ANODE_ENABLE_VALUE;
        constant ANODE_DISABLE_VALUE : std_logic := not ANODE_ENABLE_VALUE;
 
 
        subtype switch_counter_type is natural range 0 to SWITCH_COUNT - 1;
        subtype switch_counter_type is natural range 0 to SWITCH_COUNT - 1;
        signal switch_counter : switch_counter_type := 0;
        signal switch_counter : switch_counter_type := 0;
 
 
        signal anodes : std_logic_vector(NUM_DISPLAYS - 1 downto 0);
        signal anodes : std_logic_vector(NUM_DISPLAYS - 1 downto 0);
 
 
        -- Wishbone controller acknowledge signal:
        -- Wishbone controller acknowledge signal:
        signal ack : std_logic;
        signal ack : std_logic;
begin
begin
 
 
        assert NUM_DISPLAYS <= 8 and NUM_DISPLAYS > 0
        assert NUM_DISPLAYS <= 8 and NUM_DISPLAYS > 0
                report "Only 1 - 8 displays are supported by the 7-seg module!"
                report "Only 1 - 8 displays are supported by the 7-seg module!"
                severity FAILURE;
                severity FAILURE;
 
 
        -- Connect display outputs:
        -- Connect display outputs:
        seg7_cathode <= output_array(active_display) when CATHODE_ENABLE_VALUE = '0' else not output_array(active_display);
        seg7_cathode <= output_array(active_display) when CATHODE_ENABLE_VALUE = '0' else not output_array(active_display);
        seg7_anode <= anodes;
        seg7_anode <= anodes and not ctrl_enable when ANODE_ENABLE_VALUE = '1' else anodes and ctrl_enable;
 
 
        -- Create one decoder for each display:
        -- Create one decoder for each display:
        generate_decoders: for i in 0 to NUM_DISPLAYS - 1
        generate_decoders: for i in 0 to NUM_DISPLAYS - 1
        generate
        generate
                decoder: entity work.pp_seg7dec
                decoder: entity work.pp_seg7dec
                        port map(
                        port map(
                                input => ctrl_value(i * 4 + 3 downto i * 4),
                                input => ctrl_value(i * 4 + 3 downto i * 4),
                                output => output_array(i)
                                output => output_array(i)
                        );
                        );
        end generate;
        end generate;
 
 
        -- Switch between the displays:
        -- Switch between the displays:
        switch_displays: process(clk)
        switch_displays: process(clk)
        begin
        begin
                if rising_edge(clk) then
                if rising_edge(clk) then
                        if reset = '1' then
                        if reset = '1' then
                                anodes <= (0 => ANODE_ENABLE_VALUE, others => ANODE_DISABLE_VALUE);
                                anodes <= (0 => ANODE_ENABLE_VALUE, others => ANODE_DISABLE_VALUE);
                                active_display <= 0;
                                active_display <= 0;
                        else
                        else
                                if switch_counter = SWITCH_COUNT - 1 then
                                if switch_counter = SWITCH_COUNT - 1 then
                                        anodes <= std_logic_vector(rotate_left(unsigned(anodes), 1));
                                        anodes <= std_logic_vector(rotate_left(unsigned(anodes), 1));
                                        switch_counter <= 0;
                                        switch_counter <= 0;
                                        if active_display = NUM_DISPLAYS - 1 then
                                        if active_display = NUM_DISPLAYS - 1 then
                                                active_display <= 0;
                                                active_display <= 0;
                                        else
                                        else
                                                active_display <= active_display + 1;
                                                active_display <= active_display + 1;
                                        end if;
                                        end if;
                                else
                                else
                                        switch_counter <= switch_counter + 1;
                                        switch_counter <= switch_counter + 1;
                                end if;
                                end if;
                        end if;
                        end if;
                end if;
                end if;
        end process switch_displays;
        end process switch_displays;
 
 
        ----- Wishbone controller: -----
        ----- Wishbone controller: -----
        wb_ack_out <= ack and wb_cyc_in and wb_stb_in;
        wb_ack_out <= ack and wb_cyc_in and wb_stb_in;
        wishbone: process(clk)
        wishbone: process(clk)
        begin
        begin
                if rising_edge(clk) then
                if rising_edge(clk) then
                        if reset = '1' then
                        if reset = '1' then
                                ctrl_value <= (others => '0');
                                ctrl_value <= (others => '0');
                                ctrl_enable <= (others => '1');
                                ctrl_enable <= (others => '1');
                                wb_dat_out <= (others => '0');
                                wb_dat_out <= (others => '0');
                                ack <= '0';
                                ack <= '0';
                        else
                        else
                                if wb_cyc_in = '1' and wb_stb_in = '1' and ack = '0' then
                                if wb_cyc_in = '1' and wb_stb_in = '1' and ack = '0' then
                                        if wb_we_in = '1' then
                                        if wb_we_in = '1' then
                                                case wb_adr_in is
                                                case wb_adr_in is
                                                        when b"0" =>
                                                        when b"0" =>
                                                                ctrl_enable <= wb_dat_in(NUM_DISPLAYS - 1 downto 0);
                                                                ctrl_enable <= wb_dat_in(NUM_DISPLAYS - 1 downto 0);
                                                        when b"1" =>
                                                        when b"1" =>
                                                                ctrl_value <= wb_dat_in(NUM_DISPLAYS * 4 - 1 downto 0);
                                                                ctrl_value <= wb_dat_in(NUM_DISPLAYS * 4 - 1 downto 0);
                                                        when others =>
                                                        when others =>
                                                end case;
                                                end case;
                                                ack <= '1';
                                                ack <= '1';
                                        else
                                        else
                                                case wb_adr_in is
                                                case wb_adr_in is
                                                        when b"0" =>
                                                        when b"0" =>
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(ctrl_enable), wb_dat_out'length));
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(ctrl_enable), wb_dat_out'length));
                                                        when b"1" =>
                                                        when b"1" =>
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(ctrl_value), wb_dat_out'length));
                                                                wb_dat_out <= std_logic_vector(resize(unsigned(ctrl_value), wb_dat_out'length));
                                                        when others =>
                                                        when others =>
                                                end case;
                                                end case;
                                                ack <= '1';
                                                ack <= '1';
                                        end if;
                                        end if;
                                elsif wb_stb_in = '0' then
                                elsif wb_stb_in = '0' then
                                        ack <= '0';
                                        ack <= '0';
                                end if;
                                end if;
                        end if;
                        end if;
                end if;
                end if;
        end process wishbone;
        end process wishbone;
 
 
end architecture behaviour;
end architecture behaviour;
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.