Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8 bit Mod VHDL question

Status
Not open for further replies.

Jorge Jesse Cantu

Junior Member level 1
Joined
Mar 3, 2014
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
167
Hello fellow engineers/enthusiasts! I wrote the following program for an 8-bit modula N-bit counter, where N was a specified constant. I had to alter it a little bit due to my friend helping me, but what he altered I am confused about.

My question is, why does he assign my cout to din within my for loop? Din isn't counting, so I am confused on what sort of value din would have and/or assign to cout.

Also I'd be interested to see what a timing diagram for the din input and cout output would look like, but if you guys do not feel like drawing one up for me that is fine, I just want to get rid of my confusion.

Here is my code:

HTML:
----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity nmod is
		port( clear: in std_logic;
				load:  in std_logic;
				arst_l: in std_logic;	--make it active low
				clk:	 in std_logic;
				din:	 in std_logic_vector(7 downto 0);
				count: out std_logic_vector(7 downto 0)
				);
end nmod;

architecture Behavioral of nmod is
constant N: std_logic_vector(7 downto 0) := X"C0";
signal cout: std_logic_vector(7 downto 0);
signal arst: std_logic;
signal dain: std_logic;

begin
count <= cout;		--output signal, output on left side
arst <= arst_l;	--input signal, input on right side
process(clk, arst)
begin
	if(arst = '1')then
		cout <= '0';
	elsif(clk'event and clk = '1')then
		if(clear = '1' or cout = 'N') then
		     cout <= din;
		else
		     cout <= cout +1;
		end if;
	end if;
end process;
end Behavioral;
 

Your "friend" isn't helping you out, with that change.

Code:
if (clear = '1' or cout = 'N') then
should be N without the 's.

Now if your friend meant to have the value of din load the counter to change the modulus then that would work, but I would instead make the N value into an input port and load that into the cout and decrement cout...reloading the N value when cout reaches X"00". Doing that will be a reduction NOR operation instead of an 8-bit compare operation.

Regards
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top