Hi mmTsuchi,
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
--use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
use IEEE.math_real.all;
entity countervhdl is
generic
(
DATA_WIDTH : natural := 2;
ADDR_WIDTH : natural := 5
);
port( clk : in std_logic;
--raddr : in natural range 0 to 2**ADDR_WIDTH - 1;
waddr : in natural range 0 to 2**ADDR_WIDTH - 1;
--data : in std_logic_vector((DATA_WIDTH-1) downto 0);
re : in std_logic := '1';
we : in std_logic := '1';
reset : in std_logic;
q : out std_logic_vector(3 downto 0));
end countervhdl;
architecture counting of countervhdl is
signal prescalar: integer range 0 to 50000000:=0;
signal pre: integer range 0 to 9;
signal count:integer range 0 to 9;
--signal
--subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array(2**ADDR_WIDTH-1 downto 0) of integer range 0 to 9;
-- Declare the RAM signal.
signal ram : memory_t;
-- Register to hold the address
--signal addr_reg : natural range 0 to 2**ADDR_WIDTH-1;
begin
process(clk,reset,pre)
--variable addr:integer range 0 to 2**ADDR_WIDTH-1;
variable ten:integer:=10;
begin
if (clk = '1' and clk'event) then
if (prescalar<50000000) then
prescalar<=prescalar+1;
else prescalar<=0;
end if;
if (prescalar=0) then
--for addr in 0 to 9 loop
if (reset='1') then
if(we = '0') then
if pre<10 then
pre<=pre +1 ;
--elsif pre>10 then
-- pre<=0;
end if;
ram(waddr) <= pre;
--address<=addr;
end if;
if re='0' then
count<=ram(waddr);
q<=std_logic_vector(to_unsigned(count,4));--ram(addr);
end if;
end if;
end if;
end if;
end process;
end counting;
This is my code and i want to apply this in nios system made from qsys.I used sysid,nios processor, tristate bus, ext ssram clk, onchip memory jtag_uaert,pios for led and keys.
Now my problem is how to connect these read, write, output from counter in the nios processor file that is generated from qsys. In the tutorials it says i can use only eclipse ide for this counter but anyhow i want to use vhdl code. ANd I get error when i generate vhdl file in qsys but it works with verilog.
Please help me.
Thanks