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.

[SOLVED] synchronous 4 bit counter problem

Status
Not open for further replies.

Digit0001

Member level 1
Joined
Jun 12, 2010
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,547
Hi

Can someone help me on how would you code the following:
A synchronous 4 bit counter up performs the counting and the loading on the falling edge of the clock. The clear is an asynchronous input which resets the counter. The counter generates a carry Cout in state 15 if T = '1'. The counter increments if P and T = 1.

This is what i have done. Can someone tell me if this is correct?

Code:
entity ques4 is
port(P,T : in std_logic;
	 Clear,Load : in std_logic;
	 Clk : in std_logic;
	 cout : in std_logic;
	 D : in std_logic_vector(3 downto 0);
	 Q : out std_logic_vector(3 downto 0));
end ques4;

architecture Behavioral of ques4 is
signal count : std_logic_vector(3 downto 0);
begin
	process(clk,clear)
	begin
		if(clear = '0') then
			count <= "0000";
		elsif(clk'event and clk='0') then
			if(load = '1') then
				count <= D;
			elsif(T = '1') then
				count <= D;
			elsif(T='1' and P='1') then
				count <= count + "0001";
			end if;
		end if;
	end process;
	Q <= count;
end Behavioral;

P.S
 

why not simulate it/run it and find out?

You have one problem, it is never going to actually count. the branch (T= '1' and P = '1') can never be reached because it is overridden by the T='1' branch above.
 

i have tried it again, can someone tell me where is my mistake, because when i simulate it doesn't give me an output for Q.

Code:
architecture Behavioral of ques4 is
signal count : std_logic_vector(3 downto 0);
signal tCout : std_logic;
begin
	process(clk,clear,count,P,T,Load)
	begin	
		if(clear = '1') then
			count <= "0000";
			tCout <= '0';
		elsif(clk'event and clk='0') then
			if(Load = '1') then
				count <= D;
				tCout <= '0';
			elsif(T = '1' and P = '0') then
				tCout <= '1';
			elsif(T = '1' and P = '1') then
				count <= count + '1';
				tCout <= '0';
			else
				count <= count;
			end if;
		end if;
	end process;
		Q <= count;
	Cout <= tCout;
end Behavioral;
 
Last edited:

nothing wrong with the code, what does your testbech code look like? and what does no output mean?
 

solved my problem, something with my coding.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top